Skip to content

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

Open
@Ben555555

Description

@Ben555555

Is there an existing issue for this?

  • 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<HealthCheckPublisherOptions>(options =>
{
    options.Delay = TimeSpan.FromSeconds(2); // Initial delay
    options.Period = TimeSpan.FromSeconds(60); // delay between checks
    options.Predicate = _ => true;
});

services.AddSingleton<IHealthCheckPublisher, PeriodHealthCheckPublisher>();

services.AddHealthChecks();

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-healthchecksIncludes: Healthchecks (some bugs also in Extensions repo)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions