Skip to content

Commit 82ab818

Browse files
committed
initialization message
1 parent 49c3270 commit 82ab818

File tree

3 files changed

+24
-7
lines changed

3 files changed

+24
-7
lines changed

src/PerfProblemSimulator/Controllers/ConfigController.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Microsoft.AspNetCore.Mvc;
22
using Microsoft.Extensions.Options;
33
using PerfProblemSimulator.Models;
4+
using PerfProblemSimulator.Services;
45

56
namespace PerfProblemSimulator.Controllers;
67

@@ -44,9 +45,10 @@ namespace PerfProblemSimulator.Controllers;
4445
/// </remarks>
4546
[ApiController]
4647
[Route("api/[controller]")]
47-
public class ConfigController(IOptions<ProblemSimulatorOptions> options) : ControllerBase
48+
public class ConfigController(IOptions<ProblemSimulatorOptions> options, IIdleStateService idleStateService) : ControllerBase
4849
{
4950
private readonly ProblemSimulatorOptions _options = options.Value;
51+
private readonly IIdleStateService _idleStateService = idleStateService;
5052

5153
/// <summary>
5254
/// Gets client-side configuration settings.
@@ -63,7 +65,8 @@ public ActionResult<ClientConfig> GetConfig()
6365
return Ok(new ClientConfig
6466
{
6567
PageFooter = pageFooter,
66-
LatencyProbeIntervalMs = _options.LatencyProbeIntervalMs
68+
LatencyProbeIntervalMs = _options.LatencyProbeIntervalMs,
69+
IdleTimeoutMinutes = _idleStateService.IdleTimeoutMinutes
6770
});
6871
}
6972
}
@@ -82,4 +85,9 @@ public class ClientConfig
8285
/// How often the server sends latency probes in milliseconds.
8386
/// </summary>
8487
public int LatencyProbeIntervalMs { get; init; } = 200;
88+
89+
/// <summary>
90+
/// How long until the app goes idle (stops probing) in minutes.
91+
/// </summary>
92+
public int IdleTimeoutMinutes { get; init; } = 20;
8593
}

src/PerfProblemSimulator/Hubs/MetricsHub.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,15 +142,17 @@ public async Task WakeUp()
142142
if (wasIdle)
143143
{
144144
_logger.LogInformation("Server woken up by client request from: {ConnectionId}", Context.ConnectionId);
145+
// The MetricsBroadcastService will broadcast the wake-up message to all clients
146+
// via the WakingUp event, so we don't need to send it directly here
147+
return;
145148
}
146149

147-
// Send current idle state back to caller
150+
// Only send direct response when app was already active (not waking up)
151+
// to confirm current state to caller
148152
var idleData = new IdleStateData
149153
{
150154
IsIdle = _idleStateService.IsIdle,
151-
Message = wasIdle
152-
? "App waking up from idle state. There may be gaps in diagnostics and logs."
153-
: "Application is active",
155+
Message = "Application is active",
154156
Timestamp = DateTimeOffset.UtcNow
155157
};
156158
await Clients.Caller.ReceiveIdleState(idleData);

src/PerfProblemSimulator/wwwroot/js/dashboard.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const CONFIG = {
1717
// latencyProbeIntervalMs is loaded from server config (default 200ms).
1818
// Server probes at this interval and broadcasts results via SignalR.
1919
latencyProbeIntervalMs: 200,
20+
idleTimeoutMinutes: 20,
2021
latencyTimeoutMs: 30000,
2122
reconnectDelayMs: 2000,
2223
apiBaseUrl: '/api'
@@ -1679,6 +1680,12 @@ async function fetchAppConfig() {
16791680
CONFIG.latencyProbeIntervalMs = config.latencyProbeIntervalMs;
16801681
console.log(`Latency probe interval set to ${CONFIG.latencyProbeIntervalMs}ms`);
16811682
}
1683+
1684+
// Update idle timeout (server sends its timeout for display)
1685+
if (config.idleTimeoutMinutes && config.idleTimeoutMinutes > 0) {
1686+
CONFIG.idleTimeoutMinutes = config.idleTimeoutMinutes;
1687+
console.log(`Idle timeout set to ${CONFIG.idleTimeoutMinutes}m`);
1688+
}
16821689

16831690
// Update page footer if configured
16841691
const footerElement = document.getElementById('pageFooterContent');
@@ -1731,7 +1738,7 @@ document.addEventListener('DOMContentLoaded', async () => {
17311738
// Wire up side panel toggle
17321739
initializeSidePanel();
17331740

1734-
logEvent('system', 'Dashboard initialized');
1741+
logEvent('system', `Dashboard initialized (probe rate: ${CONFIG.latencyProbeIntervalMs}ms, idle timeout: ${CONFIG.idleTimeoutMinutes}m)`);
17351742
});
17361743

17371744
// ==========================================================================

0 commit comments

Comments
 (0)