Address latest health check review feedback
Agent-Logs-Url: https://github.com/elsa-workflows/elsa-core/sessions/6a652ca4-f0c8-4284-938d-6de0eb7a2bea Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com>
This commit is contained in:
parent
09641c1fab
commit
8c1618b5d4
|
|
@ -40,7 +40,7 @@ app.MapHealthChecks("/health/live", new()
|
|||
|
||||
app.MapHealthChecks("/health/ready", new()
|
||||
{
|
||||
Predicate = check => check.Tags.Contains(HealthCheckExtensions.ReadinessTag),
|
||||
Predicate = check => check.Tags.Contains(HealthCheckExtensions.ElsaTag) && check.Tags.Contains(HealthCheckExtensions.ReadinessTag),
|
||||
ResultStatusCodes =
|
||||
{
|
||||
[HealthStatus.Degraded] = StatusCodes.Status503ServiceUnavailable,
|
||||
|
|
|
|||
|
|
@ -177,7 +177,7 @@ app.MapHealthChecks("/health/live", new()
|
|||
});
|
||||
app.MapHealthChecks("/health/ready", new()
|
||||
{
|
||||
Predicate = check => check.Tags.Contains(HealthCheckExtensions.ReadinessTag),
|
||||
Predicate = check => check.Tags.Contains(HealthCheckExtensions.ElsaTag) && check.Tags.Contains(HealthCheckExtensions.ReadinessTag),
|
||||
ResultStatusCodes =
|
||||
{
|
||||
[HealthStatus.Degraded] = StatusCodes.Status503ServiceUnavailable,
|
||||
|
|
@ -186,12 +186,7 @@ app.MapHealthChecks("/health/ready", new()
|
|||
});
|
||||
app.MapHealthChecks("/", new()
|
||||
{
|
||||
Predicate = _ => false,
|
||||
ResultStatusCodes =
|
||||
{
|
||||
[HealthStatus.Degraded] = StatusCodes.Status503ServiceUnavailable,
|
||||
[HealthStatus.Unhealthy] = StatusCodes.Status503ServiceUnavailable
|
||||
}
|
||||
Predicate = _ => false
|
||||
});
|
||||
|
||||
// Routing used for SignalR.
|
||||
|
|
|
|||
|
|
@ -10,12 +10,17 @@ namespace Elsa.Extensions;
|
|||
/// </summary>
|
||||
public static class HealthCheckExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Tag applied to Elsa health checks.
|
||||
/// </summary>
|
||||
public const string ElsaTag = "elsa";
|
||||
|
||||
/// <summary>
|
||||
/// Tag applied to Elsa readiness checks.
|
||||
/// </summary>
|
||||
public const string ReadinessTag = "readiness";
|
||||
|
||||
private static readonly string[] ReadinessTags = ["elsa", ReadinessTag];
|
||||
private static readonly string[] ReadinessTags = [ElsaTag, ReadinessTag];
|
||||
|
||||
/// <summary>
|
||||
/// Adds conservative Elsa-specific readiness probes for the workflow runtime and its core stores.
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ public class ElsaDistributedLockHealthCheck(
|
|||
});
|
||||
}
|
||||
|
||||
var lockName = $"elsa-health-check-{Environment.MachineName}-{Guid.NewGuid():N}";
|
||||
var lockName = $"elsa-health-check-{Guid.NewGuid():N}";
|
||||
await using var handle = await distributedLockProvider.TryAcquireLockAsync(lockName, options.Value.DistributedLockAcquisitionTimeout, cancellationToken);
|
||||
if (handle == null)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -20,10 +20,22 @@ public class ElsaWorkflowPersistenceHealthCheck(IServiceProvider serviceProvider
|
|||
{
|
||||
var probeResults = new List<ProbeResult>
|
||||
{
|
||||
await ProbeAsync("workflow-definitions", serviceProvider.GetService<IWorkflowDefinitionStore>(), async (store, ct) => await store.FindAsync(new WorkflowDefinitionFilter { Id = ProbeId }, ct)),
|
||||
await ProbeAsync("workflow-instances", serviceProvider.GetService<IWorkflowInstanceStore>(), async (store, ct) => await store.CountAsync(new WorkflowInstanceFilter { Id = ProbeId }, ct)),
|
||||
await ProbeAsync("triggers", serviceProvider.GetService<ITriggerStore>(), async (store, ct) => await store.FindAsync(new TriggerFilter { Id = ProbeId }, ct)),
|
||||
await ProbeAsync("bookmark-queue", serviceProvider.GetService<IBookmarkQueueStore>(), async (store, ct) => await store.FindAsync(new BookmarkQueueFilter { Id = ProbeId }, ct))
|
||||
await ProbeAsync("workflow-definitions", serviceProvider.GetService<IWorkflowDefinitionStore>(), async (store, ct) =>
|
||||
{
|
||||
await store.FindAsync(new WorkflowDefinitionFilter { Id = ProbeId }, ct);
|
||||
}),
|
||||
await ProbeAsync("workflow-instances", serviceProvider.GetService<IWorkflowInstanceStore>(), async (store, ct) =>
|
||||
{
|
||||
await store.CountAsync(new WorkflowInstanceFilter { Id = ProbeId }, ct);
|
||||
}),
|
||||
await ProbeAsync("triggers", serviceProvider.GetService<ITriggerStore>(), async (store, ct) =>
|
||||
{
|
||||
await store.FindAsync(new TriggerFilter { Id = ProbeId }, ct);
|
||||
}),
|
||||
await ProbeAsync("bookmark-queue", serviceProvider.GetService<IBookmarkQueueStore>(), async (store, ct) =>
|
||||
{
|
||||
await store.FindAsync(new BookmarkQueueFilter { Id = ProbeId }, ct);
|
||||
})
|
||||
};
|
||||
|
||||
var attemptedProbes = probeResults.Where(x => !x.Skipped).Select(x => x.StoreName).ToList();
|
||||
|
|
|
|||
|
|
@ -50,6 +50,7 @@ public class ElsaDistributedLockHealthCheckTests
|
|||
await sut.CheckHealthAsync(new HealthCheckContext());
|
||||
|
||||
Assert.Equal(2, lockNames.Count);
|
||||
Assert.All(lockNames, x => Assert.DoesNotContain(Environment.MachineName, x, StringComparison.Ordinal));
|
||||
Assert.NotEqual(lockNames[0], lockNames[1]);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue