docs: finish lab 6 report and reproducible evidence
This commit is contained in:
@@ -31,7 +31,7 @@ def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--base-url", default="http://127.0.0.1:8080")
|
||||
parser.add_argument("--grafana-url", default="http://127.0.0.1:3000")
|
||||
parser.add_argument("criterion", choices=["provisioning", "signals", "pipeline"])
|
||||
parser.add_argument("criterion", choices=["provisioning", "signals", "pipeline", "dashboard"])
|
||||
args = parser.parse_args()
|
||||
|
||||
def query(path, **params):
|
||||
@@ -51,6 +51,24 @@ def main():
|
||||
print("Загружен dashboard messenger-lab6, панелей:", len(dashboard["panels"]))
|
||||
return
|
||||
|
||||
if args.criterion == "dashboard":
|
||||
dashboard = query("/api/dashboards/uid/messenger-lab6")["dashboard"]
|
||||
check(len(dashboard["panels"]) >= 17, "grade 4 dashboard panels missing")
|
||||
for panel in dashboard["panels"]:
|
||||
if panel["datasource"]["type"] != "prometheus":
|
||||
continue
|
||||
for target in panel["targets"]:
|
||||
result = source("prometheus", "/api/v1/query", query=target["expr"])
|
||||
check(result["status"] == "success", "PromQL query failed")
|
||||
print(panel["title"], "—", target["expr"], "— рядов:", len(result["data"]["result"]))
|
||||
expression = ('1 - (sum(increase(messenger_http_requests_total{http_status_class="5xx"}[30m])) '
|
||||
'or 0 * sum(increase(messenger_http_requests_total[30m]))) '
|
||||
'/ sum(increase(messenger_http_requests_total[30m]))')
|
||||
result = source("prometheus", "/api/v1/query", query=expression)["data"]["result"]
|
||||
check(bool(result), "SLI series missing")
|
||||
print("SLI за 30 минут:", result[0]["value"][1], "цель: >= 0.99")
|
||||
return
|
||||
|
||||
client = Client(args.base_url)
|
||||
start = time.time_ns()
|
||||
alice, bob, _, chat = client.bootstrap()
|
||||
@@ -67,19 +85,23 @@ def main():
|
||||
start=start, end=time.time_ns())["data"]["result"]
|
||||
if logs:
|
||||
trace_id = logs[0]["stream"]["trace_id"]
|
||||
trace = source("tempo", "/api/traces/" + trace_id)
|
||||
try:
|
||||
trace = source("tempo", "/api/traces/" + trace_id)
|
||||
except urllib.error.HTTPError as error:
|
||||
if error.code != 404:
|
||||
raise
|
||||
time.sleep(2)
|
||||
continue
|
||||
spans = [span for batch in trace["batches"] for scope in batch["scopeSpans"] for span in scope["spans"]]
|
||||
producer = next((span for span in spans if span["kind"] == "SPAN_KIND_PRODUCER"), None)
|
||||
consumer = next((span for span in spans if span["kind"] == "SPAN_KIND_CONSUMER"), None)
|
||||
if producer and consumer:
|
||||
api = next(span for span in spans if span["kind"] == "SPAN_KIND_SERVER")
|
||||
check(producer["parentSpanId"] == api["spanId"], "producer parent mismatch")
|
||||
check(consumer["parentSpanId"] == producer["spanId"], "consumer parent mismatch")
|
||||
by_id = {span["spanId"]: span for span in spans}
|
||||
for consumer in (span for span in spans if span["kind"] == "SPAN_KIND_CONSUMER"):
|
||||
producer = by_id.get(consumer.get("parentSpanId"), {})
|
||||
api = by_id.get(producer.get("parentSpanId"), {})
|
||||
children = {span["name"] for span in spans if span.get("parentSpanId") == consumer["spanId"]}
|
||||
check({"postgresql finalize attachment", "s3 read staging and write variants"} <= children,
|
||||
"worker S3 and PostgreSQL spans missing")
|
||||
print("Upload → producer → consumer → S3/PostgreSQL, trace:", trace_id)
|
||||
return
|
||||
if (producer.get("kind") == "SPAN_KIND_PRODUCER" and api.get("kind") == "SPAN_KIND_SERVER"
|
||||
and {"postgresql finalize attachment", "s3 read staging and write variants"} <= children):
|
||||
print("Upload → producer → consumer → S3/PostgreSQL, trace:", trace_id)
|
||||
return
|
||||
time.sleep(2)
|
||||
raise Failure("upload trace did not include the worker pipeline")
|
||||
|
||||
@@ -132,7 +154,9 @@ def main():
|
||||
spans = [span for batch in trace["batches"] for scope in batch["scopeSpans"] for span in scope["spans"]]
|
||||
span_id_base64 = base64.b64encode(bytes.fromhex(span_id)).decode()
|
||||
matched = [span for span in spans if span["spanId"] in (span_id, span_id_base64)]
|
||||
check(len(matched) == 1, "span ID from log missing in trace")
|
||||
if not matched:
|
||||
continue
|
||||
check(len(matched) == 1, "duplicate span ID in trace")
|
||||
span = matched[0]
|
||||
check(span["kind"] in (span_kind, "SPAN_KIND_SERVER" if span_kind == 2 else "SPAN_KIND_CONSUMER"), "wrong span kind")
|
||||
check(int(span["endTimeUnixNano"]) > int(span["startTimeUnixNano"]), "span duration missing")
|
||||
|
||||
Reference in New Issue
Block a user