diff --git a/src/ZB.MOM.WW.MxGateway.Server/GatewayApplication.cs b/src/ZB.MOM.WW.MxGateway.Server/GatewayApplication.cs index 7b12193..beba939 100644 --- a/src/ZB.MOM.WW.MxGateway.Server/GatewayApplication.cs +++ b/src/ZB.MOM.WW.MxGateway.Server/GatewayApplication.cs @@ -2,6 +2,7 @@ using System.Security.Cryptography.X509Certificates; using Microsoft.AspNetCore.Hosting.StaticWebAssets; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Configuration; +using ZB.MOM.WW.Health; using ZB.MOM.WW.MxGateway.Contracts; using ZB.MOM.WW.MxGateway.Server.Alarms; using ZB.MOM.WW.MxGateway.Server.Configuration; @@ -63,7 +64,11 @@ public static class GatewayApplication builder.Services.AddGatewayConfiguration(); builder.Services.AddSqliteAuthStore(); builder.Services.AddGatewayGrpcAuthorization(); - builder.Services.AddHealthChecks(); + builder.Services.AddHealthChecks() + .AddTypeActivatedCheck( + "auth-store", + failureStatus: null, + tags: new[] { ZbHealthTags.Ready }); builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); @@ -169,13 +174,7 @@ public static class GatewayApplication { endpoints.MapStaticAssets(ResolveStaticAssetsManifestPath()); - endpoints.MapGet( - "/health/live", - () => Results.Ok(new GatewayHealthReply( - Status: "Healthy", - DefaultBackend: GatewayContractInfo.DefaultBackendName, - WorkerProtocolVersion: GatewayContractInfo.WorkerProtocolVersion))) - .WithName("LiveHealth"); + endpoints.MapZbHealth(); 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 5f2c746..9fb3f05 100644 --- a/src/ZB.MOM.WW.MxGateway.Tests/Gateway/GatewayApplicationTests.cs +++ b/src/ZB.MOM.WW.MxGateway.Tests/Gateway/GatewayApplicationTests.cs @@ -11,19 +11,22 @@ namespace ZB.MOM.WW.MxGateway.Tests.Gateway; public sealed class GatewayApplicationTests { - /// Verifies that Build maps the live health check endpoint. + /// Verifies that Build maps the canonical three health tiers. [Fact] - public async Task Build_MapsLiveHealthEndpoint() + public async Task Build_MapsCanonicalHealthEndpoints() { await using WebApplication app = GatewayApplication.Build([]); - RouteEndpoint endpoint = Assert.Single( - ((IEndpointRouteBuilder)app).DataSources - .SelectMany(dataSource => dataSource.Endpoints) - .OfType(), - candidate => candidate.RoutePattern.RawText == "/health/live"); + var paths = ((IEndpointRouteBuilder)app).DataSources + .SelectMany(dataSource => dataSource.Endpoints) + .OfType() + .Select(e => e.RoutePattern.RawText) + .ToHashSet(); - Assert.Equal("LiveHealth", endpoint.Metadata.GetMetadata()?.EndpointName); + Assert.Contains("/health/ready", paths); + Assert.Contains("/health/active", paths); + Assert.Contains("/healthz", paths); + Assert.DoesNotContain("/health/live", paths); } /// Verifies that Build registers the gateway metrics service.