Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamically adding health check endpoints #535

Closed
kisalay1988 opened this issue May 19, 2020 · 6 comments
Closed

Dynamically adding health check endpoints #535

kisalay1988 opened this issue May 19, 2020 · 6 comments

Comments

@kisalay1988
Copy link

What would you like to be added: As per current implementation, all the health check endpoints should be added while registering the HealthCheckUI middleware. Consider a case :

  1. There are multiple APIs with multiple versions and their own respective Health Check JSON endpoints.
  2. Depending on the case I want to filter the Health Check UI to show the data for specific versions but that's not possble as all endpoints needs to be configured when registering the UI middleware
  3. Possiblity to add some custom fields to the UI like for each endpoint say, I want to add :
    a. Complete endpoint URL
    b. Date when the API was last built
    c. The username who deployed the API, etc

Why is this needed:
Providing more flexibility to users in customizing the UI as per needs.

I am working on an API project where I actually have such requirement. I am trying to figure out my own way to achieve it.

@CarlosLanderas
Copy link
Contributor

CarlosLanderas commented May 19, 2020

This capability is added in our docker image as the K8s operator is able to publish discovered services to the target UI.

https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks/blob/master/build/docker-images/HealthChecks.UI.Image/Extensions/IEndpointRouteBuilderExtensions.cs#L38

Can you work with containers?

@kisalay1988
Copy link
Author

Let me explain the case which I am trying to implement.

  1. Say I call an API : http://localhost/api/healthcheck?version=1.1
  2. This API call would collect all the API details and the health check endpoints with version 1.1 and then redirect to the UI showing the status only of these endpoints.

@NateB2
Copy link

NateB2 commented Jun 15, 2020

Currently we work around this by dynamically fetching the endpoints from an external data store during startup, adding them in the startup code, and rebooting the web app if the endpoints we want to monitor changes. Hardly ideal - having a way to dynamically add health check endpoints in some fashion would be much better. In our circumstance, we are using Azure App Services and have no plans to migrate to K8s.

@CarlosLanderas
Copy link
Contributor

@NateB2, HealthChecksDb DbContext is now public. You can retrieve it using Dependency Injection and use the underlying storage provider to add, remove or edit your remote endpoints.

https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks/blob/master/src/HealthChecks.UI.Core/Data/HealthChecksDb.cs

@kisalay19
Copy link

@CarlosLanderas .. Great ... Let me implement it in my solution then and check :)

@hartmark
Copy link

For future Googlers also finding this thread.

We wanted to dynamicly add and disable healthchecks, however there's is no active-flag so we need some logic to keep the healthchecks we want to keep.

We ended up building a simple controller that first does a delete and adds back the ones we want to keep.

    [HttpDelete]
    [Route("AllHealthChecks")]
    public void ClearAllHealthChecks()
    {
        healthChecksDb.Configurations.RemoveRange(healthChecksDb.Configurations);
        healthChecksDb.SaveChanges();
    }
    
    [HttpPost]
    [Route("HealthCheck")]
    public void AddHealthCheck(string name, string uri)
    {
        var healthCheckConfiguration = new HealthCheckConfiguration
        {
            Name = name,
            Uri = uri
        };
        healthChecksDb.Configurations.Add(healthCheckConfiguration);
        healthChecksDb.SaveChanges();
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants