All files / src/platform/observability/controllers health.controller.ts

0% Statements 0/33
0% Branches 0/22
0% Functions 0/10
0% Lines 0/29

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100                                                                                                                                                                                                       
import { Controller, Get } from '@nestjs/common';
import { HealthService } from '../services/health.service';
import { MetricsService } from '../services/metrics.service';
import { ApiTags, ApiOperation, ApiResponse } from '@nestjs/swagger';
 
@ApiTags('Health')
@Controller('api/v1/health')
export class HealthController {
  constructor(
    private readonly healthService: HealthService,
    private readonly metricsService: MetricsService,
  ) {}
 
  @Get()
  @ApiOperation({ summary: 'Basic health check' })
  @ApiResponse({ status: 200, description: 'Operation successful' })
  async health() {
    return this.healthService.getLiveness();
  }
 
  @Get('live')
  @ApiOperation({ summary: 'Liveness probe (k8s)' })
  @ApiResponse({ status: 200, description: 'Operation successful' })
  async live() {
    return this.healthService.getLiveness();
  }
 
  @Get('ready')
  @ApiOperation({ summary: 'Readiness probe with component checks' })
  @ApiResponse({ status: 200, description: 'Operation successful' })
  async ready() {
    return this.healthService.getReadiness();
  }
}
 
@ApiTags('Admin Health')
@Controller('api/v1/admin/health')
export class AdminHealthController {
  constructor(
    private readonly healthService: HealthService,
    private readonly metricsService: MetricsService,
  ) {}
 
  @Get('summary')
  @ApiOperation({ summary: 'Full system health summary' })
  @ApiResponse({ status: 200, description: 'Operation successful' })
  async summary() {
    return this.healthService.getSummary();
  }
 
  @Get('metrics')
  @ApiOperation({ summary: 'Application metrics snapshot' })
  @ApiResponse({ status: 200, description: 'Operation successful' })
  async metrics() {
    return this.metricsService.getAllMetrics();
  }
 
  @Get('database')
  @ApiOperation({ summary: 'Database health check' })
  @ApiResponse({ status: 200, description: 'Operation successful' })
  async database() {
    const summary = await this.healthService.getSummary();
    return (
      summary['mongodb'] ?? {
        component: 'mongodb',
        status: 'unknown',
        checkedAt: new Date().toISOString(),
      }
    );
  }
 
  @Get('redis')
  @ApiOperation({ summary: 'Redis health check' })
  @ApiResponse({ status: 200, description: 'Operation successful' })
  async redis() {
    const summary = await this.healthService.getSummary();
    return (
      summary['redis'] ?? {
        component: 'redis',
        status: 'unknown',
        checkedAt: new Date().toISOString(),
      }
    );
  }
 
  @Get('queues')
  @ApiOperation({ summary: 'BullMQ queue health' })
  @ApiResponse({ status: 200, description: 'Operation successful' })
  async queues() {
    const summary = await this.healthService.getSummary();
    return (
      summary['queues'] ?? {
        component: 'queues',
        status: 'unknown',
        checkedAt: new Date().toISOString(),
      }
    );
  }
}