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:
Joseph Doherty
2026-11-09 12:08:25 -05:00
parent e2b15bd520
commit 79957c4b96
4 changed files with 59 additions and 0 deletions
@@ -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&lt;object?&gt;</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();
}
}