- 문제: URL 조합 시 슬래시 3개 발생 (///api/stats/rb8001) - 해결: settings.get_monitor_stats_url() 메서드로 정규화 - 결과: 슬래시 정규화 완료, 200 OK 확인 - 상태: 미해결 → 해결 완료 (efca09f) 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
89 lines
2.3 KiB
Markdown
89 lines
2.3 KiB
Markdown
# Gateway Redis 통합 및 Stats API 수정
|
|
|
|
## 날짜: 2025-09-26
|
|
## 작성자: happybell80
|
|
## 관련 서비스: robeing-gateway
|
|
## 상태: 해결 완료
|
|
|
|
---
|
|
|
|
## 1. 문제 발생
|
|
|
|
### Stats API URL 이중 슬래시
|
|
- **증상**: Gateway → Monitor 요청 시 `///api/stats//rb8001`
|
|
- **원인**: MONITOR_URL과 MONITOR_STATUS_URI 연결 시 슬래시 중복
|
|
- **위치**: `robeing-gateway/app/main.py:290`
|
|
|
|
### 헬스체크 실패
|
|
- **증상**: Actions에서 localhost:8100/healthz 연결 거부
|
|
- **원인**: 컨테이너 시작 지연
|
|
|
|
---
|
|
|
|
## 2. 해결 방법
|
|
|
|
### Stats API 수정
|
|
**서버 .env 수정**:
|
|
```bash
|
|
MONITOR_STATUS_URI=/api/stats # 앞 슬래시만 유지
|
|
```
|
|
|
|
### Redis 연결 설정
|
|
**서버 .env 추가**:
|
|
```bash
|
|
REDIS_HOST=auth-redis # auth-server의 Redis 컨테이너 공유
|
|
REDIS_PORT=6379
|
|
```
|
|
|
|
---
|
|
|
|
## 3. 아키텍처
|
|
|
|
### 캐시 구조
|
|
- **UserCache**: 사용자-로빙 매핑 (메모리, 30분 TTL)
|
|
- **Redis**: Rate limiting (auth-redis 컨테이너)
|
|
|
|
### 네트워크
|
|
- 모든 컨테이너가 appnet 네트워크 공유
|
|
- auth-redis:6379로 직접 통신 가능
|
|
|
|
---
|
|
|
|
## 4. 확인 방법
|
|
```bash
|
|
docker inspect robeing-gateway auth-redis | grep -A2 "Networks"
|
|
```
|
|
|
|
## 5. 결과
|
|
- ✅ Stats API 정상 작동
|
|
- ✅ Redis 연결 성공 (rate limiting)
|
|
- ✅ 헬스체크 통과
|
|
|
|
---
|
|
|
|
## 6. Stats API 슬래시 중복 문제 해결 (2025-09-27)
|
|
|
|
### 문제
|
|
- **증상**: `http://192.168.219.52:9024///api/stats/rb8001` 404 응답 (1분마다)
|
|
- **원인**: URL 조합 시 슬래시 중복 (`MONITOR_URL` 끝 + `MONITOR_STATUS_URI` 앞 + f-string 내부)
|
|
- **기존 코드**: `main.py:290` - `f"{env_setting.MONITOR_URL}/{env_setting.MONITOR_STATUS_URI}/{robeing_id}"`
|
|
|
|
### 해결 방법
|
|
**settings.py에 URL 생성 메서드 추가**:
|
|
```python
|
|
def get_monitor_stats_url(self, robeing_id: str) -> str:
|
|
monitor_url = str(self.MONITOR_URL).rstrip('/') if self.MONITOR_URL else ""
|
|
status_uri = self.MONITOR_STATUS_URI.strip('/') if self.MONITOR_STATUS_URI else ""
|
|
return f"{monitor_url}/{status_uri}/{robeing_id}"
|
|
```
|
|
|
|
**main.py 수정**:
|
|
```python
|
|
target_url = env_setting.get_monitor_stats_url(robeing_id)
|
|
```
|
|
|
|
### 결과
|
|
- ✅ 슬래시 정규화: `///` → `/`
|
|
- ✅ URL 생성 로직 중앙화
|
|
- ✅ 환경변수 설정 오류 방지
|
|
- **상태**: 해결 완료 (efca09f) |