Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
909b88af56 | ||
|
|
f9f342cee7 |
@@ -12,8 +12,8 @@ The predictor reads two data sources:
|
|||||||
2. **Heartbeat logs** (`heartbeat/ticks_*.jsonl`) — Gitea availability,
|
2. **Heartbeat logs** (`heartbeat/ticks_*.jsonl`) — Gitea availability,
|
||||||
local inference health
|
local inference health
|
||||||
|
|
||||||
It compares a **recent window** (last N hours) against a **baseline window**
|
It compares a **recent window** (last N hours of activity) against the **previous active window**
|
||||||
(previous N hours) to detect surges and degradation.
|
(previous N hours ending at the most recent event before the current window) so sparse telemetry still yields a meaningful baseline.
|
||||||
|
|
||||||
## Output Contract
|
## Output Contract
|
||||||
|
|
||||||
|
|||||||
@@ -90,13 +90,19 @@ def compute_rates(
|
|||||||
|
|
||||||
latest = max(_parse_ts(r["timestamp"]) for r in rows)
|
latest = max(_parse_ts(r["timestamp"]) for r in rows)
|
||||||
recent_cutoff = latest - timedelta(hours=horizon_hours)
|
recent_cutoff = latest - timedelta(hours=horizon_hours)
|
||||||
baseline_cutoff = latest - timedelta(hours=horizon_hours * 2)
|
|
||||||
|
|
||||||
recent = [r for r in rows if _parse_ts(r["timestamp"]) >= recent_cutoff]
|
recent = [r for r in rows if _parse_ts(r["timestamp"]) >= recent_cutoff]
|
||||||
baseline = [
|
|
||||||
r for r in rows
|
earlier = [r for r in rows if _parse_ts(r["timestamp"]) < recent_cutoff]
|
||||||
if baseline_cutoff <= _parse_ts(r["timestamp"]) < recent_cutoff
|
if earlier:
|
||||||
]
|
previous_latest = max(_parse_ts(r["timestamp"]) for r in earlier)
|
||||||
|
previous_cutoff = previous_latest - timedelta(hours=horizon_hours)
|
||||||
|
baseline = [
|
||||||
|
r for r in earlier
|
||||||
|
if _parse_ts(r["timestamp"]) >= previous_cutoff
|
||||||
|
]
|
||||||
|
else:
|
||||||
|
baseline = []
|
||||||
|
|
||||||
recent_rate = len(recent) / max(horizon_hours, 1)
|
recent_rate = len(recent) / max(horizon_hours, 1)
|
||||||
baseline_rate = (
|
baseline_rate = (
|
||||||
|
|||||||
@@ -99,6 +99,17 @@ class TestComputeRates:
|
|||||||
_, _, surge, _, _ = compute_rates(rows, horizon_hours=6)
|
_, _, surge, _, _ = compute_rates(rows, horizon_hours=6)
|
||||||
assert surge < 1.5
|
assert surge < 1.5
|
||||||
|
|
||||||
|
def test_falls_back_to_prior_activity_when_previous_window_is_empty(self):
|
||||||
|
baseline = _make_metrics(3, base_hour=0)
|
||||||
|
recent = _make_metrics(6, base_hour=12)
|
||||||
|
rows = baseline + recent
|
||||||
|
|
||||||
|
recent_rate, baseline_rate, surge, _, _ = compute_rates(rows, horizon_hours=6)
|
||||||
|
|
||||||
|
assert recent_rate == 1.0
|
||||||
|
assert baseline_rate == 0.5
|
||||||
|
assert surge == 2.0
|
||||||
|
|
||||||
|
|
||||||
# ── Caller Analysis ──────────────────────────────────────────────────────────
|
# ── Caller Analysis ──────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user