fix: rb8001 stats API 문서 정확성 수정

- 에러 메시지 위치: brain_service.py:56 (router.py 아님)
- robeing-monitor 경로: /stats/{id} (gateway와 불일치)
- DB 스키마 차이: robeing_id vs robeing_container_id
- 설정값 위치: config.py는 None, state_client.py가 8507 기본값
This commit is contained in:
happybell80 2025-09-15 19:50:41 +09:00
parent f372ee436c
commit 64a77618fa

View File

@ -1,4 +1,4 @@
# rb8001 Stats API 중복 구현 및 Failed to load stats 에러
# rb8001 Stats API 중복 구현 조사
## 작성일: 2025-09-15
## 작성자: happybell80
@ -9,58 +9,55 @@
## 현재 상황
### 에러 메시지
- **발생 위치**: rb8001 컨테이너 시작 시
- **에러**: `Failed to load stats: All connection attempts failed`
- **파일**: `/home/happybell/projects/ivada/rb8001/app/router/router.py:92`
- **발생 위치**: rb8001 brain_service.py
- **에러**: `Failed to fetch stats: {e}`
- **파일**: `/home/happybell/projects/ivada/rb8001/app/brain/brain_service.py:56`
- **참고**: router.py의 `_load_stats_from_state()` 호출은 이미 제거됨
### Stats API 엔드포인트 현황
#### 1. rb8001 내부 구현 (포트 8507)
#### 1. rb8001 내부 구현
- **파일**: `/home/happybell/projects/ivada/rb8001/app/state/state_service.py`
- **GET 엔드포인트**: `@app.get("/api/stats/{robeing_id}")` (67줄)
- **PUT 엔드포인트**: `@app.put("/api/stats/{robeing_id}")` (89줄)
- **DB 모델**: `RobeingStats` in `/home/happybell/projects/ivada/rb8001/app/state/database.py:24-41`
- **테이블명**: `"robeing"`
- **DB 모델**: `RobeingStats` (database.py:24-41)
- 필드: `robeing_id`, `ethics`, `stat_points` 포함
- 테이블명: `"robeing"`
#### 2. robeing-monitor 구현 (포트 9024)
- **서버**: 51124
- **서비스**: robeing-monitor
- **포트**: 9024
- **용도**: Stats 관리 담당
- **파일**: `/home/happybell/projects/ivada/robeing-monitor/app/state/state_service.py`
- **GET 엔드포인트**: `@app.get("/stats/{robeing_id}")` (53줄) - `/api` 없음
- **PUT 엔드포인트**: `@app.put("/stats/{robeing_id}")` (75줄) - `/api` 없음
- **DB 모델**: `RobeingStats` (database.py:20-34)
- 필드: `robeing_container_id` 사용 (`robeing_id` 아님)
- `ethics`, `stat_points` 필드 없음
- 테이블명: `"robeing"`
#### 3. robeing-gateway 프록시
- **파일**: `/home/happybell/projects/ivada/robeing-gateway/app/main.py:304`
- **프록시 설정**: `target_url = f"http://192.168.219.52:9024/api/stats/{robeing_id}"`
- **라우팅**: Gateway → robeing-monitor(9024)
- **프록시**: `f"http://192.168.219.52:9024/api/stats/{robeing_id}"`
- **문제**: gateway는 `/api/stats/`로 프록시하지만 monitor는 `/stats/`로 서비스
### Stats API 호출자
#### 1. rb8001/app/router/router.py
- **80-82줄**: `_load_stats_from_state()` 함수 (현재 pass로 변경됨)
- **164줄**: 호출부 주석 처리됨
#### 2. rb8001/app/brain/brain_service.py
- **파일 크기**: 152줄
#### 1. rb8001/app/brain/brain_service.py
- **GET 호출**: 48줄 `f"{settings.STATE_SERVICE_URL}/api/stats/{robeing_id}"`
- **PUT 호출**: 110줄 `f"{settings.STATE_SERVICE_URL}/api/stats/{robeing_id}"`
- **변수**: `settings.STATE_SERVICE_URL`
- **에러 로깅**: 56줄 `Failed to fetch stats`
- **설정**: `settings.STATE_SERVICE_URL` (config.py:51, 기본값 None)
#### 3. rb8001/app/brain/state_client.py
- **파일 크기**: 168줄
#### 2. rb8001/app/brain/state_client.py
- **base_url**: `os.getenv('STATE_SERVICE_URL', 'http://localhost:8507')` (17줄)
- **robeing_id**: `settings.ROBEING_ID` (18줄)
- **GET 메서드**: `get_stats()` 25줄 `f"{self.base_url}/api/stats/{self.robeing_id}"`
- **PUT 메서드**: `update_stats()` 68줄 `f"{self.base_url}/api/stats/{self.robeing_id}"`
- **POST 메서드**: `create_stats()` 44줄 (엔드포인트 없음)
- **GET 메서드**: 25줄 `f"{self.base_url}/api/stats/{self.robeing_id}"`
- **PUT 메서드**: 68줄 `f"{self.base_url}/api/stats/{self.robeing_id}"`
- **싱글톤**: `state_client = StateServiceClient()` (168줄)
- **참고**: rb8001 내에서 state_client 직접 사용 흔적 없음
### 설정값
- **파일**: `/home/happybell/projects/ivada/rb8001/app/core/config.py`
- **STATE_SERVICE_URL**: 51줄 (기본값 `http://localhost:8507`)
- **ROBEING_ID**: settings에 정의
- **config.py:51**: `STATE_SERVICE_URL: Optional[str] = None`
- **state_client.py:17**: `os.getenv('STATE_SERVICE_URL', 'http://localhost:8507')`
### 관찰된 사실
1. rb8001이 자기 자신의 8507 포트로 stats API 호출
2. robeing-gateway는 9024(robeing-monitor)로 프록시
3. rb8001 내부 state_service.py와 robeing-monitor가 중복 구현
4. router.py의 stats 로드는 제거되었지만 brain_service.py는 여전히 호출
### 확인된 문제
1. robeing-monitor 경로: `/stats/{id}` vs gateway 프록시: `/api/stats/{id}` 불일치
2. DB 스키마 차이: rb8001은 `robeing_id`, monitor는 `robeing_container_id`
3. 필드 차이: rb8001은 `ethics`, `stat_points` 있음, monitor는 없음