| | 1 | | using HealthChecks.UI.Client; |
| | 2 | | using Microsoft.AspNetCore.Diagnostics.HealthChecks; |
| | 3 | | using Microsoft.Extensions.Diagnostics.HealthChecks; |
| | 4 | |
|
| | 5 | | namespace Gateway; |
| | 6 | |
|
| | 7 | | public static class Probes |
| | 8 | | { |
| | 9 | | private const string LivenessProbe = $"/{LivenessTag}"; |
| | 10 | | private const string ReadinessProbe = $"/{ReadinessTag}"; |
| | 11 | | private const string LivenessTag = "alive"; |
| | 12 | | private const string ReadinessTag = "health"; |
| | 13 | |
|
| | 14 | | public static WebApplication UseProbes(this WebApplication app) |
| | 15 | | { |
| 0 | 16 | | app.MapHealthChecks( |
| 0 | 17 | | ReadinessProbe, |
| 0 | 18 | | new HealthCheckOptions |
| 0 | 19 | | { |
| 0 | 20 | | Predicate = (x) => x.Tags.Contains(ReadinessTag, StringComparer.OrdinalIgnoreCase), |
| 0 | 21 | | ResultStatusCodes = |
| 0 | 22 | | { |
| 0 | 23 | | [HealthStatus.Healthy] = StatusCodes.Status200OK, |
| 0 | 24 | | [HealthStatus.Degraded] = StatusCodes.Status200OK, |
| 0 | 25 | | [HealthStatus.Unhealthy] = StatusCodes.Status503ServiceUnavailable |
| 0 | 26 | | } |
| 0 | 27 | | } |
| 0 | 28 | | ); |
| | 29 | |
|
| 0 | 30 | | app.MapHealthChecks( |
| 0 | 31 | | LivenessProbe, |
| 0 | 32 | | new HealthCheckOptions |
| 0 | 33 | | { |
| 0 | 34 | | Predicate = (x) => x.Tags.Contains(LivenessTag, StringComparer.OrdinalIgnoreCase), |
| 0 | 35 | | ResultStatusCodes = |
| 0 | 36 | | { |
| 0 | 37 | | [HealthStatus.Healthy] = StatusCodes.Status200OK, |
| 0 | 38 | | [HealthStatus.Degraded] = StatusCodes.Status200OK, |
| 0 | 39 | | [HealthStatus.Unhealthy] = StatusCodes.Status503ServiceUnavailable |
| 0 | 40 | | } |
| 0 | 41 | | } |
| 0 | 42 | | ); |
| | 43 | |
|
| 0 | 44 | | return app; |
| | 45 | | } |
| | 46 | | } |