runpod: try multiple log routes (the tail= param returned HTTP 400)

Live run showed get_pod_logs hitting HTTP 400 on {rest}/pods/{id}/logs?tail=N, so a
failed boot fell back to the console link with no output. Now tries the plausible
routes in order (no params, ?limit=, containerLogs) and keeps the first that
answers, reporting the collected errors otherwise. The console deep-link remains
the always-available path.
Co-Authored-By: 's avatarClaude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01R6iugoNeEgt9PkajKrFyq4
parent 0c8417fa
...@@ -283,10 +283,21 @@ class RunpodClient: ...@@ -283,10 +283,21 @@ class RunpodClient:
import requests import requests
out = {"console_url": pod_console_url(pod_id)} out = {"console_url": pod_console_url(pod_id)}
rest = (getattr(self._cfg, "rest_base", "") or "https://rest.runpod.io/v1").rstrip("/") rest = (getattr(self._cfg, "rest_base", "") or "https://rest.runpod.io/v1").rstrip("/")
try: hdrs = {"Authorization": f"Bearer {self._api_key}"}
r = requests.get(f"{rest}/pods/{pod_id}/logs", # RunPod's log surface has moved around; try the plausible routes in order and
headers={"Authorization": f"Bearer {self._api_key}"}, # keep the first that answers. The console link is the always-available path.
params={"tail": tail}, timeout=15) attempts = [
(f"{rest}/pods/{pod_id}/logs", None),
(f"{rest}/pods/{pod_id}/logs", {"limit": tail}),
(f"{rest}/pods/{pod_id}/containerLogs", None),
]
errors = []
for url, params in attempts:
try:
r = requests.get(url, headers=hdrs, params=params, timeout=15)
except requests.RequestException as exc:
errors.append(f"{url.rsplit('/', 1)[-1]}: unreachable ({exc})")
continue
if r.status_code == 200: if r.status_code == 200:
try: try:
body = r.json() body = r.json()
...@@ -294,10 +305,10 @@ class RunpodClient: ...@@ -294,10 +305,10 @@ class RunpodClient:
(body.get("logs") or body.get("data") or str(body)) (body.get("logs") or body.get("data") or str(body))
except ValueError: except ValueError:
out["logs"] = r.text out["logs"] = r.text
else: return out
out["error"] = f"logs API HTTP {r.status_code} — use the console link" errors.append(f"HTTP {r.status_code}")
except requests.RequestException as exc: out["error"] = ("logs API unavailable (" + "; ".join(errors[:3])
out["error"] = f"logs API unreachable ({exc}) — use the console link" + ") — use the console link")
return out return out
def wait_ready(self, pod_id: str, port: int, ready_timeout: float = 900.0, def wait_ready(self, pod_id: str, port: int, ready_timeout: float = 900.0,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment