HealthChecks icon indicating copy to clipboard operation
HealthChecks copied to clipboard

Add check based on counters threshold

Open ycrumeyrolle opened this issue 7 years ago • 5 comments

Checks based on counter are useful for detecting transient failures recurrence. For example :

try
{
  // do some stuff that can fail
  // ...
  counter.Reset();
}
catch
{
  counter.Increment();
  throw;
}

Where the counter reach the threshold, the check is unhealthy.

ycrumeyrolle avatar Mar 21 '17 21:03 ycrumeyrolle

What registration syntax would you expect to see for this check? I assume it is an IHealthCheck that wraps another IHealthCheck, what would it look like to register that?

glennc avatar Mar 27 '17 23:03 glennc

I like the idea. It could look like the HealthCheckGroup: https://github.com/aspnet/HealthChecks/pull/16

checks.AddRetryCheck("checks-to-retry", group =>
                {
                    group.AddUrlCheck("https://github.com");
                }, 
                threshold: 5, 
                delay: TimeSpan.FromSeconds(5), 
                partiallyStatus: CheckStatus.Unhealthy);

JuergenGutsch avatar Mar 28 '17 06:03 JuergenGutsch

My main concern is to check health of not checkable components. I have a concrete use case of web service that only accept request that modify data. And I pay for each request.

The registration mat be similar to other checks. Here is what I have done in my custom repo: https://github.com/ycrumeyrolle/HealthCheck/blob/master/samples/HealthSample/Startup.cs#L77

ycrumeyrolle avatar Mar 28 '17 06:03 ycrumeyrolle

I'm going to try something and will create a PR

JuergenGutsch avatar Mar 29 '17 09:03 JuergenGutsch

Tried to implement with a ICounter giving the ability to have a local n-memory counter or a distributed counter. I am facing to the problem that checks are not DI DI friendly. I have the following interfaces :


    public interface ICounterProvider
    {
        ICounter GetCounter(string name);
    }

    public interface ICounter
    {
        string Name { get; }
        long Decrement(long decrementBy);
        long Increment(long incrementBy);
        long Value { get; set; }
        void Reset();
    }

I can easily inject the ICounterProvider into any Di-friendly class (controller, middleware & any container-controlled class), but not in the HealthCheck class. Opened the issue #37

ycrumeyrolle avatar Mar 29 '17 20:03 ycrumeyrolle