feat: Implement latency profiling and guardrails for performance monitoring
CI / lint-test-build (push) Failing after 19s
CI / lint-test-build (push) Failing after 19s
- Added synthetic latency profiler scenarios and CLI scripts for baseline generation and regression checks. - Introduced latency baseline and threshold artifacts for CI enforcement. - Enhanced CI workflow with latency guardrail checks. - Updated documentation to include latency profiling commands and performance metrics. - Added unit tests for latency guardrail evaluation.
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from arbitrade.perf.guardrails import evaluate_guardrails
|
||||
from arbitrade.perf.latency import run_latency_profile
|
||||
|
||||
|
||||
def test_run_latency_profile_contains_expected_shape() -> None:
|
||||
profile = run_latency_profile(iterations=50)
|
||||
|
||||
scenarios = profile.get("scenarios")
|
||||
assert isinstance(scenarios, dict)
|
||||
assert set(scenarios) == {
|
||||
"book_update_burst",
|
||||
"execution_spike",
|
||||
"reconnect_storm",
|
||||
}
|
||||
|
||||
for payload in scenarios.values():
|
||||
assert isinstance(payload, dict)
|
||||
stages = payload.get("stages")
|
||||
assert isinstance(stages, dict)
|
||||
assert "end_to_end" in stages
|
||||
|
||||
|
||||
def test_evaluate_guardrails_flags_regression() -> None:
|
||||
baseline = {
|
||||
"scenarios": {
|
||||
"book_update_burst": {
|
||||
"stages": {
|
||||
"end_to_end": {"p95_ms": 1.0, "p99_ms": 1.0},
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
current = {
|
||||
"scenarios": {
|
||||
"book_update_burst": {
|
||||
"stages": {
|
||||
"end_to_end": {"p95_ms": 4.0, "p99_ms": 4.0},
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
thresholds = {"default": {"p95_ms": 2.0, "p99_ms": 2.0}}
|
||||
|
||||
failures = evaluate_guardrails(baseline=baseline, current=current, thresholds=thresholds)
|
||||
|
||||
assert failures
|
||||
assert "latency regression" in failures[0]
|
||||
@@ -11,7 +11,11 @@ def test_dashboard_auth_requires_both_fields() -> None:
|
||||
|
||||
def test_kraken_api_auth_requires_key_and_secret() -> None:
|
||||
with pytest.raises(ValidationError):
|
||||
Settings(_env_file=None, KRAKEN_API_KEY="key-only")
|
||||
Settings(
|
||||
_env_file=None,
|
||||
KRAKEN_API_KEY="key-only",
|
||||
KRAKEN_API_SECRET="",
|
||||
)
|
||||
|
||||
|
||||
def test_kraken_permissions_require_query_and_trade() -> None:
|
||||
|
||||
Reference in New Issue
Block a user