feat(health): include degraded reasons in responses

This commit is contained in:
2026-04-21 13:34:58 +00:00
parent 703cceb512
commit 9022c8dbf3
4 changed files with 84 additions and 1 deletions
+9
View File
@@ -210,6 +210,7 @@ export class ApiServer {
const models = await this.containerManager.getAllAvailableModels();
let status: 'ok' | 'degraded' | 'error' = 'ok';
const reasons = new Set<'unhealthy_container' | 'no_models_available' | 'gpu_detection_failed'>();
const containerHealth: Record<string, 'healthy' | 'unhealthy'> = {};
const gpuStatus: Record<string, 'available' | 'in_use' | 'error'> = {};
@@ -220,6 +221,7 @@ export class ApiServer {
} else {
containerHealth[id] = 'unhealthy';
status = 'degraded';
reasons.add('unhealthy_container');
}
}
@@ -228,8 +230,14 @@ export class ApiServer {
gpuStatus[gpu.id] = 'available';
}
if (models.size === 0) {
status = 'degraded';
reasons.add('no_models_available');
}
const response: IHealthResponse = {
status,
reasons: Array.from(reasons),
version: VERSION,
uptime: Math.floor((Date.now() - this.startTime) / 1000),
containers: statuses.size,
@@ -247,6 +255,7 @@ export class ApiServer {
res.writeHead(500, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({
status: 'error',
reasons: ['gpu_detection_failed'],
error: error instanceof Error ? error.message : String(error),
}));
}