You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add comprehensive AppHost resource health checks documentation with enhanced overview (#4310)
* Initial plan
* Add AppHost resource health checks section to health checks fundamentals
Co-authored-by: DamianEdwards <[email protected]>
* Add reference to ASP.NET Core health checks documentation
Co-authored-by: DamianEdwards <[email protected]>
* Add screenshot reference for health check dashboard status
Co-authored-by: DamianEdwards <[email protected]>
* Add overview clarification that health checks run in AppHost and applications
Co-authored-by: davidfowl <[email protected]>
* Add health checks status on dashboard screenshot
---------
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: DamianEdwards <[email protected]>
Co-authored-by: davidfowl <[email protected]>
Co-authored-by: Damian Edwards <[email protected]>
Copy file name to clipboardExpand all lines: docs/fundamentals/health-checks.md
+78-1Lines changed: 78 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,14 @@ uid: dotnet/aspire/health-checks
8
8
9
9
# Health checks in .NET Aspire
10
10
11
-
Health checks provide availability and state information about an app. Health checks are often exposed as HTTP endpoints, but can also be used internally by the app to write logs or perform other tasks based on the current health. Health checks are typically used in combination with an external monitoring service or container orchestrator to check the status of an app. The data reported by health checks can be used for various scenarios:
11
+
Health checks provide availability and state information about an app. Health checks are often exposed as HTTP endpoints, but can also be used internally by the app to write logs or perform other tasks based on the current health. Health checks are typically used in combination with an external monitoring service or container orchestrator to check the status of an app.
12
+
13
+
In .NET Aspire, health checks operate in two main contexts:
14
+
15
+
-**AppHost resource health checks** - Run in the AppHost project to determine resource readiness for orchestration and dependency management. These checks control when dependent resources start and are displayed in the Aspire dashboard.
16
+
-**Application health check endpoints** - Run within individual applications and services to expose `/health` and `/alive` endpoints for monitoring and load balancing decisions.
17
+
18
+
The data reported by health checks can be used for various scenarios:
12
19
13
20
- Influence decisions made by container orchestrators, load balancers, API gateways, and other management services. For instance, if the health check for a containerized app fails, it might be skipped by a load balancer routing traffic.
14
21
- Verify that underlying dependencies are available, such as a database or cache, and return an appropriate status message.
AppHost resource health checks are different from the health check endpoints described earlier. These health checks are configured in the AppHost project and determine the readiness of resources from the orchestrator's perspective. They're particularly important for controlling when dependent resources start via the [`WaitFor`](orchestrate-resources.md#waiting-for-resources) functionality and are displayed in the Aspire dashboard.
123
+
124
+
### Resource readiness with health checks
125
+
126
+
When a resource has health checks configured, the AppHost uses them to determine if the resource is ready before starting dependent resources. If no health checks are registered for a resource, the AppHost waits for the resource to be in the <xref:Aspire.Hosting.ApplicationModel.KnownResourceStates.Running> state.
127
+
128
+
### HTTP health checks for resources
129
+
130
+
For resources that expose HTTP endpoints, you can add health checks that poll specific paths:
You can create custom health checks for more complex readiness scenarios. Start by defining the health check in the AppHost's service collection, then associate it with resources:
.WaitFor(pg); // Waits for both the Postgres container to be running
177
+
// AND the custom "mycheck" health check to be healthy
178
+
```
179
+
180
+
The <xref:Microsoft.Extensions.DependencyInjection.HealthChecksBuilderAddCheckExtensions.AddCheck*> method registers the health check, and <xref:Aspire.Hosting.ResourceBuilderExtensions.WithHealthCheck*> associates it with specific resources. For more details about creating and registering custom health checks, see [Create health checks](/aspnet/core/host-and-deploy/health-checks#create-health-checks).
181
+
182
+
### Dashboard integration
183
+
184
+
Resource health check status is displayed in the Aspire dashboard, providing real-time visibility into resource readiness. When resources are waiting for health checks to pass, the dashboard shows the current status and any failure details.
185
+
186
+
:::image type="content" source="media/health-checks-dashboard-status.png" alt-text="Screenshot of the Aspire dashboard showing health check status for resources" lightbox="media/health-checks-dashboard-status.png":::
187
+
188
+
For more information about using health checks with resource dependencies, see [Waiting for resources](orchestrate-resources.md#waiting-for-resources).
189
+
113
190
## See also
114
191
115
192
-[.NET app health checks in C#](/dotnet/core/diagnostics/diagnostic-health-checks)
0 commit comments