-
Notifications
You must be signed in to change notification settings - Fork 1
health check #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
health check #15
Conversation
📝 WalkthroughWalkthrough이번 변경사항은 NestJS 애플리케이션에 헬스 체크 기능을 추가합니다. Changes
Sequence Diagram(s)sequenceDiagram
participant C as Client
participant HC as HealthController
participant TM as TerminusModule
participant DB as PrismaService
C->>HC: GET /health 요청
HC->>TM: 헬스 체크 실행 (HTTP, 메모리, DB)
TM-->>HC: 헬스 상태 응답 (Aggregate 결과)
HC->>C: 헬스 상태 결과 반환
Poem
Tip ⚡🧪 Multi-step agentic review comment chat (experimental)
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (3)
src/health/health.module.ts (1)
16-17: HealthController를 exports에 추가하고 빈 providers 배열 제거 권장현재 HealthModule에는 빈 providers 배열이 있습니다. 필요하지 않은 경우 이를 제거하는 것이 좋습니다. 또한, AppModule에서 HealthController를 직접 사용할 수 있도록 controllers를 exports에 추가하는 것이 필요합니다.
@Module({ imports: [ TerminusModule.forRoot({ errorLogStyle: 'pretty', logger: true, }), CustomConfigModule, PrismaModule, ], - providers: [], controllers: [HealthController], + exports: [HealthController], }) export class HealthModule {}또는 AppModule에서 HealthController를 직접 선언하지 않고 HealthModule만 가져오는 방식이 더 바람직합니다.
src/health/health.controller.ts (2)
27-37: 헬스체크 로직 개선 제안헬스체크 엔드포인트가 잘 구현되었습니다. 다음 개선사항을 고려해보세요:
- 메모리 제한(150MB)을 하드코딩하는 대신 CustomConfigService를 통해 구성 가능하게 만들면 환경에 따라 유연하게 조정할 수 있습니다.
- 외부 서비스 URL이 비어있거나 잘못된 형식인 경우에 대한 예외 처리가 필요할 수 있습니다.
- 디스크 공간 사용량 같은 추가적인 헬스 지표를 고려해보세요.
@Get() @HealthCheck() async check() { this.logger.log('Health check'); return this.health.check([ () => - this.http.pingCheck('infoteam-idp', this.configService.IDP_BASE_URL), + this.configService.IDP_BASE_URL + ? this.http.pingCheck('infoteam-idp', this.configService.IDP_BASE_URL) + : Promise.resolve({ infoteam_idp: { status: 'down', message: 'IDP_BASE_URL not configured' }}), () => this.prisma.pingCheck('database', this.prismaService), - () => this.memory.checkRSS('memory_rss', 1024 * 1024 * 150), + () => this.memory.checkRSS('memory_rss', this.configService.MEMORY_LIMIT_MB * 1024 * 1024 || 1024 * 1024 * 150), ]); }
1-13: Swagger API 문서에 더 자세한 정보 추가 제안현재 헬스체크 엔드포인트에는
@ApiTags('health')데코레이터만 적용되어 있습니다. API 소비자에게 더 많은 정보를 제공하기 위해 다음과 같은 추가 데코레이터를 고려해보세요:import { Controller, Get, Logger } from '@nestjs/common'; import { CustomConfigService } from '@lib/custom-config'; import { PrismaService } from '@lib/prisma'; import { HealthCheck, HealthCheckService, HttpHealthIndicator, MemoryHealthIndicator, PrismaHealthIndicator, } from '@nestjs/terminus'; -import { ApiTags } from '@nestjs/swagger'; +import { ApiTags, ApiOperation, ApiResponse } from '@nestjs/swagger'; @ApiTags('health') @Controller('health') export class HealthController {그리고 check 메서드에 다음과 같은 데코레이터를 추가하는 것이 좋습니다:
@Get() @HealthCheck() +@ApiOperation({ summary: '애플리케이션 상태 확인', description: '외부 서비스, 데이터베이스, 메모리 사용량을 확인합니다.' }) +@ApiResponse({ status: 200, description: '모든 서비스가 정상 작동 중' }) +@ApiResponse({ status: 503, description: '하나 이상의 서비스에 문제가 있음' }) async check() {
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
package-lock.jsonis excluded by!**/package-lock.json
📒 Files selected for processing (4)
package.json(1 hunks)src/app.module.ts(1 hunks)src/health/health.controller.ts(1 hunks)src/health/health.module.ts(1 hunks)
🔇 Additional comments (1)
package.json (1)
32-32: 헬스체크 기능을 위한 @nestjs/terminus 패키지 추가NestJS 애플리케이션의 상태 모니터링을 위한 terminus 패키지가 적절히 추가되었습니다.
| import { HealthController } from './health/health.controller'; | ||
| import { HealthModule } from './health/health.module'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
HealthController를 AppModule에 직접 등록하지 말고 HealthModule을 통해서만 접근하는 것이 좋습니다
현재 구조에서는 HealthController가 두 곳에서 선언되고 있습니다:
- AppModule의 controllers 배열에 직접 포함
- HealthModule의 controllers 배열에도 포함
NestJS의 모듈 패턴에 따르면, 컨트롤러는 일반적으로 특정 모듈 내에서만 선언되고, 해당 모듈을 가져오면 컨트롤러도 자동으로 사용 가능해집니다. 따라서 다음과 같이 수정하는 것이 좋습니다:
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { UserModule } from './user/user.module';
import { ImageModule } from './image/image.module';
import { EmailModule } from './email/email.module';
-import { HealthController } from './health/health.controller';
import { HealthModule } from './health/health.module';
@Module({
imports: [UserModule, ImageModule, EmailModule, HealthModule],
- controllers: [AppController, HealthController],
+ controllers: [AppController],
providers: [AppService],
})
export class AppModule {}Also applies to: 11-12
health check
Summary by CodeRabbit