forked from mtusi2026/mtusi2026lab7
ЛР 7: Безопасность, mTLS и OpenBao
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Validate the Lab6 observability endpoints and provisioning."""
|
||||
import json
|
||||
import ssl
|
||||
import time
|
||||
import urllib.request
|
||||
from pathlib import Path
|
||||
|
||||
from client import Client, arguments, check, run
|
||||
|
||||
|
||||
def http_json(url, timeout=10):
|
||||
with urllib.request.urlopen(url, timeout=timeout) as response:
|
||||
return response.status, response.headers, response.read()
|
||||
|
||||
|
||||
def main():
|
||||
args = arguments("Validate OTel backends and Grafana provisioning")
|
||||
client = Client(args.base_url, args.ca_file)
|
||||
client.bootstrap()
|
||||
internal_ca = Path(args.ca_file).resolve().parent / "internal-ca.crt"
|
||||
context = ssl.create_default_context(cafile=str(internal_ca))
|
||||
def https_json(url):
|
||||
with urllib.request.urlopen(url, context=context, timeout=10) as response:
|
||||
return response.status, response.headers, response.read()
|
||||
|
||||
status, _, _ = http_json("http://127.0.0.1:3000/api/health")
|
||||
check(status == 200, "Grafana health endpoint is unavailable")
|
||||
status, _, raw = http_json("http://127.0.0.1:3000/api/datasources")
|
||||
check(status == 200, "Grafana datasource API is unavailable")
|
||||
datasources = {item["name"]: item["uid"] for item in json.loads(raw)}
|
||||
check(set(("Prometheus", "Loki", "Tempo")).issubset(datasources),
|
||||
"Grafana is missing required datasources")
|
||||
|
||||
status, _, _ = https_json("https://127.0.0.1:9090/-/ready")
|
||||
check(status == 200, "Prometheus is not ready")
|
||||
status, _, _ = https_json("https://127.0.0.1:3100/loki/api/v1/status/buildinfo")
|
||||
check(status == 200, "Loki API is not ready")
|
||||
status, _, _ = https_json("https://127.0.0.1:3200/status")
|
||||
check(status == 200, "Tempo search API is not ready")
|
||||
|
||||
deadline = time.monotonic() + 30
|
||||
while time.monotonic() < deadline:
|
||||
status, _, raw = https_json(
|
||||
"https://127.0.0.1:9464/metrics"
|
||||
)
|
||||
text = raw.decode("utf-8", "replace")
|
||||
if status == 200 and "messenger_http_requests" in text:
|
||||
break
|
||||
time.sleep(1)
|
||||
else:
|
||||
raise AssertionError("collector did not expose messenger HTTP metrics")
|
||||
|
||||
status, _, raw = http_json(
|
||||
"http://127.0.0.1:3000/api/dashboards/uid/messenger-lab6"
|
||||
)
|
||||
check(status == 200, "Lab6 dashboard was not provisioned")
|
||||
dashboard = json.loads(raw)["dashboard"]
|
||||
check(dashboard["title"] == "Messenger Observability",
|
||||
"unexpected Grafana dashboard title")
|
||||
|
||||
print("PASS: Grafana datasources/dashboard and Prometheus/Loki/Tempo backends are ready")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
run(main)
|
||||
Reference in New Issue
Block a user