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

Add tags to health checks #467

Closed RobCannon closed 6 years ago

RobCannon commented 6 years ago

Instead of naming (or in addition to naming), it would be great if I could apply tags when health checks are created and then use those to filter the health checks when creating the health check endpoints. So:

services
                .AddHealthChecks()
                .AddCheck(new { "live", "ready", "diagnostic"}, () => Task.FromResult(HealthCheckResult.Healthy()))
                .AddCheck(new { "ready", "diagnostic"}, new ReadinessHealthCheck())
                .AddCheck(new { "diagnostic"}, new InDepthHealthCheck());
                // Filters the set of health checks run by this middleware
    app.UseHealthChecks("/health/live", new HealthCheckOptions()
            {
                HealthCheckTags = { "live" }
            });
    app.UseHealthChecks("/health/ready", new HealthCheckOptions()
            {
                HealthCheckTags = { "ready" }
            });
    app.UseHealthChecks("/health/diagnostic", new HealthCheckOptions()
            {
                HealthCheckTags = { "diagnostic" }
            });

The diagnostic health check would include all of the health checks.

Maybe just a Category property for the Health Check would be enough and the filter could have multiple Categories for the filter.

The main difference between this and just listing the names for each health check is the information about where the Health Check is used is on the same line where the Health Check is defined. Otherwise, if you have a lot of health checks, it is too easy to add a new health check and forget to add it to the list of health checks used by an endpoint at a different point in source code.

mkArtakMSFT commented 6 years ago

Thanks for contacting us, @RobCannon. @glennc, what are your thoughts regarding this?

glennc commented 6 years ago

We are considering this at the moment, I think it's reasonable but I'm not ready to 100% commit to us adding tags just yet. Adding it to the milestone so that we make up our minds and either do it or close this.

rynowak commented 6 years ago

Done

RobCannon commented 6 years ago

Thanks!