Xabaril / AspNetCore.Diagnostics.HealthChecks

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

Not clear how to consume the UI #2303

Open chivandikwa opened 1 week ago

chivandikwa commented 1 week ago

EDIT - Resolved

Not clear how to consume the UI

What happened:

I am unable to setup the health check UI and even after browsing open and closed issues, the answer is not clear.

I have health checks setup in my startup, sample

services.AddHealthChecks()
            .AddApplicationStatus(name: "Application Status")
            ....

I then setup the UI as documented

services
            .AddHealthChecksUI()
            .AddInMemoryStorage();

The same for the rest of the bootstrapping

        app.UseHealthChecks("/healthz", new HealthCheckOptions
        {
            Predicate = _ => true,
            ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse
        });

        app
            .UseRouting()
            .UseEndpoints(config => config.MapHealthChecksUI());

Now if I leave the default for MapHealthChecksUI, the UI is empty even though /healthz returns data formatted for the UI.

If I then update the Api URL to point to /healthz then I get a console error saying map is not a function and nothing is loaded in the UI again.

What is the correct way to configure the UI

What you expected to happen:

To be able to get the UI to show the health checks.

Thanks for looking into this

Environment:

chivandikwa commented 1 week ago

Ok, so finally found a working answer


        services
            .AddHealthChecksUI(opt =>
            {
                opt.AddHealthCheckEndpoint("API", "/api/health");
            })
            .AddInMemoryStorage();

        services
            .AddHealthChecks()
            .AddApplicationStatus(name: "Application Status")
           ...

        app.UseHealthChecks("/api/health", new HealthCheckOptions
        {
            Predicate = _ => true,
            ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse
        });

        app.UseEndpoints(endpoints =>
        {
            endpoints.MapHealthChecksUI(opt =>
            {
                opt.UIPath = "/healthcheck-ui";
            });
        });