-
Notifications
You must be signed in to change notification settings - Fork 78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add health checks module #77
Conversation
Fixes #76 Add health checks module to the application. * **Add Health Check Packages**: Add `Microsoft.Extensions.Diagnostics.HealthChecks`, `AspNetCore.HealthChecks.Npgsql`, and `AspNetCore.HealthChecks.Redis` package references to `complete/Api/Api.csproj`. * **Add Health Check Services**: Add health check services for database, redis cache, and external service in `complete/Api/Program.cs`. * **Add Health Check Endpoints**: Add health check endpoints for `/health` and `/alive` in `complete/Api/Program.cs`. * **Considerations for Non-Development Environments**: Add considerations for non-development environments in `MapDefaultEndpoints` method in `complete/ServiceDefaults/Extensions.cs`. * **Documentation**: Add `workshop/10-health-checks.md` to explain the health checks module and include instructions for students to update the application with health checks. Reference relevant documentation and include information on the HealthChecksUI sample. --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/dotnet-presentations/dotnet-aspire-workshop/issues/76?shareId=XXXX-XXXX-XXXX-XXXX).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR Overview
This PR adds a comprehensive health checks module to the application to monitor critical dependencies and expose health endpoints for both development and non-development environments.
- Added documentation for health checks setup.
- Updated Api.csproj and Program.cs to register health check services and endpoints.
- Modified MapDefaultEndpoints in ServiceDefaults/Extensions.cs with distinct logic for non-development environments.
Reviewed Changes
File | Description |
---|---|
workshop/10-health-checks.md | Documentation outlining steps to add health checks to the application |
complete/Api/Program.cs | Registers health check services and maps health check endpoints in Program.cs |
complete/ServiceDefaults/Extensions.cs | Updates the MapDefaultEndpoints method to handle non-development environments |
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
Comments suppressed due to low confidence (1)
complete/Api/Program.cs:41
- Health check endpoints are being mapped in both MapDefaultEndpoints and again explicitly in Program.cs, which may lead to duplicate route mapping. Consider removing the redundant mapping in Program.cs if MapDefaultEndpoints already handles these endpoints.
app.MapHealthChecks("/health");
- Added `AspNetCore.HealthChecks.Uris` package. - Removed several outdated package references, including Entity Framework Core and health checks for Npgsql and Redis. - Updated `Microsoft.EntityFrameworkCore.Design` and health check packages to version `9.0.2` and `9.0.0`, respectively. - Removed `using Microsoft.EntityFrameworkCore;` from `NwsManager.cs`. - Updated `Program.cs` to reflect changes in health check services, focusing on Redis and external services. - Restructured `MyWeatherHub.csproj` while maintaining existing properties and added new health check packages. - Modified error handling in `Program.cs` to ensure database context creation outside of development mode. - Updated `Extensions.cs` to include health checks and JSON serialization.
…Hub and API projects
I am leaning towards closing this PR and potentially revisiting this module in a future release of .NET Aspire.
I had previously discussed with Jeff and he pointed me to this stackoverflow issue describing the above: How to make Health Checks in NET Aspire right way? I've written and rewritten this several times, and it seems like a poor use of workshop time to cover this currently. There are some open issues to extend health check functionality, at which time it would make sense to create a new PR based on the updated API. |
Closing the PR per #77 (comment) |
Fixes #76
Add health checks module to the application.
Microsoft.Extensions.Diagnostics.HealthChecks
,AspNetCore.HealthChecks.Npgsql
, andAspNetCore.HealthChecks.Redis
package references tocomplete/Api/Api.csproj
.complete/Api/Program.cs
./health
and/alive
incomplete/Api/Program.cs
.MapDefaultEndpoints
method incomplete/ServiceDefaults/Extensions.cs
.workshop/10-health-checks.md
to explain the health checks module and include instructions for students to update the application with health checks. Reference relevant documentation and include information on the HealthChecksUI sample.For more details, open the Copilot Workspace session.