forked from mtusi2026/mtusi2026lab6
Verify the grade 3 telemetry stack and inherited API guarantees
This commit is contained in:
@@ -66,7 +66,7 @@ def wait_for(what, check, timeout, interval=2.0):
|
||||
result = check()
|
||||
if result:
|
||||
return result
|
||||
except Failure:
|
||||
except (Failure, OSError):
|
||||
pass
|
||||
if time.monotonic() > deadline:
|
||||
raise Failure(f"timeout waiting for {what}")
|
||||
@@ -253,6 +253,10 @@ def request_check(args, b):
|
||||
if not trace_id:
|
||||
raise Failure("log record has no trace_id")
|
||||
spans = wait_for("API trace in Tempo", lambda: tempo_spans(b.trace(trace_id)[0]), args.timeout)
|
||||
if not any(s["kind"] == "SPAN_KIND_SERVER" and s["service"] == args.api_service for s in spans):
|
||||
raise Failure("no real API server span")
|
||||
if not any(s["kind"] == "SPAN_KIND_CLIENT" and s["attributes"].get("db.system") == "postgresql" for s in spans):
|
||||
raise Failure("no PostgreSQL client span inside API trace")
|
||||
print(json.dumps({"checked_at": now(), "request_id": rid, "log": {"line": line[:200], "trace_id": trace_id,
|
||||
"span_id": labels.get("span_id"),
|
||||
"service_name": labels.get("service_name"),
|
||||
@@ -282,6 +286,10 @@ def job_check(args, b):
|
||||
query = f'{{service_name="{args.worker_service}"}} | {args.log_attachment_key}="{attachment["id"]}"'
|
||||
worker_logs = wait_for("worker logs", lambda: b.logs(query, t0 - 30, time.time() + 30), args.timeout)
|
||||
api.logout(auth)
|
||||
if ready["status"] != "ready" or not any(s["kind"] == "SPAN_KIND_CONSUMER" and s["service"] == args.worker_service for s in chain):
|
||||
raise Failure("job is not ready or no real consumer span")
|
||||
if not any(labels.get("trace_id") and labels.get("span_id") for labels, _ in worker_logs):
|
||||
raise Failure("worker log is not correlated")
|
||||
print(json.dumps({"checked_at": now(), "upload_request_id": rid, "attachment_status": ready["status"],
|
||||
"traces": sorted({c["trace_id"] for c in chain}), "spans": chain,
|
||||
"worker_logs": [{"line": line[:200], "trace_id": labels.get("trace_id"), "span_id": labels.get("span_id")}
|
||||
|
||||
Reference in New Issue
Block a user