dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.43k stars 10.02k forks source link

Provide AddChecks method in IHealthCheckBuilder #32317

Open DurgaPrasadReddyV opened 3 years ago

DurgaPrasadReddyV commented 3 years ago

Background and Motivation

Currently IHealthCheckBuilder provides a "AddCheck" method to register a custom health check in my application.

services.AddHealthChecks().AddCheck<CustomHealthCheck>("CustomHealthCheck");

And inline is implementation for CheckHealthAsync method in my CustomHealthCheck class.

public Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default)
{
        //hardcoding directly the result for explanation purpose
        return Task.FromResult(new HealthCheckResult(HealthStatus.Healthy));
}

We can observe that I am able to return only one HealthCheckResult object from my CustomHealthCheck class. I am looking for an api from which I can return multiple health check results from a single custom health check class. Into this custom health check class I would like to add and remove health checks from an external application while the application is running so that there would be no need to modify code and redeploy the application.

Proposed API

services.AddHealthChecks().AddChecks<CustomHealthChecks>("CustomHealthChecks");

And inline is implementation for CheckHealthAsync method in my CustomHealthChecks class. The interface would be IHealthChecks instead of IHealthCheck which returns a list of HealthCheckResults.

public Task<List<HealthCheckResult>> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default)
        {
            //hardcoding result for explanation  
            return Task.FromResult(new List<HealthCheckResult>(){new HealthCheckResult(
                HealthStatus.Healthy)});
        }

Usage Examples

services.AddHealthChecks().AddChecks<CustomHealthChecks>("CustomHealthChecks");

With this registration in my ConfigureServices method I can add 0 to n healthchecks in my CustomHealthChecks class during runtime and return their status by populating the list.

Alternative Designs

Currently I am populating the IReadOnlyDictionary<string, object> Data of HealthCheckResult class to meet the requirement of different health checks status added dynamically during runtime.

Risks

No risk is involved because this is new api.

davidfowl commented 3 years ago

Can you use the API proposal template and propose an API?

ghost commented 3 years ago

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. If it is closed, feel free to comment when you are able to provide the additional information and we will re-investigate.

See our Issue Management Policies for more information.

DurgaPrasadReddyV commented 3 years ago

Can you use the API proposal template and propose an API?

updated issue with api proposal template.

ghost commented 3 years ago

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.