Xabaril / AspNetCore.Diagnostics.HealthChecks

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

When use method SetNotifyUnHealthyOneTimeUntilChange stop polling API's endpoints health checks #2059

Open wilbertCeiba opened 11 months ago

wilbertCeiba commented 11 months ago

Please, fill the following sections to help us fix the issue

What happened: By implementing the SetNotifyUnHealthyOneTimeUntilChange method in the configuration to avoid spam notifications through a webhook, the polling of the configured APIs, which is 10 seconds, stops and does not poll any API again. And when I remove the SetNotifyUnHealthyOneTimeUntilChange configuration the API's polling works correctly.

What you expected to happen: That when implementing the SetNotifyUnHealthyOneTimeUntilChange method, the polling of the configured APIs will continue to execute normally

How to reproduce it (as minimally and precisely as possible): I simply added the SetNotifyUnHealthyOneTimeUntilChange method in the AddHealthChecksUI configuration and the API's polling stopped.

Source code sample:

builder.Services.AddHealthChecksUI(setup =>
{
    setup.SetNotifyUnHealthyOneTimeUntilChange(); //Add this line generated the issue
    SetupHealthEndpoints(setup); //Own method, below is the definition
    SetupWebhooks(setup); //Own method, below is the definition
    setup.SetHeaderText("Superapp Health Check DashBoard");
    setup.SetEvaluationTimeInSeconds(int.Parse(Environment.GetEnvironmentVariable("EVALUATIONTIME") ?? "10"));
    setup.SetMinimumSecondsBetweenFailureNotifications(int.Parse(Environment.GetEnvironmentVariable("FAILURENOTIFICATIONSTIME") ?? "60"));
    setup.MaximumHistoryEntriesPerEndpoint(int.Parse(Environment.GetEnvironmentVariable("MAXIMUMHISTORYENTRIES") ?? "60"));
}).AddSqlServerStorage(Environment.GetEnvironmentVariable("DATABASE_CONNECTION")?? "");

static void SetupHealthEndpoints(Settings setup)
{
    var healthEndpoints = JsonConvert.DeserializeObject<List<HealthEndpointDto>>(Environment.GetEnvironmentVariable("HEALTHCHECK_ENDPOINTS")??"") ?? new List<HealthEndpointDto>();
    if (healthEndpoints.Any())
    {
        foreach (var healthEndpointDto in healthEndpoints)
        {
            setup.AddHealthCheckEndpoint(healthEndpointDto.Name, healthEndpointDto.Url.ToString());
        }
    }
}

static void SetupWebhooks(Settings setup)
{
    var webhooks = JsonConvert.DeserializeObject<List<WebHookDto>>(Environment.GetEnvironmentVariable("WEBHOOKS") ?? "") ?? new List<WebHookDto>();
    if (webhooks.Any())
    {
        foreach (var webhook in webhooks)
        {
            setup.AddWebhookNotification(webhook.Name, webhook.Url.ToString(), webhook.Payload, restorePayload: webhook.RestorePayload);
        }
    }
}

Anything else we need to know?:

Environment:

abeninski commented 10 months ago

I observe the same behavior on .net7