feat(agent): add health check endpoint and Docker HEALTHCHECK
Migrate from Microsoft.NET.Sdk.Worker to Microsoft.NET.Sdk.Web to enable HTTP health checks. Add /healthz endpoint via AgentHealthCheck (reports healthy when registered with Central). Configure Docker HEALTHCHECK with 30s interval and 15s start period.
This commit is contained in:
1 parent
eafbab5e7a
commit
58f46fe3dd
5 files changed
+66
-8
No files matched your search
@@ -1,7 +1,10 @@
|
||||
using Heimdall.Agent.Services;
|
||||
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
|
||||
using Microsoft.Extensions.Diagnostics.HealthChecks;
|
||||
|
||||
var builder = Host.CreateApplicationBuilder(args);
|
||||
var builder = WebApplication.CreateSlimBuilder(args);
|
||||
|
||||
// HTTP clients
|
||||
builder.Services.AddHttpClient("Central", client =>
|
||||
{
|
||||
client.Timeout = TimeSpan.FromSeconds(10);
|
||||
@@ -12,8 +15,26 @@ builder.Services.AddHttpClient("IpResolver", client =>
|
||||
client.Timeout = TimeSpan.FromSeconds(5);
|
||||
});
|
||||
|
||||
// Agent services
|
||||
builder.Services.AddSingleton<AgentState>();
|
||||
builder.Services.AddHostedService<AgentRegistrationService>();
|
||||
|
||||
var host = builder.Build();
|
||||
host.Run();
|
||||
// Health checks — used by Docker HEALTHCHECK
|
||||
builder.Services.AddHealthChecks()
|
||||
.AddCheck<AgentHealthCheck>("agent_health", tags: ["ready"]);
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// Health endpoint (port 5001 is mapped in Dockerfile)
|
||||
app.MapHealthChecks("/healthz", new HealthCheckOptions
|
||||
{
|
||||
Predicate = _ => true,
|
||||
ResultStatusCodes =
|
||||
{
|
||||
[HealthStatus.Healthy] = StatusCodes.Status200OK,
|
||||
[HealthStatus.Degraded] = StatusCodes.Status200OK,
|
||||
[HealthStatus.Unhealthy] = StatusCodes.Status503ServiceUnavailable,
|
||||
}
|
||||
});
|
||||
|
||||
await app.RunAsync();
|
||||
Reference in new issue
Block a user