Readiness Healthcheck with warmup C#
NickName:Jean-Paul Ask DateTime:2020-10-14T15:48:58

Readiness Healthcheck with warmup C#

I am using Readiness healthchecks for my project and want to add a warmup period to it. Dependency Injection is being used to get the warmup task from the Kernel but I am not able to get it because the Readiness Healthcheck is being initialized before the IKernel it seems. I am getting the follow error:

Unable to resolve service for type 'IKernel' while attempting to activate 'Project.Ranking.API.HealthCheck.RankingReadinessHealthCheck'.

How does one use a class to warm up the pod before it is being used. I have not been able to find a working example where someone warms up before the endpoints are available.

UPDATE:

Core.Library Startup.CS

public void CoreConfigureServices(IServiceCollection services) 
{
... other code

            services.AddHealthChecks()
                .AddIdentityServer("https://identity.example.com")
                .AddCheck<IReadinessHealthCheck>("Readiness", failureStatus: null)
                .AddCheck<ILivenessHealthCheck>("Liveness", failureStatus: null);

            services.AddSingleton<ILivenessHealthCheck, LivenessHealthCheck>();
}

public void CoreConfigure(IApplicationBuilder app, IHostEnvironment env)
{
... other code

app.UseHealthChecks("/healthcheck/live", new HealthCheckOptions()
            {
                Predicate = check => check.Name == "Liveness"
            });

            app.UseHealthChecks("/healthcheck/ready", new HealthCheckOptions()
            {
                Predicate = check => check.Name == "Readiness",
            });
}

API Startup.CS

public void ConfigureServices(IServiceCollection services)
{
   CoreConfigureServices(services);

... other code

services.AddSingleton<Core.Library.IReadinessHealthCheck, ReadinessHealthCheck>();
}

public void Configure(IApplicationBuilder app, IHostEnvironment env)
{
CoreConfigure(app, env);

... other code

//Here used to be the warm up, but this is used in the liveness probe and i want to warm up in the readiness probe
//Kernel.Get<IWarmupTask>().Initialize();

Kernel.Bind<IReadinessHealthCheck>().To<ReadinessHealthCheck>();
}

Core.Library BaseReadinessHealthCheck.cs

public abstract class BaseReadinessHealthCheck : IReadinessHealthCheck
    {
        public BaseReadinessHealthCheck()
        {
        }

        private bool StartupTaskCompleted { get; set; } = false;

        public abstract void WarmUp();

        public void CompleteTask()
        {
            StartupTaskCompleted = true;
        }

        public Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default)
        {
            //start tasks
            if (!StartupTaskCompleted)
            {
                Task.Run(() => WarmUp());
            }

            if (StartupTaskCompleted)
            {
                return Task.FromResult(HealthCheckResult.Healthy("The startup task is finished."));
            }

            return Task.FromResult(HealthCheckResult.Unhealthy("The startup task is still running."));
        }
    }

API ReadinessHealthCheck.CS

public class ReadinessHealthCheck : ReadinessHealthCheck
    {
        public ReadinessHealthCheck(IKernel kernel) : base(kernel)
        {
        }

        public override void WarmUp()
        {
// I want to do a warmup here, where it calls IWarmupTask 

            CompleteTask();
        }
    }

Copyright Notice:Content Author:「Jean-Paul」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/64348824/readiness-healthcheck-with-warmup-c-sharp

More about “Readiness Healthcheck with warmup C#” related questions

Readiness Healthcheck with warmup C#

I am using Readiness healthchecks for my project and want to add a warmup period to it. Dependency Injection is being used to get the warmup task from the Kernel but I am not able to get it because...

Show Detail

What is benefit of readiness probe and healthCheck?

I am working on an application that, as I can see is doing multiple health checks? DB readiness probe Another API dependency readiness probe When I look at cluster logs, I realize that my service...

Show Detail

Switching from GKE to Cloud Run - best practices for healthcheck, liveness, readiness and general monitoring

I'm looking towards switching some microservices from GKE to Cloud Run but I'm not able to find out anything related to the healthcheck, liveness, readiness and general monitoring when it goes how ...

Show Detail

Quarkus HealthCheck

Here is my database healthcheck : @Readiness @ApplicationScoped @Slf4j public class DatabaseConnectionHealthCheck implements HealthCheck { @Inject PgPool pgPool; @Override public

Show Detail

docker-compose healthcheck does not work in a way it is expected for making container a run first and then container B

I am using docker compose to run couple of service which depends on each other. Here is part of the docker-compose: backend: build: . command: bash -c "npm run build &amp;&amp; npm start...

Show Detail

Readiness probe failed: Get http://*.*.*.*:8080/***/healthCheck: net/http: request canceled (Client.Timeout exceeded while awaiting headers)

The GCP Error reporting Dashboard is showing following error for one of our production cluster ,could you please help me with it is this an issue or information about the pod is not ready to take t...

Show Detail

EKS Readiness probe failed - httpGet.port: Invalid value

I've tried to use a readiness probe to check my pod's health while deploying using internal api. Below is my readiness config in deployment yaml, readinessProbe: initialDelayS...

Show Detail

Does Kubernetes Liveness and Readiness check if python is running?

I've got a simple question but I can't find out the right answer. I have a couple of pods runnig my applications in python in kubernetes. I didn't implement liveness and readiness yet. When I was t...

Show Detail

Warmup endpoint not working on App Engine

I have a kotlin application on App Engine and I'm trying to set up the warmup endpoint with the code bellow: @RestController @RequestMapping(&quot;/&quot;) class HealthCheck { @GetMapping ...

Show Detail

Init container to wait for rabbit-mq readiness

I saw the example for docker healthcheck of RabbitMQ at docker-library/healthcheck. I would like to apply a similar mechanism to my Kubernetes deployment to await on Rabbit deployment readiness. I'm

Show Detail