Xabaril / AspNetCore.Diagnostics.HealthChecks

Enterprise HealthChecks for ASP.NET Core Diagnostics Package
Apache License 2.0
4.07k stars 793 forks source link

Customized Polling per Health Check #1722

Open RoLYroLLs opened 1 year ago

RoLYroLLs commented 1 year ago

What would you like to be added: Ability to set a separate EvaluationTimeIsSeconds per health check. Ability to manually poll zero or more health checks. Include MinimumSecondsBetweenFailureNotifications per health check as well. The current EvaluationTimeIsSeconds and MinimumSecondsBetweenFailureNotifications can be kept as the default values for anything not specifically defined.

Why is this needed: I have certain services that need to be polled more frequently than others, ie: once a minute, while others once every 10 minutes. I even have another service where I don't want the app to poll until I ask it to.

Having this feature will greatly allow different users to customize polling of each of their health checks based on their own needs and open the UI to more users. This was a feature of an old UI I used 15+ years ago, wish I remembered what it was.

Keep up the great work!

sungam3r commented 1 year ago

PR is welcome.

sungam3r commented 1 year ago

It will require changes in design. Now HealthCheckCollectorHostedService spins up while loop calling HealthCheckReportCollector.Collect that iterates through the list of HealthCheckConfiguration. Each such configuration is uri to some service that eventually has 0 or more healtchecks inside. In that regard I would like to highlight that part in your suggestion:

Ability to set a separate EvaluationTimeIsSeconds per health check.

Do you mean per health check AS per registered by AddHealthCheckEndpoint API uri like these ones? изображение

RoLYroLLs commented 1 year ago

@sungam3r Yes, per AddHealthCheckEndpoint. I think it would add a great deal of customization and make it even more useful.

sungam3r commented 1 year ago

The main question is how to deal with independent pollings without exsessive complexity.

cieciurm commented 1 year ago

Hi everyone,

I'm just trying to understand this.

What was suggested is something like this in appsettings.json:

"HealthChecksUI": {
    "HealthChecks": [
      {
        "Name": "Name1",
        "Uri": "URL1",
        "EvaluationTimeinSeconds": 100,
        "MinimumSecondsBetweenFailureNotifications": 200
      },
      {
        "Name": "Name2",
        "Uri": "URL2"
      }
    ],
    "EvaluationTimeinSeconds": 10,
    "MinimumSecondsBetweenFailureNotifications": 60
}

In this example, first Health Check has overriding settings, while the second one uses the default ones. Did I get this right?

So, in back-end code we'd need to extend HealthCheckConfiguration with two additional properties.

Then, the next step would be to expose those information to the front-end by extending response for /health/ui-settings. Currently the response contains:

{
  "pollingInterval": 10,
  "headerText":"Health Checks Status"
}

Possibly with something like:

{
  // ...
  "healthchecks": {
     "name1": {
         "pollingInterval": 100
     }
  }
}

And the final step is to use config for name1 and the defaults and split polling depending on the interval.

I see the biggest complexity in the UI, because right now it only polls by single interval - it would need to become way smarter to be able to poll in the new way.

sungam3r commented 1 year ago

I think you understood it right.