Skip to content

Commit 260ad26

Browse files
vitkyrkaclaude
andcommitted
velero: surface malformed collector JSON and agent pod logs on failure
replay_collector_output called json.loads unguarded, so a malformed collector blob surfaced as a bare JSONDecodeError with no indication of which candidate produced it. run_discovery_check_kubernetes's failure path also only showed the agent check invocation's own stdout/stderr, not the agent pod's own logs, which is often where the real failure (a crashed IPC/auth setup) shows up. Mirror dd_agent_check's handling of both cases. Environment: Datadog workspace Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
1 parent 76ad601 commit 260ad26

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

datadog_checks_dev/datadog_checks/dev/kube_discovery.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,10 @@ def run_discovery_check_kubernetes(
157157

158158
result = exec_agent_pod(state['kubeconfig_path'], state['namespace'], command, capture=True, check=False)
159159
if not replay_collector_output(result.stdout, aggregator, datadog_agent):
160-
raise ValueError(f'Could not find valid check output:\n{result.stdout}\n{result.stderr}')
160+
agent_logs = get_pod_logs(state['kubeconfig_path'], state['namespace'], AGENT_POD_NAME)
161+
raise ValueError(
162+
f'Could not find valid check output:\n{result.stdout}\n{result.stderr}\n\nAgent pod logs:\n{agent_logs}'
163+
)
161164

162165
return aggregator
163166

@@ -228,7 +231,10 @@ def replay_collector_output(output: str, aggregator: Any, datadog_agent: Any) ->
228231
"""Replay collector JSON blobs from ``agent check --json`` output."""
229232
matches = find_collector_blobs(output)
230233
for raw_json in matches:
231-
collector = json.loads(raw_json)
234+
try:
235+
collector = json.loads(raw_json)
236+
except Exception as e:
237+
raise Exception(f'Error loading json: {e}\nCollector Json Output:\n{raw_json}')
232238
replay_check_run(collector, aggregator, datadog_agent)
233239

234240
return len(matches)

0 commit comments

Comments
 (0)