| | | 1 | | using AsyncResponse; |
| | | 2 | | using Microsoft.Extensions.DependencyInjection.Extensions; |
| | | 3 | | using Microsoft.Extensions.Diagnostics.HealthChecks; |
| | | 4 | | |
| | | 5 | | namespace Microsoft.Extensions.DependencyInjection; |
| | | 6 | | |
| | | 7 | | /// <summary> |
| | | 8 | | /// Health-check registration for AsyncResponse. This is the one feature deliberately added on the |
| | | 9 | | /// health-checks pipeline rather than the fluent <c>AddAsyncResponse()</c> builder, because it |
| | | 10 | | /// belongs to <c>AddHealthChecks()</c>. |
| | | 11 | | /// </summary> |
| | | 12 | | public static class AsyncResponseHealthCheckExtensions |
| | | 13 | | { |
| | | 14 | | /// <summary> |
| | | 15 | | /// Adds the <see cref="AsyncResponseRecoveryHealthCheck"/> to the health-check pipeline. It |
| | | 16 | | /// reads the watchdog's cached snapshot (probes never touch the recovery store) and reports at |
| | | 17 | | /// most <c>Degraded</c> — stale flows are an operator signal, not process ill-health, so keep |
| | | 18 | | /// <c>Degraded</c> mapped to HTTP 200 on readiness endpoints (the ASP.NET Core default). The |
| | | 19 | | /// watchdog itself runs by default once <c>AddAsyncResponse()</c> is registered. |
| | | 20 | | /// </summary> |
| | | 21 | | public static IHealthChecksBuilder AddAsyncResponseRecoveryCheck( |
| | | 22 | | this IHealthChecksBuilder builder, |
| | | 23 | | string name = "async-response-recovery", |
| | | 24 | | IEnumerable<string>? tags = null) |
| | | 25 | | { |
| | 3 | 26 | | builder.Services.TryAddSingleton<AsyncResponseWatchdogState>(); |
| | 3 | 27 | | builder.Add(new HealthCheckRegistration( |
| | 3 | 28 | | name, |
| | 3 | 29 | | provider => new AsyncResponseRecoveryHealthCheck(provider.GetRequiredService<AsyncResponseWatchdogState>()), |
| | 3 | 30 | | failureStatus: HealthStatus.Degraded, |
| | 3 | 31 | | tags)); |
| | | 32 | | |
| | 3 | 33 | | return builder; |
| | | 34 | | } |
| | | 35 | | } |