45 lines
1.2 KiB
Python
45 lines
1.2 KiB
Python
#!/usr/bin/env python3
|
|
"""Concurrent health probes detect starvation without retrying readiness failures."""
|
|
|
|
import collections
|
|
import concurrent.futures
|
|
import json
|
|
import ssl
|
|
import urllib.error
|
|
import urllib.request
|
|
from pathlib import Path
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
|
|
|
|
def main():
|
|
context = ssl.create_default_context(cafile=str(ROOT / "secrets/ca.pem"))
|
|
|
|
def one(_):
|
|
try:
|
|
with urllib.request.urlopen(
|
|
"https://localhost:8447/health/ready", context=context, timeout=8
|
|
) as response:
|
|
return str(response.status)
|
|
except urllib.error.HTTPError as exc:
|
|
return str(exc.code)
|
|
except OSError:
|
|
return "connection_error"
|
|
|
|
with concurrent.futures.ThreadPoolExecutor(max_workers=8) as pool:
|
|
counts = dict(collections.Counter(pool.map(one, range(64))))
|
|
result = {
|
|
"concurrency": 8,
|
|
"requests": 64,
|
|
"status_counts": counts,
|
|
"passed": counts == {"200": 64},
|
|
}
|
|
(ROOT / "evidence/readiness-concurrency.json").write_text(json.dumps(result, indent=2) + "\n")
|
|
print(json.dumps(result))
|
|
if not result["passed"]:
|
|
raise SystemExit(1)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|