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.6k stars 10.06k forks source link

Provide common IHealthCheckPublisher implementation #53670

Open thompson-tomo opened 10 months ago

thompson-tomo commented 10 months ago

Summary

I want to have some general Health publisher's available which publish to common targets ie log file, System.Diagnostic.

Motivation and goals

I want to make it as easy as possible for developers to be able record the results of the configured health checks and monitor them over time. It should not matter if on-premise or cloud software.

With this change I will be able to collect log files from site & to see what the health has been for a period of time. Note A key thing would be to ensure that appropriate log levels are used

In scope

Release of new nuget package

Out of scope

Supporting any logger other Microsoft.Extensions.Logger

Examples

The idea is to make it as simple for developer to enable and as such the idea would be:

builder.Services.AddHealthPublisherLogger();

Or

builder.Services.AddHealthPublisherDiagnosticSource();

Obviously it should be possible to define the HealthCheckPublisherOptions just like if it was explicitly added.

Detailed design

To eliminate log spam The following mapping of the health status is needed.

For diagnostic source the key thing is all the attributes of report data are exposed as attributes.

davidfowl commented 10 months ago

Why does this need to be in the box? Why not write one for your on prem software?

thompson-tomo commented 10 months ago

Writing one is not the issue, I am more than happy to write it & then it submit it as a PR etc. I am more thinking for key Microsoft libraries ie logger, System.DiagnosticSource should the appropriate publisher be provided in a similar manner to configuration, logging or do we simply rely on third parties to manage it in it's entirety.

thompson-tomo commented 10 months ago

For instance with the System.Diagnostic publisher it would then facilitate aspire to visualise the result of the health checks.

davidfowl commented 10 months ago

If there were a set of concrete scenarios then we would add this. I'll leave this open but I don't see a reason to add this to the framework.

thompson-tomo commented 10 months ago

So the scenarios, I see would be Aspire & OTEL more broadly as they could utilise the metrics such a publisher would have access to & would be able to provide.

At the same time having a publisher writing to logs is useful not just for my case but also for general debugging/development.

davidfowl commented 10 months ago

Right, if that how aspire choses to implement health checks (which isn't the plan right now), that would be a +1, but we don't have a logging publisher as a scenario for health checks.

thompson-tomo commented 10 months ago

I have reworked the description to make it more descriptive and it now encompasses the 2 use cases with the scenarios for each mentioned. Obviously Aspire would fall under the DiagnosticSource option.