This commit is contained in:
@@ -19,7 +19,7 @@ SAFE_TOKEN_METADATA_KEYS = {
|
||||
SAFE_APPROVAL_ENV_VAR = "MARKET_INTEL_QUEUE_WRITE_APPROVAL"
|
||||
TARGET_TABLE = "market_alert_review_queue"
|
||||
OLLAMA_CASCADE = (
|
||||
{"key": "gcp_a", "label": "GCP-A", "host": "34.143.170.20:11434"},
|
||||
{"key": "gcp_a", "label": "GCP-A", "host": "34.87.90.216:11434"},
|
||||
{"key": "gcp_b", "label": "GCP-B", "host": "34.21.145.224:11434"},
|
||||
{"key": "lan_111", "label": "111", "host": "192.168.0.111:11434"},
|
||||
)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
"""Lightweight Ollama runtime health probes shared by scheduler and UI."""
|
||||
|
||||
import os
|
||||
from typing import Optional, Tuple
|
||||
|
||||
|
||||
def _env_flag(name: str, default: bool = False) -> bool:
|
||||
@@ -19,7 +20,7 @@ def host_health_model_probe_enabled(label: str) -> bool:
|
||||
return True
|
||||
|
||||
|
||||
def probe_ollama_embedding_runtime(requests_module, host: str) -> tuple[bool, str | None]:
|
||||
def probe_ollama_embedding_runtime(requests_module, host: str) -> Tuple[bool, Optional[str]]:
|
||||
"""Verify Ollama can serve a tiny embedding, not just answer /api/tags."""
|
||||
model = os.getenv("OLLAMA_HOST_HEALTH_EMBED_MODEL", "bge-m3:latest")
|
||||
timeout = float(os.getenv("OLLAMA_HOST_HEALTH_EMBED_TIMEOUT", "30"))
|
||||
|
||||
@@ -17,7 +17,7 @@ from dataclasses import dataclass
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
APPROVED_OLLAMA_HOST_SUBSTRINGS = (
|
||||
'34.143.170.20:11434', # GCP-A / Primary
|
||||
'34.87.90.216:11434', # GCP-A / Primary
|
||||
'34.21.145.224:11434', # GCP-B / Secondary
|
||||
'192.168.0.111:11434', # 111 / final fallback
|
||||
'192.168.0.110:11435', # 110 proxy to GCP-A
|
||||
@@ -48,7 +48,7 @@ def approved_ollama_env(name: str, default: str = '') -> str:
|
||||
|
||||
|
||||
# Ollama 設定 - 僅允許 GCP-A → GCP-B → 111 三主機
|
||||
OLLAMA_HOST_PRIMARY = approved_ollama_env('OLLAMA_HOST_PRIMARY', 'http://34.143.170.20:11434')
|
||||
OLLAMA_HOST_PRIMARY = approved_ollama_env('OLLAMA_HOST_PRIMARY', 'http://34.87.90.216:11434')
|
||||
OLLAMA_HOST_SECONDARY = approved_ollama_env('OLLAMA_HOST_SECONDARY', 'http://34.21.145.224:11434')
|
||||
OLLAMA_HOST_FALLBACK = approved_ollama_env('OLLAMA_HOST_FALLBACK', 'http://192.168.0.111:11434')
|
||||
OLLAMA_HOST_PRIMARY_PROXY = approved_ollama_env('OLLAMA_HOST_PRIMARY_PROXY', 'http://192.168.0.110:11435')
|
||||
@@ -204,7 +204,10 @@ def _host_label_for_embedding_health(host: str) -> str:
|
||||
"""Map an Ollama host URL to the host_health_probes label used by scheduler."""
|
||||
if not host:
|
||||
return ''
|
||||
if '34.143.170.20:11434' in host or '192.168.0.110:11435' in host:
|
||||
if (
|
||||
'34.87.90.216:11434' in host
|
||||
or '192.168.0.110:11435' in host
|
||||
):
|
||||
return 'Primary (GCP)'
|
||||
if '34.21.145.224:11434' in host or '192.168.0.110:11436' in host:
|
||||
return 'Secondary (GCP)'
|
||||
@@ -215,7 +218,7 @@ def _host_label_for_direct_health(host: str) -> str:
|
||||
"""Map only direct GCP Ollama URLs to host_health_probes labels."""
|
||||
if not host:
|
||||
return ''
|
||||
if '34.143.170.20:11434' in host:
|
||||
if '34.87.90.216:11434' in host:
|
||||
return 'Primary (GCP)'
|
||||
if '34.21.145.224:11434' in host:
|
||||
return 'Secondary (GCP)'
|
||||
@@ -252,10 +255,11 @@ def _recent_direct_host_unhealthy(host: str) -> bool:
|
||||
SELECT healthy, error_msg, probed_at
|
||||
FROM host_health_probes
|
||||
WHERE host_label = :host_label
|
||||
AND host_url = :host_url
|
||||
ORDER BY probed_at DESC
|
||||
LIMIT 1
|
||||
"""),
|
||||
{'host_label': host_label},
|
||||
{'host_label': host_label, 'host_url': _normalize_host(host)},
|
||||
).fetchone()
|
||||
finally:
|
||||
session.close()
|
||||
@@ -320,10 +324,11 @@ def _recent_embedding_host_unhealthy(host: str) -> bool:
|
||||
SELECT healthy, error_msg, probed_at
|
||||
FROM host_health_probes
|
||||
WHERE host_label = :host_label
|
||||
AND host_url = :host_url
|
||||
ORDER BY probed_at DESC
|
||||
LIMIT 1
|
||||
"""),
|
||||
{'host_label': host_label},
|
||||
{'host_label': host_label, 'host_url': _normalize_host(host)},
|
||||
).fetchone()
|
||||
finally:
|
||||
session.close()
|
||||
@@ -625,7 +630,7 @@ def get_host_label(host: str) -> str:
|
||||
if not host:
|
||||
return "未知"
|
||||
# 直連 GCP(docker-compose 環境)
|
||||
if "34.143.170.20" in host:
|
||||
if "34.87.90.216" in host:
|
||||
return "GCP-SSD"
|
||||
if "34.21.145.224" in host:
|
||||
return "GCP-SSD-2"
|
||||
@@ -651,7 +656,7 @@ def get_provider_tag(host: str) -> str:
|
||||
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:
|
||||
if "34.87.90.216" 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'
|
||||
|
||||
Reference in New Issue
Block a user