Skip to content

Commit

Permalink
feat: 스프링 액추에이터를 통한 DB 테이블 생성 상태 확인
Browse files Browse the repository at this point in the history
  • Loading branch information
donghyuun committed Oct 27, 2024
1 parent 39c3454 commit 78b904f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.helpmeCookies.global.infra;

import com.helpmeCookies.user.repository.UserRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor
public class CustomDatabaseHealthIndicator implements HealthIndicator {

private final UserRepository userRepository;
@Override
public Health health() {
try {
// 테이블이 존재하는지 확인하는 쿼리 (Users 테이블 사용)
long count = userRepository.count();
// 테이블 존재 시 0 이상을 반환
return Health.up().withDetail("Users table exists, count: ", count).build();
} catch (Exception e) {
// 테이블이 없거나 데이터베이스 연결에 문제가 있는 경우
return Health.down(e).withDetail("Users table", "Table missing or database issue")
.build();
}
}
}
2 changes: 1 addition & 1 deletion src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ management:
endpoints:
web:
exposure: # 외부에 노출할 엔드포인트
include: prometheus, health, info, swagger-ui
include: prometheus, health, info
metrics:
tags:
application: "katecam" # 메트릭 데이터에 태그를 추가

0 comments on commit 78b904f

Please sign in to comment.