HealthChecks
HealthChecks copied to clipboard
Add check based on counters threshold
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.
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?
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);
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
I'm going to try something and will create a PR
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