dotnet / dotnet/aspnetcore

HealthCheck add possibility to cache checks and protect API from DDOS attacks

Open
#59,561 0 comments 1 reaction 0 assignees View on GitHub
area-healthchecks
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 6h
Merged PRs (30d)
290

Description

### Is there an existing issue for this?

- [x] I have searched the existing issues

### Is your feature request related to a problem? Please describe the problem.

Currently there is no way to run health checks like DbContextCheck periodically. Therefor the Health check endpoints can be abused to be very exhaustive for the API.

### Describe the solution you'd like

There are already HealthCheckPublishers but currently even when they are applied the checks are made on each request. It would be nice if there was an option to use this also for returning the last published check results. It would be even better to be able to cache the results without an additional publisher by just using an additional setting or allowing to hook into the process to add a cache.

### Additional context

```
public class PeriodHealthCheckPublisher : IHealthCheckPublisher
{
public Task PublishAsync(HealthReport report, CancellationToken cancellationToken)
{
return Task.CompletedTask;
}
}

services.Configure(options =>
{
options.Delay = TimeSpan.FromSeconds(2); // Initial delay
options.Period = TimeSpan.FromSeconds(60); // delay between checks
options.Predicate = _ => true;
});

services.AddSingleton();

services.AddHealthChecks();
```

Currently whenever the healthcheck endpoint is called all the checks are executed again.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.