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:
@@ -253,4 +253,32 @@ public class SiteScriptCompileCacheTests
|
||||
Assert.True(cache.Count <= 16);
|
||||
Assert.True(cache.Evictions > 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ScadaBridge#68: evictions are exported as a Meter counter (not only the rate-limited Warning
|
||||
/// log), on the ScadaBridge meter that the Host already allowlists for export.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void Eviction_IsExportedAsAMeterCounter()
|
||||
{
|
||||
long exported = 0;
|
||||
using var listener = new System.Diagnostics.Metrics.MeterListener();
|
||||
listener.InstrumentPublished = (instrument, l) =>
|
||||
{
|
||||
if (instrument.Meter.Name == ZB.MOM.WW.ScadaBridge.Commons.Observability.ScadaBridgeTelemetry.MeterName
|
||||
&& instrument.Name == "scadabridge.site.script_compile_cache.evictions")
|
||||
l.EnableMeasurementEvents(instrument);
|
||||
};
|
||||
listener.SetMeasurementEventCallback<long>((_, measurement, _, _) => Interlocked.Add(ref exported, measurement));
|
||||
listener.Start();
|
||||
|
||||
var cache = new SiteScriptCompileCache(16, logger: null);
|
||||
for (var i = 0; i < 40; i++)
|
||||
cache.GetOrAdd("return " + i + ";", typeof(ScriptGlobals), Ok);
|
||||
|
||||
// The instrument is process-wide, so a parallel test's evictions may add to it: bound from below.
|
||||
Assert.True(cache.Evictions > 0);
|
||||
Assert.True(Interlocked.Read(ref exported) >= cache.Evictions,
|
||||
$"exported {exported} but the cache evicted {cache.Evictions}");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user