From 4dfb6d2a2d68c764abb2105be1c70df389dbeb19 Mon Sep 17 00:00:00 2001 From: StuartFerguson Date: Mon, 21 Sep 2026 19:14:48 +0100 Subject: [PATCH 1/2] add health monitoring --- Directory.Packages.props | 1 + .../Bootstrapper/MiddlewareRegistry.cs | 3 ++- MessagingService/MessagingService.csproj | 1 + MessagingService/Program.cs | 8 ++++++-- MessagingService/Startup.cs | 19 +------------------ MessagingService/appsettings.json | 17 ++++++++++++----- 6 files changed, 23 insertions(+), 26 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index 66a255d..0c434ce 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -4,6 +4,7 @@ + diff --git a/MessagingService/Bootstrapper/MiddlewareRegistry.cs b/MessagingService/Bootstrapper/MiddlewareRegistry.cs index 6fdde5a..b69c5eb 100644 --- a/MessagingService/Bootstrapper/MiddlewareRegistry.cs +++ b/MessagingService/Bootstrapper/MiddlewareRegistry.cs @@ -7,6 +7,7 @@ using System; using System.Text.Json; using System.Text.Json.Serialization; +using HealthMonitoring.Client; namespace MessagingService.Bootstrapper { @@ -58,7 +59,7 @@ public MiddlewareRegistry() { this.ConfigureHttpJsonOptions(jsonOptions => JsonSerializerConfiguration.ConfigureMinimalApi(jsonOptions.SerializerOptions)); - this.AddUptimeKuma(); + this.AddHealthMonitoringRegistration(Startup.Configuration); } private void ConfigureAuthentication() { diff --git a/MessagingService/MessagingService.csproj b/MessagingService/MessagingService.csproj index 1cf85de..61be700 100644 --- a/MessagingService/MessagingService.csproj +++ b/MessagingService/MessagingService.csproj @@ -11,6 +11,7 @@ + diff --git a/MessagingService/Program.cs b/MessagingService/Program.cs index 6eeabff..98c2210 100644 --- a/MessagingService/Program.cs +++ b/MessagingService/Program.cs @@ -3,18 +3,19 @@ using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using NLog.Extensions.Logging; +using Sentry.Extensibility; using Shared.Logger; using Shared.Middleware; using System; using System.IO; using System.Reflection; -using Sentry.Extensibility; namespace MessagingService { using Lamar.Microsoft.DependencyInjection; using NLog; using Shared.General; + using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; [ExcludeFromCodeCoverage] @@ -77,7 +78,10 @@ private static void ConfigureWebHost(IWebHostBuilder webBuilder, .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true, reloadOnChange: true) .AddJsonFile($"/home/txnproc/config/appsettings.local.json", optional: true, reloadOnChange: true) - .AddEnvironmentVariables(); + .AddEnvironmentVariables().AddInMemoryCollection(new Dictionary + { + ["HealthMonitoring:Service:Version"] = Assembly.GetEntryAssembly()?.GetName().Version?.ToString() ?? "0.0.0.0" + }); // Build a snapshot of configuration so we can use it immediately (e.g. for Sentry) var builtConfig = configBuilder.Build(); diff --git a/MessagingService/Startup.cs b/MessagingService/Startup.cs index cfc821d..8cd53c9 100644 --- a/MessagingService/Startup.cs +++ b/MessagingService/Startup.cs @@ -115,25 +115,8 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerF app.UseSwagger(); app.UseSwaggerUI(); - - lifetime.ApplicationStarted.Register(() => - { - _ = RegisterWithUptimeKumaAsync(host); - }); - + app.PreWarm(); } - - private static async Task RegisterWithUptimeKumaAsync(IHost host) - { - try - { - await host.RegisterWithUptimeKumaAsync(); - } - catch (Exception ex) - { - Shared.Logger.Logger.LogError("Failed to register the Messaging Service with Uptime Kuma.", ex); - } - } } } diff --git a/MessagingService/appsettings.json b/MessagingService/appsettings.json index cb60484..eefd1f9 100644 --- a/MessagingService/appsettings.json +++ b/MessagingService/appsettings.json @@ -43,11 +43,18 @@ "SecurityConfiguration": { "ApiName": "messagingService" }, - "UptimeKuma": { - "Monitor": { + "HealthMonitoring": { + "Service": { + "ServiceId": "messaging-service", "Name": "Messaging Service", - "Url": "http://localhost:5006/health", - "IntervalInSeconds": 60 - } + "Description": "Messaging Service", + "HealthUrl": "http://localhost:5006/healthui" + }, + "Dependencies": [ + { + "DependencyName": "Eventstore", + "TargetServiceId": "kurrentdb" + } + ] } } From 8ec3514f91911692fb39e8e3bb3772c98422d016 Mon Sep 17 00:00:00 2001 From: StuartFerguson Date: Mon, 21 Sep 2026 19:49:43 +0100 Subject: [PATCH 2/2] fix to health client --- Directory.Packages.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index 0c434ce..a830e18 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -4,7 +4,7 @@ - +