Skip to content

Commit b9214b4

Browse files
authored
Merge pull request #142 from 2025-Shifterz/OFFNAL-25
[OFFNAL-25 / Feat][yunnij]: Health Check API 추가
2 parents 5201456 + 3fe802f commit b9214b4

File tree

6 files changed

+138
-5
lines changed

6 files changed

+138
-5
lines changed

src/main/java/com/offnal/shifterz/global/config/SecurityConfig.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
3838
http.cors().and() //CORS 활성화 추가
3939
.authorizeHttpRequests(authorizeRequests ->
4040
authorizeRequests.requestMatchers(
41+
"/health/**",
42+
"/actuator/health/**",
4143
"/login/**",
4244
"/login/page/**",
4345
"/tokens/reissue",
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
package com.offnal.shifterz.global.health;
2+
3+
import io.swagger.v3.oas.annotations.Operation;
4+
import io.swagger.v3.oas.annotations.media.Content;
5+
import io.swagger.v3.oas.annotations.media.ExampleObject;
6+
import io.swagger.v3.oas.annotations.responses.ApiResponse;
7+
import io.swagger.v3.oas.annotations.tags.Tag;
8+
import lombok.RequiredArgsConstructor;
9+
import org.springframework.boot.actuate.health.HealthComponent;
10+
import org.springframework.boot.actuate.health.HealthEndpoint;
11+
import org.springframework.http.ResponseEntity;
12+
import org.springframework.web.bind.annotation.GetMapping;
13+
import org.springframework.web.bind.annotation.RestController;
14+
15+
@Tag(name = "Health", description = "헬스체크 API")
16+
@RestController
17+
@RequiredArgsConstructor
18+
public class HealthController {
19+
private final HealthEndpoint healthEndpoint;
20+
21+
@Operation(
22+
summary = "Liveness Check",
23+
description = """
24+
애플리케이션 프로세스가 살아있는지 확인합니다.
25+
26+
- status: 전체 상태 (UP/DOWN)
27+
- components.ping: 애플리케이션 자체 상태
28+
"""
29+
)
30+
@ApiResponse(
31+
responseCode = "200",
32+
description = "정상 응답",
33+
content = @Content(
34+
mediaType = "application/json",
35+
examples = @ExampleObject(
36+
name = "Liveness Example",
37+
value = """
38+
{
39+
"status": "UP",
40+
"components": {
41+
"ping": {
42+
"status": "UP"
43+
}
44+
}
45+
}
46+
"""
47+
)
48+
)
49+
)
50+
@GetMapping("/health/liveness")
51+
public ResponseEntity<HealthComponent> liveness() {
52+
return ResponseEntity.ok(healthEndpoint.healthForPath("liveness"));
53+
}
54+
55+
@Operation(
56+
summary = "Readiness Check",
57+
description = """
58+
트래픽을 받을 준비가 되었는지 확인합니다.
59+
60+
- status: 전체 상태 (UP/DOWN)
61+
- components.db: 데이터베이스 연결 상태
62+
- components.redis: Redis 연결 상태
63+
- details: 각 컴포넌트의 추가 정보
64+
"""
65+
)
66+
@ApiResponse(
67+
responseCode = "200",
68+
description = "정상 응답",
69+
content = @Content(
70+
mediaType = "application/json",
71+
examples = @ExampleObject(
72+
name = "Readiness Example",
73+
value = """
74+
{
75+
"status": "UP",
76+
"components": {
77+
"db": {
78+
"status": "UP",
79+
"details": {
80+
"database": "MySQL",
81+
"validationQuery": "isValid()"
82+
}
83+
},
84+
"redis": {
85+
"status": "UP",
86+
"details": {
87+
"version": "8.2.1"
88+
}
89+
}
90+
}
91+
}
92+
"""
93+
)
94+
)
95+
)
96+
@GetMapping("/health/readiness")
97+
public ResponseEntity<HealthComponent> readiness() {
98+
return ResponseEntity.ok(healthEndpoint.healthForPath("readiness"));
99+
}
100+
}

src/main/resources/application-dev.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,9 @@ apple:
4343
encrypt:
4444
aes:
4545
key: ${AES_ENCRYPTION_KEY}
46-
migration:
47-
enabled: true
46+
47+
management:
48+
endpoints:
49+
web:
50+
exposure:
51+
include: health

src/main/resources/application-local.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,9 @@ apple:
4646
encrypt:
4747
aes:
4848
key: ${AES_ENCRYPTION_KEY}
49-
migration:
50-
enabled: true
49+
50+
management:
51+
endpoints:
52+
web:
53+
exposure:
54+
include: health

src/main/resources/application-prod.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,10 @@ springdoc:
4747

4848
encrypt:
4949
aes:
50-
key: ${AES_ENCRYPTION_KEY}
50+
key: ${AES_ENCRYPTION_KEY}
51+
52+
management:
53+
endpoints:
54+
web:
55+
exposure:
56+
include: health

src/main/resources/application.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,20 @@ apple:
4545
token: https://appleid.apple.com
4646
public-key: https://appleid.apple.com/auth/keys
4747
revoke: https://appleid.apple.com/auth/revoke
48+
49+
management:
50+
endpoints:
51+
web:
52+
base-path: /actuator
53+
54+
endpoint:
55+
health:
56+
show-details: never
57+
probes:
58+
enabled: true
59+
group:
60+
liveness:
61+
include: ping
62+
readiness:
63+
include: db, redis
64+

0 commit comments

Comments
 (0)