Files
mtusi2026lab7/student-tests/history_snapshot.py
T
mayorovasonya 7353ab97a6
Application / application (pull_request) Canceled after 0s
Skeleton contracts / contracts (pull_request) Canceled after 0s
Лаб7: mTLS, Argon2id, OpenBao и исследование отзыва worker
Майорова Софья, БВТ2301, на 5. Трек1. HTTPS/TLS/ACL,18 API tests,13 pipeline groups,3 compromise runs,clean clone,persistence. Original tests/API contract preserved; residual CVE triage in REPORT/security.
2026-11-20 14:48:26 +03:00

20 lines
1.1 KiB
Python

"""Read only historical telemetry via the operator identity and verified TLS."""
import json
import sys
from urllib.parse import urlencode
from security_helpers import http
traceid=sys.argv[1];at=sys.argv[2]
_,raw=http('https://tempo:8443/api/traces/'+traceid)
trace=json.loads(raw)
ids=[]
for batch in trace.get('batches',trace.get('resourceSpans',[])):
for scope in batch.get('scopeSpans',[]):ids.extend(x['spanId'] for x in scope['spans'])
assert ids
query='{service_name=~"messenger-.*"} | json | trace_id="'+traceid+'"'
_,raw=http('https://loki:8443/loki/api/v1/query_range?'+urlencode({'query':query,'start':str(int((float(at)-3600)*1e9)),'end':str(int((float(at)+300)*1e9)),'limit':'100'}))
records=[line for stream in json.loads(raw)['data']['result'] for stamp,line in stream['values']]
assert records
_,raw=http('https://prometheus:8443/api/v1/query?'+urlencode({'query':'sum(http_server_requests_total)','time':at}))
metric=json.loads(raw)['data']['result'];assert metric
print(json.dumps({'trace_spans':sorted(ids),'logs':sorted(records),'fixed_time_metric':metric},sort_keys=True))