#!/usr/bin/env python3 """Проверяет работу бизнес-контура при временной недоступности Loki и Tempo.""" import argparse import json import os import subprocess import time from client import Client ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) def compose(*args: str, capture: bool = False): """Запускает Docker Compose из корня проекта и при необходимости захватывает вывод.""" return subprocess.run( ["docker", "compose", *args], cwd=ROOT, check=True, text=True, capture_output=capture, ) def main(): """Отключает telemetry backends, запускает smoke и гарантированно восстанавливает их.""" parser = argparse.ArgumentParser() parser.add_argument("--base-url", default="http://localhost:8080") args = parser.parse_args() compose("stop", "loki", "tempo") started = time.monotonic() try: result = subprocess.run( ["python3", "tests/smoke.py", "--base-url", args.base_url], cwd=ROOT, check=True, text=True, capture_output=True, ) time.sleep(10) Client(args.base_url).call("GET", "/health/ready", schema="Health") running = compose("ps", "--status", "running", "--services", capture=True).stdout.split() if "otel-collector" not in running: raise RuntimeError("OTel Collector stopped while exporters were retrying") finally: compose("start", "loki", "tempo") print(json.dumps({ "scenario": "telemetry_backend_outage", "business_smoke": "PASS" if "PASS:" in result.stdout else "UNKNOWN", "collector": "running", "duration_seconds": round(time.monotonic() - started, 1), "result": "PASS", })) if __name__ == "__main__": main()