import json import os import subprocess import sys def emit(key: str, value) -> None: print(f"{key}: {json.dumps(value)}") def main() -> None: pod = subprocess.check_output( [ "kubectl", "-n", "cluster-agent-e2e", "get", "pods", "-l", "app=cluster-agent", "-o", "jsonpath={.items[0].metadata.name}", ], text=True, ).strip() audit_log = subprocess.check_output( [ "kubectl", "-n", "cluster-agent-e2e", "exec", pod, "--", "cat", "/tmp/audit.log", ], text=True, ).strip() healthz_entries = [] for line in audit_log.splitlines(): line = line.strip() if not line: continue try: entry = json.loads(line) except json.JSONDecodeError: continue uri = entry.get("request_uri", "") if "/healthz" in uri: healthz_entries.append(entry) emit("healthz_audit_count", len(healthz_entries)) if __name__ == "__main__": main()