diff --git a/src/modules/Elsa.Workflows.Runtime/Extensions/HealthCheckExtensions.cs b/src/modules/Elsa.Workflows.Runtime/Extensions/HealthCheckExtensions.cs index 6c9b7195d..8d636d417 100644 --- a/src/modules/Elsa.Workflows.Runtime/Extensions/HealthCheckExtensions.cs +++ b/src/modules/Elsa.Workflows.Runtime/Extensions/HealthCheckExtensions.cs @@ -30,8 +30,10 @@ public static class HealthCheckExtensions bool includeDistributedLocks = false, Action? configureOptions = null) { + var optionsBuilder = builder.Services.AddOptions(); + if (configureOptions != null) - builder.Services.Configure(configureOptions); + optionsBuilder.Configure(configureOptions); builder.AddCheck("elsa-runtime", tags: ReadinessTags); diff --git a/src/modules/Elsa.Workflows.Runtime/HealthChecks/ElsaWorkflowPersistenceHealthCheck.cs b/src/modules/Elsa.Workflows.Runtime/HealthChecks/ElsaWorkflowPersistenceHealthCheck.cs index e86346e4c..0d4679949 100644 --- a/src/modules/Elsa.Workflows.Runtime/HealthChecks/ElsaWorkflowPersistenceHealthCheck.cs +++ b/src/modules/Elsa.Workflows.Runtime/HealthChecks/ElsaWorkflowPersistenceHealthCheck.cs @@ -13,7 +13,7 @@ namespace Elsa.Workflows.Runtime.HealthChecks; /// public class ElsaWorkflowPersistenceHealthCheck(IServiceProvider serviceProvider, ILogger logger) : IHealthCheck { - private const string ProbeId = "__elsa_health_check_probe__"; + private const string ProbeId = "00000000-0000-0000-0000-000000000000"; /// public async Task CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default) @@ -24,7 +24,8 @@ public class ElsaWorkflowPersistenceHealthCheck(IServiceProvider serviceProvider ProbeAsync("triggers", serviceProvider.GetService(), async (store, ct) => await store.FindAsync(new TriggerFilter { Id = ProbeId }, ct)), ProbeAsync("bookmark-queue", serviceProvider.GetService(), async (store, ct) => await store.FindAsync(new BookmarkQueueFilter { Id = ProbeId }, ct))); - var probes = probeResults.Where(x => !x.Skipped).Select(x => x.StoreName).ToList(); + var attemptedProbes = probeResults.Where(x => !x.Skipped).Select(x => x.StoreName).ToList(); + var successfulProbes = probeResults.Where(x => !x.Skipped && x.Exception == null).Select(x => x.StoreName).ToList(); var skippedProbes = probeResults.Where(x => x.Skipped).Select(x => x.StoreName).ToList(); var failedProbe = probeResults.FirstOrDefault(x => x.Exception != null); if (failedProbe != null) @@ -38,7 +39,7 @@ public class ElsaWorkflowPersistenceHealthCheck(IServiceProvider serviceProvider } var healthyData = CreateData(); - return probes.Count == 0 + return attemptedProbes.Count == 0 ? HealthCheckResult.Degraded("No Elsa workflow persistence stores are registered.", data: healthyData) : HealthCheckResult.Healthy("Elsa workflow stores are reachable.", healthyData); @@ -71,8 +72,11 @@ public class ElsaWorkflowPersistenceHealthCheck(IServiceProvider serviceProvider ["category"] = "persistence" }; - if (probes.Count > 0) - data["probes"] = string.Join(",", probes); + if (successfulProbes.Count > 0) + data["probes"] = string.Join(",", successfulProbes); + + if (attemptedProbes.Count > 0) + data["attemptedProbes"] = string.Join(",", attemptedProbes); if (skippedProbes.Count > 0) data["skippedProbes"] = string.Join(",", skippedProbes); diff --git a/test/unit/Elsa.Workflows.Runtime.UnitTests/HealthChecks/ElsaWorkflowPersistenceHealthCheckTests.cs b/test/unit/Elsa.Workflows.Runtime.UnitTests/HealthChecks/ElsaWorkflowPersistenceHealthCheckTests.cs index 457668082..7d6192334 100644 --- a/test/unit/Elsa.Workflows.Runtime.UnitTests/HealthChecks/ElsaWorkflowPersistenceHealthCheckTests.cs +++ b/test/unit/Elsa.Workflows.Runtime.UnitTests/HealthChecks/ElsaWorkflowPersistenceHealthCheckTests.cs @@ -51,6 +51,8 @@ public class ElsaWorkflowPersistenceHealthCheckTests Assert.Equal("persistence", result.Data["category"]); Assert.Equal("triggers", result.Data["failedStore"]); Assert.Equal("triggers", result.Data["failedProbe"]); + Assert.Equal("workflow-definitions,workflow-instances,triggers,bookmark-queue", result.Data["attemptedProbes"]); + Assert.Equal("workflow-definitions,workflow-instances,bookmark-queue", result.Data["probes"]); } [Fact] @@ -64,6 +66,7 @@ public class ElsaWorkflowPersistenceHealthCheckTests Assert.Equal(HealthStatus.Healthy, result.Status); Assert.Equal("persistence", result.Data["category"]); Assert.Equal("triggers,bookmark-queue", result.Data["probes"]); + Assert.Equal("triggers,bookmark-queue", result.Data["attemptedProbes"]); Assert.Equal("workflow-definitions,workflow-instances", result.Data["skippedProbes"]); }