diff --git a/src/ZB.MOM.WW.MxGateway.Server/GatewayApplication.cs b/src/ZB.MOM.WW.MxGateway.Server/GatewayApplication.cs index 621e630..b1931a9 100644 --- a/src/ZB.MOM.WW.MxGateway.Server/GatewayApplication.cs +++ b/src/ZB.MOM.WW.MxGateway.Server/GatewayApplication.cs @@ -15,6 +15,7 @@ using ZB.MOM.WW.MxGateway.Server.Security.Authentication; using ZB.MOM.WW.MxGateway.Server.Security.Authorization; using ZB.MOM.WW.MxGateway.Server.Sessions; using ZB.MOM.WW.MxGateway.Server.Workers; +using ZB.MOM.WW.Telemetry; using ZB.MOM.WW.Telemetry.Serilog; namespace ZB.MOM.WW.MxGateway.Server; @@ -73,6 +74,11 @@ public static class GatewayApplication failureStatus: null, tags: new[] { ZbHealthTags.Ready }); builder.Services.AddSingleton(); + builder.AddZbTelemetry(o => + { + o.ServiceName = "mxgateway"; + o.Meters = [GatewayMetrics.MeterName]; // "MxGateway.Server" — name unchanged + }); builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); @@ -179,6 +185,7 @@ public static class GatewayApplication endpoints.MapStaticAssets(ResolveStaticAssetsManifestPath()); endpoints.MapZbHealth(); + endpoints.MapZbMetrics(); endpoints.MapGrpcService(); endpoints.MapGrpcService(); diff --git a/src/ZB.MOM.WW.MxGateway.Tests/Gateway/GatewayApplicationTests.cs b/src/ZB.MOM.WW.MxGateway.Tests/Gateway/GatewayApplicationTests.cs index 1205d72..e5d5e91 100644 --- a/src/ZB.MOM.WW.MxGateway.Tests/Gateway/GatewayApplicationTests.cs +++ b/src/ZB.MOM.WW.MxGateway.Tests/Gateway/GatewayApplicationTests.cs @@ -1,3 +1,5 @@ +using System.Net; +using System.Net.Http; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Routing; @@ -50,6 +52,28 @@ public sealed class GatewayApplicationTests Assert.NotNull(metrics); } + /// Verifies that Build mounts the Prometheus /metrics scrape endpoint. + [Fact] + public async Task Build_MapsMetricsEndpoint() + { + // Bind an ephemeral port (:0) — xUnit runs test collections in parallel, so any + // started-host test must avoid a fixed port to prevent a bind collision. + await using WebApplication app = GatewayApplication.Build(["--urls=http://127.0.0.1:0"]); + await app.StartAsync(); + try + { + using var client = new HttpClient { BaseAddress = new Uri(app.Urls.First()) }; + + using HttpResponseMessage response = await client.GetAsync("/metrics"); + + Assert.Equal(HttpStatusCode.OK, response.StatusCode); + } + finally + { + await app.StopAsync(); + } + } + /// Verifies that Build maps dashboard and authentication endpoints when the dashboard is enabled. [Fact] public async Task Build_WhenDashboardEnabled_MapsBlazorDashboardAndAuthEndpoints()