refactor code

This commit is contained in:
Матвей
2026-11-06 11:12:38 +03:00
parent c885462c04
commit 7fe48e38c1
50 changed files with 5674 additions and 564 deletions
+11 -9
View File
@@ -2,7 +2,7 @@
"""Run two bounded DB-lock incidents against the local Compose project.
Creates synthetic data, records only aggregate counts/alert states, and releases
all locks on exit. Run on the isolated lab6 stack, never a shared database.
bounded locks; interrupted server-side sleeps may persist until their deadline. Run on the isolated lab6 stack, never a shared database.
"""
import base64
from concurrent.futures import ThreadPoolExecutor
@@ -43,7 +43,7 @@ def monitor():
try:
alerts = get('alerts')['alerts']
firing = sorted(a['labels']['alertname'] for a in alerts if a['state'] == 'firing' and 'Burn' in a['labels']['alertname'])
with LOCK: sample = {'time': utc(), 'monotonic': time.monotonic(), 'phase': SCENARIO['phase'], 'counts': dict(COUNTS), 'firing': firing}
with LOCK: sample = {'time': utc(), 'monotonic': time.monotonic(), 'phase': SCENARIO['phase'], 'counts': dict(COUNTS), 'firing': firing, 'all_firing': sorted(a['labels']['alertname'] for a in alerts if a['state'] == 'firing')}
SAMPLES.append(sample)
except Exception as error:
SAMPLES.append({'time': utc(), 'monotonic': time.monotonic(), 'phase': SCENARIO['phase'], 'monitor_error': type(error).__name__})
@@ -103,13 +103,15 @@ def main():
try:
with ThreadPoolExecutor(max_workers=3) as pool:
futures = [pool.submit(worker, actor, chat) for _ in range(3)]
phase('baseline'); time.sleep(60)
result['periods']['burst'] = incident('burst', 75)
time.sleep(100)
result['periods']['sustained'] = incident('sustained', 180)
time.sleep(100)
phase('complete')
STOP.set()
try:
phase('baseline'); time.sleep(60)
result['periods']['burst'] = incident('burst', 75)
time.sleep(100)
result['periods']['sustained'] = incident('sustained', 180)
time.sleep(100)
phase('complete')
finally:
STOP.set()
for future in futures: future.result(timeout=15)
finally:
STOP.set(); monitor_thread.join(timeout=10)