Xabaril / AspNetCore.Diagnostics.HealthChecks

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

EvaluationTimeInSeconds will not set #520

Closed OmerNassie closed 4 years ago

OmerNassie commented 4 years ago

What happened: I followed the examples and the README file, I've set the EvaluationTimeInSeconds property to 300 seconds but it stays on 10 seconds. I tried from Configuration file (appsettings.json) or from the setup settings function but nothing works.

What you expected to happen: I would expect that the EvaluationTimeInSeconds will be changed from 10 seconds to 300.

How to reproduce it (as minimally and precisely as possible): This is my configuration in appsettings.json

"HealthChecksUI": {
    "HealthChecks": [
      {
        "Name": "HTTP-Api-Basic",
        "Uri": "/health"
      }
    ],
    "EvaluationTimeInSeconds": 300,
    "MinimumSecondsBetweenFailureNotifications": 60
 }

My configure Services:

      public void ConfigureService(IServiceCollection services)
       {
        services.AddHealthChecks()
                    .AddSqlServer(Configuration.GetConnectionString("SqlConnection"),
                                  healthQuery: "SELECT 1;",
                                  name: "SqlServer Connection Check",
                                  failureStatus: HealthStatus.Unhealthy,
                                  tags: new string[] { "db", "sql", "sqlserver" })
                    .AddDbContextCheck<DataAccess.Data.ApplicationDataContext>("DbContext Health Check", HealthStatus.Unhealthy, tags: new string[] { "db", "sql", "efcore", "sqlserver" });
            services.AddHealthChecksUI();
     }

My Configure:

    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
                endpoints.MapHealthChecksUI(opts =>
                {
                    opts.UIPath = "/health-ui";
                });
                endpoints.MapHealthChecks("/health", new HealthCheckOptions()
                {
                    Predicate = _ => true,
                    ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse
                });
            });
     }
CarlosLanderas commented 4 years ago

Hello @OmerNassie. I'm not able to reproduce this:

Using appsettings.json:

"HealthChecksUI": {
    "HealthChecks": [
      {
        "Name": "Endpoint1",
        "Uri": "/memory-health"
      }
    ],
    "Webhooks": [],
    "EvaluationTimeinSeconds": 500,
    "MinimumSecondsBetweenFailureNotifications": 60
  }

works for me.

And using

  .AddHealthChecksUI(setupSettings: setup =>
   {
      setup.SetEvaluationTimeInSeconds(300);
   });

works as well.

Could you upload a non-working sample to github?

Thanks

OmerNassie commented 4 years ago

Hi @CarlosLanderas thanks for the quick response! Does the Health Checks UI is correlated with the evaluation time's value? This is what not worked for me. Without opening the health checks UI the evaluation time works perfect.

image

CarlosLanderas commented 4 years ago

@OmerNassie these are two different things. The evaluation time in seconds is used by a background hosted service to poll healthchecks endpoints and store results.

The UI refresh every, is the rate the spa queries the healthchecks UI Api. But the UI api does no trigger the endpoint collection (only queries the latest results). That UI button is just a mechanism to accelerate or delay api polling, depending on the evaluation time you configure for the collection. If you have a EvaluationTimeInSeconds of 500 seconds, you can the increase the UI rate so you decrease useless api calls where data is gonna be the same.