perf(sitelog): sampled per-run events; interval run summaries; site_events replication policy pinned
Implements WP3.2 stage (b) per docs/plans/2026-08-15-site-events-policy-design.md.
- Per-run instance-script Started/Completed Info site events are now off by
default (SiteRuntimeOptions.PerRunScriptEvents=false) instead of firing on
every run, closing the dominant site_events writer. Gated at the ScriptRunLauncher
call sites (moved there from ScriptExecutionActor by WP3.1). Error-level events
(timeout/failure/stuck-watchdog/recursion-limit) remain unconditional.
- ScriptRunSummaryRecorder accumulates per-(instance, script) run counters and a
new site-only ScriptRunSummaryFlushService emits one aggregate "script" Info
site event per ScriptRunSummaryIntervalSeconds (default 300s), top-50-script
breakdown with an "others" rollup, zero-activity intervals emit nothing.
- Per-script opt-in via PerRunScriptEventScripts ("Instance/Script" exact or
"Instance/*" wildcard), matched by the new pure ScriptRunEventPolicy. All three
options are read from IOptionsMonitor<SiteRuntimeOptions> per run, so the
policy is hot-togglable without a restart.
- Fixed the stale "event log is not replicated" comment at AkkaHostedService.cs
(~905): site_events IS registered in SiteLocalDbSetup.ReplicatedTables — the
singleton is what makes queries always hit the actively-written copy;
replication is what gives the singleton history to read after a failover
(memo Decision (b)). site_events replication itself is unchanged (still
registered) and already pinned by
tests/ZB.MOM.WW.ScadaBridge.Host.Tests/SiteLocalDbCdcRegistrationTests.cs.
- Updated Component-SiteEventLogging.md (Volume Policy section, corrected
Storage/replication rationale) and Component-SiteRuntime.md (Script Run
Launch + Error Handling sections).
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
using System.Collections.Concurrent;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Options;
|
||||
using ZB.MOM.WW.ScadaBridge.SiteEventLogging;
|
||||
using ZB.MOM.WW.ScadaBridge.SiteRuntime.Scripts;
|
||||
|
||||
namespace ZB.MOM.WW.ScadaBridge.SiteRuntime.Tests.TestSupport;
|
||||
|
||||
@@ -59,16 +61,34 @@ public sealed class FakeSiteEventLogger : ISiteEventLogger
|
||||
/// don't throw before they reach the logging hot path.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
public sealed class SingleServiceProvider(ISiteEventLogger logger)
|
||||
/// <param name="logger">The event logger to resolve for <see cref="ISiteEventLogger"/>.</param>
|
||||
/// <param name="optionsMonitor">
|
||||
/// WP3.2: optional <see cref="IOptionsMonitor{TOptions}"/> for <see cref="SiteRuntimeOptions"/>
|
||||
/// — resolves for the hot-toggle tests; null (the default) exercises the launcher's
|
||||
/// constructor-passed-options fallback, matching every pre-WP3.2 caller of this class.
|
||||
/// </param>
|
||||
/// <param name="summaryRecorder">
|
||||
/// WP3.2: optional <see cref="ScriptRunSummaryRecorder"/> — resolves so a test can assert on
|
||||
/// the aggregate counters a run produced; null (the default) exercises the launcher's
|
||||
/// null-safe skip path.
|
||||
/// </param>
|
||||
public sealed class SingleServiceProvider(
|
||||
ISiteEventLogger logger,
|
||||
IOptionsMonitor<SiteRuntimeOptions>? optionsMonitor = null,
|
||||
ScriptRunSummaryRecorder? summaryRecorder = null)
|
||||
: IServiceProvider, IServiceScopeFactory, IServiceScope
|
||||
{
|
||||
private readonly ISiteEventLogger _logger = logger;
|
||||
private readonly IOptionsMonitor<SiteRuntimeOptions>? _optionsMonitor = optionsMonitor;
|
||||
private readonly ScriptRunSummaryRecorder? _summaryRecorder = summaryRecorder;
|
||||
|
||||
/// <inheritdoc />
|
||||
public object? GetService(Type serviceType)
|
||||
{
|
||||
if (serviceType == typeof(ISiteEventLogger)) return _logger;
|
||||
if (serviceType == typeof(IServiceScopeFactory)) return this;
|
||||
if (serviceType == typeof(IOptionsMonitor<SiteRuntimeOptions>)) return _optionsMonitor;
|
||||
if (serviceType == typeof(ScriptRunSummaryRecorder)) return _summaryRecorder;
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user