diff --git a/k8s/02-configmap.yaml b/k8s/02-configmap.yaml index db95438..c052d7d 100644 --- a/k8s/02-configmap.yaml +++ b/k8s/02-configmap.yaml @@ -44,10 +44,9 @@ data: PASSWORD_REQUIRE_SPECIAL: "false" # Ollama AI 服務(ADR-027 三主機級聯:GCP-A → GCP-B → 111) - # 不再寫死 OLLAMA_HOST,改由 services/ollama_service.py:resolve_ollama_host() - # 動態解析。三主機 env 由 OLLAMA_HOST_PRIMARY/SECONDARY/FALLBACK 控制。 - OLLAMA_HOST_PRIMARY: "http://34.143.170.20:11434" - OLLAMA_HOST_SECONDARY: "http://34.21.145.224:11434" + # 已架設 Nginx Proxy (110:11435/11436) 轉發至 GCP,解決 K8s 內網無法直連 GCP 11434 的問題。 + OLLAMA_HOST_PRIMARY: "http://192.168.0.110:11435" + OLLAMA_HOST_SECONDARY: "http://192.168.0.110:11436" OLLAMA_HOST_FALLBACK: "http://192.168.0.111:11434" OLLAMA_MODEL: "qwen3:8b" diff --git a/services/code_review_pipeline_service.py b/services/code_review_pipeline_service.py index 5374c77..dbcfaa7 100644 --- a/services/code_review_pipeline_service.py +++ b/services/code_review_pipeline_service.py @@ -228,13 +228,11 @@ class CodeReviewPipeline: 只輸出 JSON 陣列,不含其他文字。無問題時輸出 []""" # ADR-027 Phase 2 N3:lazy resolve Hermes 主機(GCP 優先 / 111 備援), - # 避開 import-time freeze。provider 標籤跟著解析結果動態決定。 + # 避開 import-time freeze。Phase 53:改用 services.ollama_service.get_provider_tag + # 統一函式,支援 K8s Nginx Proxy(110:11435/11436)。 hermes_url = get_hermes_url() - provider_tag = ( - 'gcp_ollama' if ('34.21.145.224' in hermes_url or '34.143.170.20' in hermes_url) - else 'ollama_111' if '192.168.0.111' in hermes_url - else 'ollama_other' - ) + from services.ollama_service import get_provider_tag + provider_tag = get_provider_tag(hermes_url) # Phase 1 v5.0: 包 ai_call_logger 追蹤 Code Review Hermes scan with log_ai_call( caller='code_review_hermes', diff --git a/services/ollama_service.py b/services/ollama_service.py index c3f02c8..46a57a3 100644 --- a/services/ollama_service.py +++ b/services/ollama_service.py @@ -134,13 +134,24 @@ def resolve_ollama_host(primary: str = OLLAMA_HOST_PRIMARY, def get_host_label(host: str) -> str: - """將 IP/URL 轉換為易讀的主機標籤""" + """將 IP/URL 轉換為易讀的主機標籤 + + Phase 53:支援 K8s 環境的 Nginx Proxy(110:11435/11436 → GCP)。 + 判斷順序:直連 GCP IP > Nginx 轉發 port > 內網 IP > 本地。 + """ if not host: return "未知" + # 直連 GCP(docker-compose 環境) if "34.143.170.20" in host: return "GCP-SSD" if "34.21.145.224" in host: return "GCP-SSD-2" + # Nginx Proxy 轉發(K8s 環境,110 跳板代理 GCP) + if "192.168.0.110:11435" in host: + return "GCP-SSD(via Nginx 110)" + if "192.168.0.110:11436" in host: + return "GCP-SSD-2(via Nginx 110)" + # 內網 / 本地 if "192.168.0.111" in host: return "111 備援" if "192.168.0.188" in host or "localhost" in host: @@ -148,6 +159,24 @@ def get_host_label(host: str) -> str: return host.split('//')[-1].split(':')[0] +def get_provider_tag(host: str) -> str: + """將 host URL 轉換為 ai_calls.provider 標籤 + + Phase 53 新加:統一 provider 判斷邏輯,避免散落各 service 重寫。 + 對應 ai_calls.provider 白名單:gcp_ollama / ollama_secondary / ollama_111 / ollama_other + """ + if not host: + return 'ollama_other' + # GCP 直連或 Nginx 轉發都歸 gcp_ollama / ollama_secondary + if "34.143.170.20" in host or "192.168.0.110:11435" in host: + return 'gcp_ollama' + if "34.21.145.224" in host or "192.168.0.110:11436" in host: + return 'ollama_secondary' + if "192.168.0.111" in host: + return 'ollama_111' + return 'ollama_other' + + @dataclass class OllamaResponse: """Ollama 回應結構