Skip to content

Commit 128046a

Browse files
committed
fix: move metric scope to a tag
1 parent ed4e3c1 commit 128046a

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

LiveControlGateway/LifetimeManager/HubLifetimeManager.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using OpenShock.Common.Redis.PubSub;
88
using OpenShock.Common.Services.RedisPubSub;
99
using OpenShock.LiveControlGateway.Controllers;
10+
using OpenShock.LiveControlGateway.Options;
1011
using Redis.OM.Contracts;
1112
using StackExchange.Redis;
1213

@@ -37,13 +38,15 @@ public sealed class HubLifetimeManager
3738
/// <param name="redisConnectionProvider"></param>
3839
/// <param name="redisPubService"></param>
3940
/// <param name="loggerFactory"></param>
41+
/// <param name="lcgOptions"></param>
4042
/// <param name="meter"></param>
4143
public HubLifetimeManager(
4244
IDbContextFactory<OpenShockContext> dbContextFactory,
4345
IConnectionMultiplexer connectionMultiplexer,
4446
IRedisConnectionProvider redisConnectionProvider,
4547
IRedisPubService redisPubService,
4648
ILoggerFactory loggerFactory,
49+
LcgOptions lcgOptions,
4750
[FromKeyedServices("OpenShock.Gateway.Meter")] Meter meter
4851
)
4952
{
@@ -56,11 +59,13 @@ public HubLifetimeManager(
5659
_logger = _loggerFactory.CreateLogger<HubLifetimeManager>();
5760

5861

62+
var gatewayFqdn = new KeyValuePair<string, object?>("gateway_fqdn", lcgOptions.Fqdn);
63+
5964
meter.CreateObservableUpDownCounter("openshock_hub_connections", () =>
6065
{
6166
return new[]
6267
{
63-
new Measurement<int>(_lifetimes.Count)
68+
new Measurement<int>(_lifetimes.Count, gatewayFqdn)
6469
};
6570
}, "connections", "Current number of connected hubs");
6671
}

LiveControlGateway/Program.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@
3333
builder.Services.AddScoped<IDeviceService, DeviceService>();
3434
builder.Services.AddScoped<IControlSender, ControlSender>();
3535
builder.Services.AddScoped<IOtaService, OtaService>();
36-
builder.Services.AddKeyedSingleton("OpenShock.Gateway.Meter", new Meter("OpenShock.Gateway", "1.0.0", [new KeyValuePair<string, object?>("gateway_fqdn", lcgOptions.Fqdn)]));
36+
// The fqdn rides on the individual measurements, not on the Meter: a tag set here is a *scope*
37+
// attribute, which the Prometheus exporter emits prefixed as otel_scope_gateway_fqdn.
38+
builder.Services.AddKeyedSingleton("OpenShock.Gateway.Meter", new Meter("OpenShock.Gateway", "1.0.0"));
3739

3840
builder.AddSwaggerExt<Program>();
3941

0 commit comments

Comments
 (0)