Search code examples
c#health-checkocelot

Ocelot Gateway Healthcheck


I want to add an Ocelot Gateway healthcheck, but

  1. This is nowhere to be found as default nuget package from AspNetCore.HealthChecks.??? . Is this not done usually?
  2. When adding the healthcheck myself, and mapping a healthcheck on startup, navigation to the url wants to redirect me to a downstream. (code below)
    var builder = WebApplication.CreateBuilder(args);
    
    builder.Services.AddHealthChecks();
    builder.Configuration.AddOcelot(builder.Environment);

    var app = builder.Build();
    app.UseOcelot();
    app.MapHealthChecks("/_health", new HealthCheckOptions
    {
        ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse
    });
    app.Run();

Anyone any clue on how to do this?


Solution

  • Solved thanks to Artur in comments above.
    Just add UseRouting(), MapHealthChecks() and UseEndpoints() BEFORE the UseOcelot() method.

    var builder = WebApplication.CreateBuilder(args);
    
    builder.Services.AddHealthChecks();
    builder.Configuration.AddOcelot(builder.Environment);
    
    var app = builder.Build();
    app.UseRouting();
    
    app.MapHealthChecks("/_health", new HealthCheckOptions
    {
        ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse
    });
    app.UseEndpoints(e =>
    {
        e.MapControllers();
    });
    app.UseOcelot();
    app.Run();