aspnet / Diagnostics

[Archived] Diagnostics middleware for reporting info and handling exceptions and errors in ASP.NET Core, and diagnosing Entity Framework Core migrations errors. Project moved to https://github.com/aspnet/AspNetCore
Apache License 2.0
213 stars 111 forks source link

Ability to throttle calls to IHealthCheck #515

Closed alecor191 closed 5 years ago

alecor191 commented 5 years ago

With Preview2 we implemented several health checks. Some were really cheap to execute and others were a bit more expensive. Services are running in a Kubernetes cluster and the health check endpoints are called quite frequently (every couple of seconds).

We implemented a decorator IHealthCheck that can be configured with a throttling interval. I.e. depending on how "expensive" the underlying health check is, we can configure the maximum frequency an IHealthCheck implementation can be invoked.

As in Preview3 a couple more IHealthCheck implementations were added (like DbContextHealthCheck), I was wondering if there is a way to configure the max. frequency of an IHealthCheck implementation.

IOW if e.g. I want a DbContextHealthCheck to be called at most once per minute, is there a way to configure/ensure this?

mkArtakMSFT commented 5 years ago

Thanks for contacting us, @alecor191. @rynowak thoughts?

mkArtakMSFT commented 5 years ago

Not even sure whether this is something we should do at all. Leaving it up to you, @rynowak.

rynowak commented 5 years ago

If you feel like you really need to do this, I'd recommend using HealthCheckRegistration.Factory to plug in a decorator https://github.com/aspnet/Diagnostics/blob/release/2.2/src/Microsoft.Extensions.Diagnostics.HealthChecks.Abstractions/HealthCheckRegistration.cs#L91

You can access these via the options type https://github.com/aspnet/Diagnostics/blob/4259b65c1619380a0fc14c1b906269fbf5ae0c82/src/Microsoft.Extensions.Diagnostics.HealthChecks/HealthCheckServiceOptions.cs

I'm not sure that we'll add anything like this as a built-in feature, but the ability to decorate a health check is already there.