Skip to content

Run health alert checks concurrently#377

Open
silentgeckoaudit3801 wants to merge 3 commits into
Quantarq:mainfrom
silentgeckoaudit3801:perf/concurrent-alert-health-checks-206
Open

Run health alert checks concurrently#377
silentgeckoaudit3801 wants to merge 3 commits into
Quantarq:mainfrom
silentgeckoaudit3801:perf/concurrent-alert-health-checks-206

Conversation

@silentgeckoaudit3801

Copy link
Copy Markdown

Summary

  • fan out health-ratio alert checks with a bounded concurrency cap (default 16)
  • wrap each user check in a per-task timeout so one slow RPC does not stall the sweep
  • use asyncio.gather(..., return_exceptions=True) so failures do not stop successful alerts
  • record Prometheus success/failure counters and log a sweep summary
  • add static coverage for the alert sweep concurrency, timeout, gather, and metrics wiring

Validation

  • Static API validation confirmed semaphore, timeout, gather with return_exceptions=True, and success/failure counter wiring are present
  • Compare is 0 commits behind upstream main

Closes #206

def test_alert_sweep_uses_bounded_concurrency_and_timeout():
source = ALERT_SOURCE.read_text(encoding="utf-8")

assert "asyncio.Semaphore(ALERT_CONCURRENCY_LIMIT)" in source
source = ALERT_SOURCE.read_text(encoding="utf-8")

assert "asyncio.Semaphore(ALERT_CONCURRENCY_LIMIT)" in source
assert 'HEALTH_RATIO_ALERT_CONCURRENCY", "16"' in source

assert "asyncio.Semaphore(ALERT_CONCURRENCY_LIMIT)" in source
assert 'HEALTH_RATIO_ALERT_CONCURRENCY", "16"' in source
assert "asyncio.wait_for(" in source
assert "asyncio.Semaphore(ALERT_CONCURRENCY_LIMIT)" in source
assert 'HEALTH_RATIO_ALERT_CONCURRENCY", "16"' in source
assert "asyncio.wait_for(" in source
assert "timeout=ALERT_TASK_TIMEOUT_SECONDS" in source
assert 'HEALTH_RATIO_ALERT_CONCURRENCY", "16"' in source
assert "asyncio.wait_for(" in source
assert "timeout=ALERT_TASK_TIMEOUT_SECONDS" in source
assert "asyncio.gather(*tasks, return_exceptions=True)" in source
def test_alert_sweep_records_success_and_failure_metrics():
source = ALERT_SOURCE.read_text(encoding="utf-8")

assert "health_ratio_alert_sweep_results_total" in source
source = ALERT_SOURCE.read_text(encoding="utf-8")

assert "health_ratio_alert_sweep_results_total" in source
assert "ALERT_SWEEP_COUNTER.labels(outcome=\"success\").inc(success_count)" in source

assert "health_ratio_alert_sweep_results_total" in source
assert "ALERT_SWEEP_COUNTER.labels(outcome=\"success\").inc(success_count)" in source
assert "ALERT_SWEEP_COUNTER.labels(outcome=\"failure\").inc(failure_count)" in source
assert "health_ratio_alert_sweep_results_total" in source
assert "ALERT_SWEEP_COUNTER.labels(outcome=\"success\").inc(success_count)" in source
assert "ALERT_SWEEP_COUNTER.labels(outcome=\"failure\").inc(failure_count)" in source
assert "health_ratio_alert_sweep_summary" in source No newline at end of file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Eliminate N+1 in get_users_for_notifications

2 participants