Skip to content

Commit cad4cd4

Browse files
refactor: drop changepoint legacy fallback paths
1 parent 3db7072 commit cad4cd4

4 files changed

Lines changed: 22 additions & 27 deletions

File tree

api/routes/metrics.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,12 @@ async def metric_changepoints(req: ChangepointRequest) -> list[ChangePoint]:
5555
results: list[ChangePoint] = []
5656
for metric_name, ts, vals in anomaly.iter_series(raw, query_hint=req.query):
5757
threshold_sigma = float(req.threshold_sigma)
58-
try:
59-
results.extend(
60-
changepoint_detect(
61-
ts,
62-
vals,
63-
threshold_sigma=threshold_sigma,
64-
metric_name=metric_name,
65-
)
58+
results.extend(
59+
changepoint_detect(
60+
ts,
61+
vals,
62+
threshold_sigma=threshold_sigma,
63+
metric_name=metric_name,
6664
)
67-
except TypeError:
68-
results.extend(changepoint_detect(ts, vals, threshold_sigma))
65+
)
6966
return sorted(results, key=lambda c: c.timestamp)

engine/analyze/helpers.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -530,16 +530,12 @@ async def _process_one_metric_series(
530530
else float(settings.cusum_threshold_sigma)
531531
)
532532
sigma_multiplier = max(1.0, sigma_multiplier)
533-
try:
534-
change_points = changepoint_detect(
535-
job.ts,
536-
job.vals,
537-
threshold_sigma=sigma_multiplier,
538-
metric_name=metric_name,
539-
)
540-
except TypeError:
541-
# Backward-compatible path for monkeypatched/legacy detector signatures.
542-
change_points = changepoint_detect(job.ts, job.vals, sigma_multiplier)
533+
change_points = changepoint_detect(
534+
job.ts,
535+
job.vals,
536+
threshold_sigma=sigma_multiplier,
537+
metric_name=metric_name,
538+
)
543539

544540
threshold = next((v for k, v in FORECAST_THRESHOLDS.items() if k in job.query_string), None)
545541
if threshold and job.analysis_window_seconds >= float(

tests/test_analyze_helpers_filters_edges.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -295,10 +295,11 @@ async def _raise_compute(*_args, **_kwargs):
295295
monkeypatch.setattr(helpers, "baseline_compute", lambda *_a, **_k: called.__setitem__("baseline_fallback", 1))
296296
monkeypatch.setattr(helpers.anomaly, "detect", lambda *_a, **_k: [_anomaly("m", 1.0, 1.0)])
297297

298-
def _legacy_cp(ts, vals, sigma):
299-
return [_cp("m", 1.0, sigma)]
298+
def _cp_detector(ts, vals, threshold_sigma=None, metric_name=None):
299+
assert metric_name == "m"
300+
return [_cp("m", 1.0, float(threshold_sigma or 0.0))]
300301

301-
monkeypatch.setattr(helpers, "changepoint_detect", _legacy_cp)
302+
monkeypatch.setattr(helpers, "changepoint_detect", _cp_detector)
302303
monkeypatch.setattr(helpers.settings, "cusum_threshold_sigma", 2.0)
303304
monkeypatch.setattr(helpers.settings, "analyzer_forecast_min_window_seconds", 10.0)
304305
monkeypatch.setattr(helpers.settings, "analyzer_degradation_min_window_seconds", 10.0)

tests/test_api_route_surface_edges.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,7 @@ async def fake_safe_call(awaitable):
249249
captured = []
250250

251251
def fake_changepoint_detect(ts, vals, threshold_sigma=None, metric_name=None):
252-
if metric_name is not None:
253-
raise TypeError("legacy signature")
254-
captured.append((tuple(ts), tuple(vals), threshold_sigma))
252+
captured.append((tuple(ts), tuple(vals), threshold_sigma, metric_name))
255253
return [types.SimpleNamespace(timestamp=2)]
256254

257255
monkeypatch.setattr(metrics_route, "changepoint_detect", fake_changepoint_detect)
@@ -260,7 +258,10 @@ def fake_changepoint_detect(ts, vals, threshold_sigma=None, metric_name=None):
260258
)
261259

262260
assert [item.timestamp for item in changepoints] == [2, 2]
263-
assert captured == [((1,), (2.0,), 6.0), ((2,), (3.0,), 6.0)]
261+
assert captured == [
262+
((1,), (2.0,), 6.0, "metric-b"),
263+
((2,), (3.0,), 6.0, "metric-a"),
264+
]
264265

265266

266267
@pytest.mark.asyncio

0 commit comments

Comments
 (0)