feat(telemetry): export the site script compile-cache eviction counter as a Meter (ScadaBridge#68)
SiteScriptCompileCache now records each eviction sweep on scadabridge.site.script_compile_cache.evictions (ScadaBridgeTelemetry). It rides the existing ZB.MOM.WW.ScadaBridge meter, which is already in SiteServiceRegistration.ObservedMeters, so no new allowlist entry is needed; a Host test pins that the meter stays allowlisted.
This commit is contained in:
@@ -76,6 +76,17 @@ public static class ScadaBridgeTelemetry
|
||||
Meter.CreateCounter<long>("scadabridge.site.alarm_cache.buffer_dropped", unit: "1",
|
||||
description: "Live deltas evicted from a live-alarm aggregator's bounded pre-seed buffer (drop-oldest).");
|
||||
|
||||
/// <summary>
|
||||
/// Incremented by the number of entries the site script compile cache evicts when it crosses its
|
||||
/// bound (ScadaBridge#68). Eviction does not unload the Roslyn assembly, so each recompile of an
|
||||
/// evicted body loads another permanent copy: a sustained climb means compile-cache thrash and
|
||||
/// monotonic working-set growth - raise <c>ScadaBridge:SiteRuntime:ScriptCompileCacheMaxEntries</c>.
|
||||
/// Alert on this instead of the rate-limited Warning log.
|
||||
/// </summary>
|
||||
private static readonly Counter<long> _scriptCompileCacheEvictions =
|
||||
Meter.CreateCounter<long>("scadabridge.site.script_compile_cache.evictions", unit: "1",
|
||||
description: "Entries evicted from the site script compile cache at its bound (each recompile of an evicted body loads another permanent Roslyn assembly).");
|
||||
|
||||
/// <summary>
|
||||
/// Incremented for each debug event evicted from a central debug session's bounded
|
||||
/// pre-snapshot buffer (drop-oldest). The Debug View is lossy-under-backpressure
|
||||
@@ -370,6 +381,10 @@ public static class ScadaBridgeTelemetry
|
||||
/// <param name="count">Number of deltas evicted.</param>
|
||||
public static void RecordLiveAlarmBufferDrop(long count = 1) => _liveAlarmBufferDrops.Add(count);
|
||||
|
||||
/// <summary>Records entries evicted from the site script compile cache.</summary>
|
||||
/// <param name="count">Number of entries evicted by one sweep.</param>
|
||||
public static void RecordScriptCompileCacheEvictions(long count) => _scriptCompileCacheEvictions.Add(count);
|
||||
|
||||
/// <summary>Records debug events evicted from a debug session's bounded pre-snapshot buffer.</summary>
|
||||
/// <param name="count">Number of events evicted.</param>
|
||||
public static void RecordDebugPreSnapshotDrop(long count = 1) => _debugPreSnapshotDrops.Add(count);
|
||||
|
||||
@@ -2,6 +2,7 @@ using System.Collections.Concurrent;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Observability;
|
||||
|
||||
namespace ZB.MOM.WW.ScadaBridge.SiteRuntime.Scripts;
|
||||
|
||||
@@ -105,6 +106,8 @@ internal sealed class SiteScriptCompileCache
|
||||
/// <c>Script<object?></c>; the assembly Roslyn loaded for it stays in the default load context
|
||||
/// for the process lifetime, and a later miss for the same body loads a second copy. A rising value
|
||||
/// therefore means monotonic working-set growth — raise <c>ScriptCompileCacheMaxEntries</c>.
|
||||
/// Also exported as the <c>scadabridge.site.script_compile_cache.evictions</c> counter
|
||||
/// (<see cref="ScadaBridgeTelemetry.RecordScriptCompileCacheEvictions"/>) for Prometheus alerting.
|
||||
/// </summary>
|
||||
public long Evictions => Interlocked.Read(ref _evictions);
|
||||
|
||||
@@ -183,6 +186,8 @@ internal sealed class SiteScriptCompileCache
|
||||
_cache.TryRemove(victim, out _);
|
||||
|
||||
Interlocked.Add(ref _evictions, victims.Length);
|
||||
// Exported on the shared ScadaBridge meter (already in SiteServiceRegistration.ObservedMeters).
|
||||
ScadaBridgeTelemetry.RecordScriptCompileCacheEvictions(victims.Length);
|
||||
WarnEvicted();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user