diff --git a/troubleshooting/250915_happybell80_rb8001_stats_api_중복_제거.md b/troubleshooting/250915_happybell80_rb8001_stats_api_중복_제거.md new file mode 100644 index 0000000..8ef7776 --- /dev/null +++ b/troubleshooting/250915_happybell80_rb8001_stats_api_중복_제거.md @@ -0,0 +1,66 @@ +# rb8001 Stats API 중복 구현 및 Failed to load stats 에러 + +## 작성일: 2025-09-15 +## 작성자: happybell80 +## 상태: 조사 완료 + +--- + +## 현재 상황 + +### 에러 메시지 +- **발생 위치**: rb8001 컨테이너 시작 시 +- **에러**: `Failed to load stats: All connection attempts failed` +- **파일**: `/home/happybell/projects/ivada/rb8001/app/router/router.py:92` + +### Stats API 엔드포인트 현황 + +#### 1. rb8001 내부 구현 (포트 8507) +- **파일**: `/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"` + +#### 2. robeing-monitor 구현 (포트 9024) +- **서버**: 51124 +- **서비스**: robeing-monitor +- **포트**: 9024 +- **용도**: Stats 관리 담당 + +#### 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) + +### Stats API 호출자 + +#### 1. rb8001/app/router/router.py +- **80-82줄**: `_load_stats_from_state()` 함수 (현재 pass로 변경됨) +- **164줄**: 호출부 주석 처리됨 + +#### 2. rb8001/app/brain/brain_service.py +- **파일 크기**: 152줄 +- **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` + +#### 3. rb8001/app/brain/state_client.py +- **파일 크기**: 168줄 +- **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줄 (엔드포인트 없음) +- **싱글톤**: `state_client = StateServiceClient()` (168줄) + +### 설정값 +- **파일**: `/home/happybell/projects/ivada/rb8001/app/core/config.py` +- **STATE_SERVICE_URL**: 51줄 (기본값 `http://localhost:8507`) +- **ROBEING_ID**: settings에 정의 + +### 관찰된 사실 +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는 여전히 호출 \ No newline at end of file