Implement lab6 observability with OpenTelemetry and Grafana

This commit is contained in:
2026-11-19 16:36:40 +03:00
parent 470d9d6f1e
commit 8c253a0e5a
149 changed files with 11752 additions and 229 deletions
+46
View File
@@ -0,0 +1,46 @@
"""Исходный persistence-сценарий плюс доказательство рестарта API и всех хранилищ."""
import argparse
import json
from pathlib import Path
import subprocess
import sys
ROOT = Path(__file__).resolve().parents[1]
def states():
result = {}
for service in ('api', 'postgres', 'redis', 'minio', 'broker', 'worker', 'dispatcher', 'reconciler', 'lb'):
ids = subprocess.check_output(['docker', 'compose', 'ps', '-q', service], cwd=ROOT, text=True).split()
if not ids:
raise RuntimeError('Не запущен сервис ' + service)
result[service] = {}
for container in ids:
state = json.loads(subprocess.check_output(['docker', 'inspect', '--format', '{{json .State}}', container], cwd=ROOT, text=True))
result[service][container] = {'StartedAt': state['StartedAt'], 'Pid': state['Pid']}
return result
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('--base-url', default='http://localhost:8080')
parser.add_argument('--action-script', required=True)
parser.add_argument('--ca-file')
args = parser.parse_args()
before = states()
print('ДО: ' + json.dumps(before), flush=True)
command = [sys.executable, str(ROOT / 'tests/resilience.py'), '--mode', 'persistence',
'--action-script', args.action_script, '--base-url', args.base_url]
if args.ca_file:
command += ['--ca-file', args.ca_file]
subprocess.run(command, cwd=ROOT, check=True)
after = states()
print('ПОСЛЕ: ' + json.dumps(after), flush=True)
for service in before:
if before[service] == after[service]:
raise AssertionError('Сервис не перезапущен: ' + service)
print('PASS: StartedAt изменился у API, PostgreSQL, Redis, MinIO, broker, worker, dispatcher, reconciler и LB; прежний токен и данные сохранены')
if __name__ == '__main__':
main()