fix(freshness): calibrate kn staleness thresholds to weekly cadence
All checks were successful
CI / changes (pull_request) Successful in 7s
CI / frontend-tests (pull_request) Has been skipped
CI / openapi-codegen-check (pull_request) Successful in 1m49s
CI / backend-tests (pull_request) Successful in 11m1s

kn (DOM.РФ ЖК) is scheduled WEEKLY (settings.scrape_kn_cron='15 4 * * mon'),
but its freshness thresholds were fresh_days=2 / stale_days=5 — so the monitor
flagged kn "stale" every Wed-Sun by design, a guaranteed weekly false-positive
that would desensitize the team to the GlitchTip alert. The freshness monitor
(#1904) caught this on its first prod run (06-26 09:00 MSK: "kn [stale, 3.9d]").

Recalibrate to weekly cadence (mirror objective 7/14): fresh_days=8 (full week +
Monday-run completion buffer), stale_days=14 (alert only after ~two missed
Mondays). +regression test pinning kn stays fresh through the week.

Refs #73
This commit is contained in:
Light1YT 2026-06-26 11:20:02 +05:00
parent 66da75681f
commit 1ea8d0b721
2 changed files with 19 additions and 2 deletions

View file

@ -1290,8 +1290,12 @@ _FRESHNESS_SOURCES: list[FreshnessSource] = [
label="DOM.РФ kn-API (ЖК)", label="DOM.РФ kn-API (ЖК)",
table="kn_scrape_runs", table="kn_scrape_runs",
work_col="objects_count", work_col="objects_count",
fresh_days=2.0, # kn шедулится ЕЖЕНЕДЕЛЬНО (settings.scrape_kn_cron='15 4 * * mon', Mon 04:15 МСК),
stale_days=5.0, # поэтому 2/5 дней давали ложный "stale" каждую среду-воскресенье. Калибруем под
# недельную каденцию (как objective 7/14): fresh до 8 дней (полная неделя + добег
# понедельничного прогона), stale при пропуске ~двух понедельников.
fresh_days=8.0,
stale_days=14.0,
critical=True, critical=True,
), ),
FreshnessSource( FreshnessSource(

View file

@ -195,3 +195,16 @@ def test_classify_freshness_boundaries() -> None:
assert f(4.9, 2.0, 5.0) == "stale" assert f(4.9, 2.0, 5.0) == "stale"
assert f(5.0, 2.0, 5.0) == "critical" # ровно stale_days → critical assert f(5.0, 2.0, 5.0) == "critical" # ровно stale_days → critical
assert f(100.0, 2.0, 5.0) == "critical" assert f(100.0, 2.0, 5.0) == "critical"
def test_kn_thresholds_match_weekly_cadence() -> None:
"""kn шедулится еженедельно (Mon cron) → пороги должны покрывать полную неделю,
иначе ложный 'stale' каждую среду-воскресенье. Регрессия на калибровку."""
kn = next(s for s in admin_scrape._FRESHNESS_SOURCES if s.source == "kn")
f = admin_scrape._classify_freshness
# В течение недели после понедельничного прогона kn остаётся свежим.
assert f(3.9, kn.fresh_days, kn.stale_days) == "fresh" # пятница
assert f(6.5, kn.fresh_days, kn.stale_days) == "fresh" # воскресенье
# Пропуск одного понедельника → stale; двух → critical.
assert f(9.0, kn.fresh_days, kn.stale_days) == "stale"
assert f(15.0, kn.fresh_days, kn.stale_days) == "critical"