/status und /metrics zeigten die letzte Dauer und einen Durchschnitt. Ein Durchschnitt versteckt genau die Anfragen, die weh tun: ein Ziel, das 95 Prozent schnell und 5 Prozent in einer Minute beantwortet, hat einen harmlosen Mittelwert. Jetzt zählt jeder Endpunkt ein Histogramm mit festen Grenzen (0,1 s bis 60 s, plus +Inf) und exportiert es in kumulativer Form, damit histogram_quantile je Ziel rechnet. /status nennt dazu p95_ms, ausdrücklich als Obergrenze des Eimers, in dem die 95-Prozent-Marke liegt — und -1, solange nichts gemessen wurde. Neue Alarmregel JunctionEndpointSlowP95 (p95 über 20 s, 15 Minuten, nur bei Verkehr) in packaging/prometheus-junction.yml; auf n95 geladen, health=ok. Beim Testen einen Fehler gebaut und gefunden, der auf dem laufenden Router sofort zugeschlagen hätte: die Histogramm-Ausgabe ließ die Zustandssperre gesperrt zurück. Der ERSTE /metrics-Scrape ging noch durch, danach antwortete der ganze Prozess nicht mehr — Prometheus scrapt alle 15 Sekunden, der Router wäre still gestorben. Gefunden, weil ich den Ablauf Status → Scrape → Status → Anfrage einzeln durchgespielt habe, nicht weil die Suite es gemerkt hätte (sie scrapt einmal). Jetzt steht die Sperre richtig und der Ablauf ist auf n95 live geprüft: Scrape, Status, Chat, 20 Sekunden später wieder alles 200. Tests: drei Prüfungen mehr — +Inf-Eimer gleich der Zahl bedienter Anfragen, Eimer monoton, p95 im Status. make test: PASS, 232 Prüfungen, 160 s.
101 lines
6.5 KiB
YAML
101 lines
6.5 KiB
YAML
# junction — der Router vor den Modellen.
|
|
#
|
|
# Zwei Dinge, die man verwechseln kann: "Prometheus erreicht den Router nicht" (up == 0)
|
|
# und "der Router erreicht einen Endpunkt nicht" (junction_endpoint_up == 0). Das erste
|
|
# ist ein Ausfall der Vermittlung selbst, das zweite oft nur ein Gerät, das absichtlich
|
|
# aus ist. Deshalb zwei Regeln mit unterschiedlicher Härte, und die Pause zählt nicht
|
|
# als Ausfall: ein pausierter Endpunkt ist eine Entscheidung, kein Fehler.
|
|
groups:
|
|
- name: junction
|
|
rules:
|
|
- alert: JunctionDown
|
|
expr: up{job="junction"} == 0
|
|
for: 3m
|
|
labels:
|
|
severity: critical
|
|
system: junction
|
|
annotations:
|
|
summary: "junction ist nicht scrapebar ({{ $labels.instance }})"
|
|
description: "Der Router vor den Modellen antwortet nicht auf /metrics. Jede Anfrage der Agenten läuft derzeit entweder direkt zu einem Anbieter oder gar nicht."
|
|
runbook: "systemctl status junction; journalctl -u junction -n 50. Der Dienst hat Restart=always — antwortet er trotzdem nicht, ist die Konfiguration kaputt, nicht der Prozess (junction --config /etc/junction/junction.conf von Hand starten zeigt die Zeile)."
|
|
|
|
- alert: JunctionEndpointDown
|
|
expr: junction_endpoint_up == 0 and on(endpoint) junction_endpoint_paused == 0
|
|
for: 30m
|
|
labels:
|
|
severity: warning
|
|
system: junction
|
|
annotations:
|
|
summary: "Endpunkt {{ $labels.endpoint }} ist seit 30 Minuten nicht nutzbar"
|
|
description: "pausiert, offline, im Cooldown oder über dem harten Budget. Die Kette läuft weiter, solange ein anderes Ziel greift — diese Meldung heißt: ein Ziel fehlt dauerhaft."
|
|
runbook: "curl -s localhost:8090/status | jq '.endpoints[] | select(.name==\"{{ $labels.endpoint }}\")' — last_error und last_hook_reason nennen den Grund. POST /admin/resume/<name> räumt Pause, Cooldown und Offline."
|
|
|
|
- alert: JunctionFailoverHeavy
|
|
expr: sum(rate(junction_requests_total{outcome="fail"}[10m])) > 0.05
|
|
for: 10m
|
|
labels:
|
|
severity: warning
|
|
system: junction
|
|
annotations:
|
|
summary: "junction scheitert an mehr als 3 Anfragen pro Minute"
|
|
description: "Requests, die keinen Endpunkt gefunden haben. Meist ein 429-Sturm beim Anbieter, ein erschöpftes Budget oder ein Modell, das kein Ziel bedienen kann."
|
|
runbook: "journalctl -u junction -n 100 | grep -E 'failed|retry|no_endpoint'. Der Retry (retry_num) fängt kurze Aussetzer ab; was hier zählt, ist schon durch alle Versuche gefallen."
|
|
|
|
# A key that is nearly out of budget is a client that will start getting 403s soon.
|
|
# The number comes from the same ledger /spend reads, so the alert and the dashboard
|
|
# cannot disagree — but it is this process's own bookkeeping, not the provider's.
|
|
- alert: JunctionVkeyBudgetNearlySpent
|
|
expr: junction_vkey_budget_usd > 0 and (junction_vkey_spend_usd_total / junction_vkey_budget_usd) > 0.9
|
|
for: 5m
|
|
labels:
|
|
severity: warning
|
|
system: junction
|
|
annotations:
|
|
summary: "virtual key {{ $labels.vkey }} has spent over 90 % of its monthly budget"
|
|
description: "At {{ $value | printf \"%.2f\" }} of the ratio. Once the budget is used up junction answers 403 vkey_budget_exhausted for that key — a client, not an endpoint, stops working."
|
|
runbook: "curl -s localhost:8090/spend | jq '.vkeys[] | select(.name==\"{{ $labels.vkey }}\")' shows where the money went. Either raise the budget in the vkey line or point the client at a cheaper model."
|
|
|
|
# The peer cache is a shortcut; errors mean the shortcut is gone, not that requests
|
|
# fail. That is exactly why it needs an alert: nothing user-visible breaks.
|
|
- alert: JunctionCachePeerFailing
|
|
expr: junction_cache_peers > 0 and increase(junction_cache_peer_errors_total[10m]) > 10
|
|
for: 10m
|
|
labels:
|
|
severity: warning
|
|
system: junction
|
|
annotations:
|
|
summary: "the shared cache reaches its peers {{ $value | printf \"%.0f\" }} times badly per 10 min"
|
|
description: "Requests are still served, from the provider rather than from the peer's cache. Errors here are: peer not reachable, peer secret wrong, frame rejected."
|
|
runbook: "curl -s -H \"X-Junction-Peer: $JUNCTION_CACHE_KEY\" http://<peer>:<cache port>/cache/stats — no answer means the port is down or cache_secret_env differs between the nodes. Check journalctl -u junction | grep cache_peer."
|
|
|
|
# A drain that never finishes is an instance that has stopped taking traffic and
|
|
# still holds its slot: the rolling update is half done and nobody noticed.
|
|
- alert: JunctionDrainStuck
|
|
expr: junction_draining == 1
|
|
for: 10m
|
|
labels:
|
|
severity: warning
|
|
system: junction
|
|
annotations:
|
|
summary: "an instance has been draining for 10 minutes"
|
|
description: "The listening socket is closed (no new requests) but the process has not exited. Either a request hangs longer than drain_timeout or the drain path itself is stuck; until it exits, a rolling update is only half done."
|
|
runbook: "curl -s localhost:8090/status | jq '.queue' — inflight tells whether requests are really running. journalctl -u junction | grep -E 'draining|drained|drain_timeout'."
|
|
|
|
# Latency as a percentile, not as the average: an endpoint that answers 95 % fast and
|
|
# 5 % of the time in a minute keeps a harmless mean. The histogram is per endpoint
|
|
# (junction_endpoint_latency_seconds_bucket), so this is decidable per target.
|
|
- alert: JunctionEndpointSlowP95
|
|
expr: |
|
|
histogram_quantile(0.95,
|
|
sum by (endpoint, le) (rate(junction_endpoint_latency_seconds_bucket[10m]))) > 20
|
|
and
|
|
sum by (endpoint) (rate(junction_endpoint_latency_seconds_count[10m])) > 0
|
|
for: 15m
|
|
labels:
|
|
severity: warning
|
|
system: junction
|
|
annotations:
|
|
summary: "p95 latency of {{ $labels.endpoint }} is over 20 s ({{ $value | printf \"%.1f\" }} s)"
|
|
description: "Ninety-five percent of the requests to this endpoint were faster than this. A slow-but-working endpoint keeps the mean harmless; the percentile is what a waiting client feels."
|
|
runbook: "curl -s localhost:8090/status | jq '.endpoints[] | select(.name==\"{{ $labels.endpoint }}\")' — last_ms, p95_ms and the histogram tell whether it is the endpoint or its queue. journalctl -u junction | grep served_by shows the per-request numbers."
|