-
Notifications
You must be signed in to change notification settings - Fork 159
Description
Describe the issue or suggestion
The current fundamentals article on Health Checks (https://github.com/dotnet/docs-aspire/blob/main/docs/fundamentals/health-checks.md) talks about Health Checks as a fundamental concept in Aspire but only covers health check endpoints, and the client integration health checks that contribute to them, that are configured in services being orchestrated by an Aspire AppHost. It does not cover resource health checks which are configured in the AppHost that contribute to the current status of the resource from the AppHost's point of view. This is important as these latter health checks contribute to whether other resources with a wait-for relationship to this resource are unblocked for starting or not. The status of AppHost resource health checks are also shown in the Aspire dashboard while the AppHost is running.
We should figure out where the best place is to document the concept of resource health checks in the AppHost and then once that document is done, link to it from the fundamentals health check document.
As an example of a custom resource health check in an AppHost:
var builder = DistributedApplication.CreateBuilder(args);
var startAfter = DateTime.Now.AddSeconds(30);
builder.Services.AddHealthChecks().AddCheck("mycheck", () =>
{
return DateTime.Now > startAfter ? HealthCheckResult.Healthy() : HealthCheckResult.Unhealthy();
});
var pg = builder.AddPostgres("pg")
.WithHealthCheck("mycheck");
builder.AddProject<Projects.MyApp>("myapp")
.WithReference(pg)
.WaitFor(pg); // This will result in waiting for the building check, and the
// custom check defined in the code.
Note you can effectively "join" a resource health check to an HTTP health check endpoint on a resource using the WithHttpHealthCheck
API, e.g.:
var builder = DistributedApplication.CreateBuilder(args);
var backend = builder.AddProject<Projects.Backend>("backend")
.WithHttpHealthCheck("/health");
builder.AddProject<Projects.Frontend>("frontend")
.WithReference(backend).WaitFor(backend);