From e634968e009e4449772ad65586f42b401243acc6 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Tue, 7 Oct 2025 00:34:00 +0800 Subject: [PATCH] :bug: Brings health check back to live --- DysonNetwork.Gateway/Program.cs | 16 ++++++++++++++++ DysonNetwork.ServiceDefaults/Extensions.cs | 19 +++++++------------ 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/DysonNetwork.Gateway/Program.cs b/DysonNetwork.Gateway/Program.cs index 6239eb5..26f1320 100644 --- a/DysonNetwork.Gateway/Program.cs +++ b/DysonNetwork.Gateway/Program.cs @@ -100,6 +100,22 @@ var routes = specialRoutes.Concat(apiRoutes).Concat(swaggerRoutes).ToArray(); var clusters = serviceNames.Select(serviceName => new ClusterConfig { ClusterId = serviceName, + HealthCheck = new() + { + Active = new() + { + Enabled = true, + Interval = TimeSpan.FromSeconds(10), + Timeout = TimeSpan.FromSeconds(5), + Policy = "ActiveHealthy", + Path = "/health" + }, + Passive = new() + { + Enabled = true, + Policy = "PassiveHealthy" + } + }, Destinations = new Dictionary { { "destination1", new DestinationConfig { Address = $"http://{serviceName}" } } diff --git a/DysonNetwork.ServiceDefaults/Extensions.cs b/DysonNetwork.ServiceDefaults/Extensions.cs index 3a85ee7..74f9008 100644 --- a/DysonNetwork.ServiceDefaults/Extensions.cs +++ b/DysonNetwork.ServiceDefaults/Extensions.cs @@ -118,19 +118,14 @@ public static class Extensions public static WebApplication MapDefaultEndpoints(this WebApplication app) { - // Adding health checks endpoints to applications in non-development environments has security implications. - // See https://aka.ms/dotnet/aspire/healthchecks for details before enabling these endpoints in non-development environments. - if (app.Environment.IsDevelopment()) - { - // All health checks must pass for app to be considered ready to accept traffic after starting - app.MapHealthChecks(HealthEndpointPath); + // All health checks must pass for app to be considered ready to accept traffic after starting + app.MapHealthChecks(HealthEndpointPath); - // Only health checks tagged with the "live" tag must pass for app to be considered alive - app.MapHealthChecks(AlivenessEndpointPath, new HealthCheckOptions - { - Predicate = r => r.Tags.Contains("live") - }); - } + // Only health checks tagged with the "live" tag must pass for app to be considered alive + app.MapHealthChecks(AlivenessEndpointPath, new HealthCheckOptions + { + Predicate = r => r.Tags.Contains("live") + }); return app; }