dotnet / aspire

Tools, templates, and packages to accelerate building observable, production-ready apps
https://learn.microsoft.com/dotnet/aspire
MIT License
3.93k stars 480 forks source link

follow-up: cancel health checks when a resource is not running #6461

Open adamint opened 1 month ago

adamint commented 1 month ago

Description

Currently, we only cancel health checks when the ResourceHealthCheckService is stopped. We should instead start to run health checks on a resource whenever it gets into the Running state and stop running them when they are no longer Running.

I created a linked cancellation token to represent the lifecycle of an individual resource's periodical health check runs. It is added when the resource is determined to be Running, and it is cancelled (and health reports' statuses are set to null) when the resource is not.

Animation

Additionally, adds several more health check tests for different scenarios, including that reports are updated where the health status did not change but a report status did, and re-enables ResourcesWithHealthCheck_NotHealthyUntilCheckSucceeds and so fixes #6385

Fixes #6450

Checklist

mitchdenny commented 1 month ago

I'm not sure we want to do this. Health checks to resources is possibly a many to many relationship.

It's possibly also worth checking out whether the health check invocation is coming from the DefaultHealthCheckService or the ResourceHealthCheckService.

adamint commented 1 month ago

I'm not sure we want to do this. Health checks to resources is possibly a many to many relationship.

Yes that's true, but resource monitoring happens per-resource. We can cancel/restart monitoring per-resource at will without cancelling health checks on other resources. It is potentially expensive to keep running these checks in perpetuity; definitionally, health status is null for non-Running resources, so it would be nice if we could avoid making these calls when possible.

It's possibly also worth checking out whether the health check invocation is coming from the DefaultHealthCheckService or the ResourceHealthCheckService.

They are coming from ResourceHealthCheckService.

JamesNK commented 1 month ago

I can't comment on app hosting changes. I'm not fimilar with the health checks logic.

adamint commented 5 days ago

@davidfowl @mitchdenny this has been sitting a while without a response