feat(observability): meter bounded API-key store lookups

This commit is contained in:
Joseph Doherty
2026-08-20 09:43:07 -04:00
parent 37288d4df5
commit 6048257dfe
5 changed files with 149 additions and 1 deletions
@@ -1,6 +1,7 @@
using System.Collections.Concurrent;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using ZB.MOM.WW.OtOpcUa.Commons.Observability;
using ZB.MOM.WW.OtOpcUa.Configuration.Entities;
using ZB.MOM.WW.OtOpcUa.Core.Authorization;
@@ -139,6 +140,8 @@ public sealed class BoundedApiKeyStore : IApiKeyStore
{
if (cache.TryGetValue(key, out var entry) && _time.GetUtcNow() - entry.StampedUtc < ttl)
{
OtOpcUaTelemetry.ApiKeyStoreBounded.Add(
1, new KeyValuePair<string, object?>("outcome", "cache_hit"));
value = entry.Value;
return true;
}
@@ -202,6 +205,8 @@ public sealed class BoundedApiKeyStore : IApiKeyStore
}
catch (OperationCanceledException) when (!ct.IsCancellationRequested)
{
OtOpcUaTelemetry.ApiKeyStoreBounded.Add(
1, new KeyValuePair<string, object?>("outcome", "timeout"));
_log.LogWarning(
"ApiKeyStore: the key store did not answer within {TimeoutMs} ms — denying this activation. "
+ "Every OPC UA session activation on this server is serialized behind this call; "