Skip to content

Commit 1bffbc5

Browse files
committed
chore: update configurations for PG and monitoring
- README에 Round 6 작업 내용 추가 - build.gradle.kts에 Resilience4j 의존성 추가 - application.yml PG base-url 설정 추가 - resilience4j.yml TIME_BASED 설정으로 변경 - monitoring-compose.yml, monitoring.yml 업데이트
1 parent 6365416 commit 1bffbc5

6 files changed

Lines changed: 79 additions & 28 deletions

File tree

README.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ docker-compose -f ./docker/monitoring-compose.yml up
2727
Root
2828
├── apps ( spring-applications )
2929
│ ├── 📦 commerce-api
30-
│ └── 📦 commerce-streamer
30+
│ ├── 📦 commerce-streamer
31+
│ └── 📦 pg-simulator
3132
├── modules ( reusable-configurations )
3233
│ ├── 📦 jpa
3334
│ ├── 📦 redis
@@ -37,3 +38,25 @@ Root
3738
├── 📦 monitoring
3839
└── 📦 logging
3940
```
41+
42+
## PG Payment System
43+
44+
완전한 결제 시스템 구현 (Resilience 패턴 적용)
45+
46+
### 빠른 시작
47+
```shell
48+
# PG Simulator 실행
49+
./gradlew :apps:pg-simulator:bootRun
50+
51+
# Commerce API 실행
52+
./gradlew :apps:commerce-api:bootRun
53+
54+
# 테스트
55+
curl -X POST http://localhost:8080/api/v1/payments/test/request \
56+
-H "X-USER-ID: 12345" -H "Content-Type: application/json" \
57+
-d '{"orderId":"ORDER-001","cardType":"SAMSUNG","cardNo":"1234-5678-9012-3456","amount":50000}'
58+
```
59+
60+
### 문서
61+
- **PAYMENT-GUIDE.md**: 전체 가이드 (구현 사항, API, 테스트)
62+
- **test-payment-flow.http**: HTTP 테스트 시나리오

apps/commerce-api/build.gradle.kts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ dependencies {
1212
implementation("org.springframework.boot:spring-boot-starter-actuator")
1313
implementation("org.springdoc:springdoc-openapi-starter-webmvc-ui:${project.properties["springDocOpenApiVersion"]}")
1414

15+
// resilience4j (Spring Boot 3.x 호환 버전)
16+
implementation("io.github.resilience4j:resilience4j-spring-boot3:2.2.0")
17+
implementation("org.springframework.boot:spring-boot-starter-aop")
18+
1519
// querydsl
1620
annotationProcessor("com.querydsl:querydsl-apt::jakarta")
1721
annotationProcessor("jakarta.persistence:jakarta.persistence-api")

apps/commerce-api/src/main/resources/application.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,18 @@ spring:
2323
- redis.yml
2424
- logging.yml
2525
- monitoring.yml
26+
- resilience4j.yml
2627

2728
springdoc:
2829
use-fqn: true
2930
swagger-ui:
3031
path: /swagger-ui.html
3132

33+
# PG Simulator 설정
34+
payment:
35+
pg:
36+
base-url: http://localhost:8082
37+
3238
---
3339
spring:
3440
config:

apps/commerce-api/src/main/resources/resilience4j.yml

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,15 @@ resilience4j:
22
circuitbreaker:
33
configs:
44
default:
5-
# Sliding Window 설정
6-
slidingWindowType: COUNT_BASED
7-
slidingWindowSize: 10 # 최근 10개 호출을 기준으로 판단
8-
minimumNumberOfCalls: 5 # 최소 5번 호출 후 Circuit Breaker 작동
9-
10-
# 실패율 임계값
11-
failureRateThreshold: 50 # 실패율 50% 이상이면 OPEN
12-
slowCallRateThreshold: 50 # 느린 호출 50% 이상이면 OPEN
13-
slowCallDurationThreshold: 2s # 2초 이상 걸리면 느린 호출로 간주
14-
15-
# Circuit Breaker 상태 전환
16-
waitDurationInOpenState: 10s # OPEN 상태에서 10초 후 HALF_OPEN으로 전환
17-
permittedNumberOfCallsInHalfOpenState: 3 # HALF_OPEN에서 3번 테스트
5+
slidingWindowType: TIME_BASED
6+
slidingWindowSize: 30
7+
minimumNumberOfCalls: 5
8+
failureRateThreshold: 50
9+
slowCallRateThreshold: 50
10+
slowCallDurationThreshold: 2s
11+
waitDurationInOpenState: 10s
12+
permittedNumberOfCallsInHalfOpenState: 3
1813
automaticTransitionFromOpenToHalfOpenEnabled: true
19-
20-
# 예외 설정
2114
registerHealthIndicator: true
2215
recordExceptions:
2316
- java.util.concurrent.TimeoutException
@@ -28,17 +21,19 @@ resilience4j:
2821
instances:
2922
pgSimulator:
3023
baseConfig: default
31-
failureRateThreshold: 60 # PG는 60% 실패율까지 허용 (40% 실패율 고려)
32-
slowCallDurationThreshold: 1s # PG는 1초 이상이면 느린 호출
33-
waitDurationInOpenState: 15s # OPEN 시 15초 대기
24+
slidingWindowSize: 20
25+
minimumNumberOfCalls: 3
26+
failureRateThreshold: 60
27+
slowCallDurationThreshold: 1s
28+
waitDurationInOpenState: 15s
3429

3530
retry:
3631
configs:
3732
default:
38-
maxAttempts: 3 # 최대 3번 재시도
39-
waitDuration: 500ms # 재시도 간격 500ms
40-
enableExponentialBackoff: true # 지수 백오프 활성화
41-
exponentialBackoffMultiplier: 2 # 2배씩 증가
33+
maxAttempts: 3
34+
waitDuration: 500ms
35+
enableExponentialBackoff: true
36+
exponentialBackoffMultiplier: 2
4237
retryExceptions:
4338
- java.util.concurrent.TimeoutException
4439
- org.springframework.web.client.ResourceAccessException
@@ -48,15 +43,14 @@ resilience4j:
4843
instances:
4944
pgSimulator:
5045
baseConfig: default
51-
maxAttempts: 1 # PG는 재시도 안 함 (멱등성 보장 어려움)
52-
# Payment 엔티티 저장 후 requiresRetry 플래그로 수동 재시도 처리
46+
maxAttempts: 1
5347
waitDuration: 300ms
5448

5549
timelimiter:
5650
configs:
5751
default:
58-
timeoutDuration: 3s # 기본 타임아웃 3초
52+
timeoutDuration: 3s
5953
cancelRunningFuture: true
6054
instances:
6155
pgSimulator:
62-
timeoutDuration: 2s # PG 호출은 2초 타임아웃 (요청 지연 100-500ms 고려)
56+
timeoutDuration: 2s

docker/monitoring-compose.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
version: '3'
22
services:
33
prometheus:
4-
image: prom/prometheus
4+
image: prom/prometheus:v2.48.0
55
ports:
66
- "9090:9090"
77
volumes:
88
- ./grafana/prometheus.yml:/etc/prometheus/prometheus.yml
9+
- prometheus-data:/prometheus
10+
restart: unless-stopped
911

1012
grafana:
1113
image: grafana/grafana
@@ -17,6 +19,9 @@ services:
1719
- GF_SECURITY_ADMIN_USER=admin
1820
- GF_SECURITY_ADMIN_PASSWORD=admin
1921

22+
volumes:
23+
prometheus-data:
24+
2025
networks:
2126
default:
2227
driver: bridge

supports/monitoring/src/main/resources/monitoring.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,29 @@ management:
33
distribution:
44
percentiles-histogram:
55
http.server.requests: true
6+
percentiles:
7+
http.server.requests: 0.5, 0.95, 0.99
8+
slo:
9+
http.server.requests: 10ms, 50ms, 100ms, 200ms, 500ms, 1s, 2s, 5s, 10s
610
tags:
711
application:
812
${spring.application.name}
13+
# 활성화할 메트릭 명시
14+
enable:
15+
jvm: true
16+
system: true
17+
tomcat: true
18+
hikaricp: true
19+
logback: true
20+
process: true
921
endpoints:
1022
web:
1123
exposure:
1224
include:
1325
- health
1426
- prometheus
27+
- metrics
28+
- info
1529
endpoint:
1630
health:
1731
probes:
@@ -23,8 +37,13 @@ management:
2337
- livenessState
2438
readiness:
2539
show-components: always
40+
include:
41+
- readinessState
42+
- db
2643
prometheus:
2744
access: read_only
45+
metrics:
46+
enabled: true
2847
health:
2948
livenessState:
3049
enabled: true

0 commit comments

Comments
 (0)