- Add ping() method to ValkeyClient and ValkeyService for health checks - Update HealthService to check Valkey connectivity before reporting ready - /health/ready now returns 503 if dependencies are unhealthy - Add detailed checks object showing individual dependency status - Update tests with ValkeyService mock Refs #339 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
39 lines
1.1 KiB
TypeScript
39 lines
1.1 KiB
TypeScript
import { Controller, Get, UseGuards, HttpStatus, HttpException } from "@nestjs/common";
|
|
import { Throttle } from "@nestjs/throttler";
|
|
import { HealthService, ReadinessResult } from "./health.service";
|
|
import { OrchestratorThrottlerGuard } from "../../common/guards/throttler.guard";
|
|
|
|
/**
|
|
* Health check controller for orchestrator service
|
|
*
|
|
* Rate limits:
|
|
* - Health endpoints: 200 requests/minute (higher for monitoring)
|
|
*/
|
|
@Controller("health")
|
|
@UseGuards(OrchestratorThrottlerGuard)
|
|
export class HealthController {
|
|
constructor(private readonly healthService: HealthService) {}
|
|
|
|
@Get()
|
|
@Throttle({ status: { limit: 200, ttl: 60000 } })
|
|
check(): { status: string; uptime: number; timestamp: string } {
|
|
return {
|
|
status: "healthy",
|
|
uptime: this.healthService.getUptime(),
|
|
timestamp: new Date().toISOString(),
|
|
};
|
|
}
|
|
|
|
@Get("ready")
|
|
@Throttle({ status: { limit: 200, ttl: 60000 } })
|
|
async ready(): Promise<ReadinessResult> {
|
|
const result = await this.healthService.isReady();
|
|
|
|
if (!result.ready) {
|
|
throw new HttpException(result, HttpStatus.SERVICE_UNAVAILABLE);
|
|
}
|
|
|
|
return result;
|
|
}
|
|
}
|