fix(agent): settings distants appliqués à chaud — log.level live + full reload complet (Fixes #20)
- log.level appliqué immédiatement via RuntimeLogLevel (règle globale en tête du LoggerFilterOptions partagé + RefreshFilters réflexif sur le LoggerFactory, API publique AddFilter retirée en .NET 10) — effet observable sur les loggers déjà créés, sans redémarrage - FetchFullConfigAsync applique désormais TOUTES les clés du full config via le même pipeline que SettingChanged (heartbeat, log.level, credentials, …) au lieu de ne traiter que discovery.credentials - Settings connus non dynamiques (ai.detection.*, detection.*, model.*, ffmpeg.*, yolo.*, camera.*) loggés explicitement « requires restart » - Tests : effet observable sur loggers existants, abaissement de niveau, full reload complet (heartbeat + log.level + credential pool)
This commit is contained in:
1 parent
5db7d84d9c
commit
ab705e72fa
4 files changed
+348
-8
No files matched your search
@@ -19,15 +19,34 @@ public sealed class ConfigReceiverService : BackgroundService
|
||||
private readonly IHttpClientFactory _httpClientFactory;
|
||||
private readonly DiscoveryScanTrigger _scanTrigger;
|
||||
private readonly AgentCredentialStore _credentialStore;
|
||||
private readonly RuntimeLogLevel _runtimeLogLevel;
|
||||
private HubConnection? _connection;
|
||||
|
||||
/// <summary>
|
||||
/// Settings that are known but cannot be applied without an agent restart
|
||||
/// (they are read once at startup by services that do not support hot
|
||||
/// reload). They are logged explicitly so operators know why the change
|
||||
/// has no immediate effect.
|
||||
/// </summary>
|
||||
private static readonly HashSet<string> RestartRequiredPrefixes =
|
||||
new(StringComparer.OrdinalIgnoreCase)
|
||||
{
|
||||
"ai.detection.",
|
||||
"detection.",
|
||||
"model.",
|
||||
"ffmpeg.",
|
||||
"yolo.",
|
||||
"camera.",
|
||||
};
|
||||
|
||||
public ConfigReceiverService(
|
||||
AgentState state,
|
||||
IOptions<AgentOptions> options,
|
||||
ILogger<ConfigReceiverService> logger,
|
||||
IHttpClientFactory httpClientFactory,
|
||||
DiscoveryScanTrigger scanTrigger,
|
||||
AgentCredentialStore credentialStore)
|
||||
AgentCredentialStore credentialStore,
|
||||
RuntimeLogLevel runtimeLogLevel)
|
||||
{
|
||||
_state = state;
|
||||
_options = options.Value;
|
||||
@@ -35,6 +54,7 @@ public sealed class ConfigReceiverService : BackgroundService
|
||||
_httpClientFactory = httpClientFactory;
|
||||
_scanTrigger = scanTrigger;
|
||||
_credentialStore = credentialStore;
|
||||
_runtimeLogLevel = runtimeLogLevel;
|
||||
}
|
||||
|
||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
@@ -147,7 +167,15 @@ public sealed class ConfigReceiverService : BackgroundService
|
||||
}
|
||||
break;
|
||||
case "log.level":
|
||||
_logger.LogInformation("Log level update received: {Level} (applied on next restart)", value);
|
||||
if (Enum.TryParse<LogLevel>(value, ignoreCase: true, out var level))
|
||||
{
|
||||
_runtimeLogLevel.Set(level);
|
||||
_logger.LogInformation("Log level updated to {Level} (applied live)", level);
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogWarning("Ignored invalid log level: {Value}", value);
|
||||
}
|
||||
break;
|
||||
case "discovery.scan.requested":
|
||||
_logger.LogInformation("Camera discovery scan requested by Central");
|
||||
@@ -157,7 +185,16 @@ public sealed class ConfigReceiverService : BackgroundService
|
||||
ApplyCredentialPool(value);
|
||||
break;
|
||||
default:
|
||||
_logger.LogDebug("Unknown setting {Key} = {Value} (stored for future use)", key, value);
|
||||
if (RestartRequiredPrefixes.Any(p => key.StartsWith(p, StringComparison.OrdinalIgnoreCase)))
|
||||
{
|
||||
_logger.LogWarning(
|
||||
"Setting {Key} = {Value} requires an agent restart to take effect (not applied live)",
|
||||
key, value);
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogDebug("Unknown setting {Key} = {Value} (stored for future use)", key, value);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -216,8 +253,11 @@ public sealed class ConfigReceiverService : BackgroundService
|
||||
|
||||
_logger.LogInformation("Full configuration fetched successfully ({Count} setting(s))", config.Count);
|
||||
|
||||
if (config.TryGetValue("discovery.credentials", out var envelope))
|
||||
ApplyCredentialPool(envelope);
|
||||
// Apply every key through the same pipeline as live SettingChanged
|
||||
// events — heartbeat interval, log level, credentials, restart-required
|
||||
// documentation, everything.
|
||||
foreach (var kvp in config)
|
||||
ApplySetting(kvp.Key, kvp.Value);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user