mirror of
https://github.com/ShayManor/github-readme-stats.git
synced 2026-12-02 11:53:48 +05:30
fix(fetcher): keep last-good counts on GitHub rate limits + expose fetch metrics
Rate-limited / 5xx / network failures were silently returning 0 from the
commit- and PR-count paths, then overwriting good values in fetcher.db —
turning a traffic spike into permanently-wrong "0 commits" cards. Raise
GitHubTransientError instead so the fetch aborts and the last-good row is
retained; genuine NOT_FOUND still yields 0.
Add a shared fetch-outcome counter (fetch_metrics table, spanning the web
workers and the cron container) surfaced at an unauthenticated GET /metrics
as ghstats_fetch_total{outcome="ok|not_found|rate_limited|error"}, so rate
limits are visible to the monitoring stack instead of dying silently.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -30,6 +30,20 @@ def test_endpoints_require_internal_token(client):
|
||||
assert r.status_code == 401
|
||||
|
||||
|
||||
def test_metrics_endpoint_no_auth_and_prometheus_format(client):
|
||||
from src import db as dbmod
|
||||
dbmod.bump_fetch_metric("ok")
|
||||
dbmod.bump_fetch_metric("rate_limited")
|
||||
r = client.get("/metrics")
|
||||
assert r.status_code == 200
|
||||
body = r.get_data(as_text=True)
|
||||
assert "# TYPE ghstats_fetch_total counter" in body
|
||||
assert 'ghstats_fetch_total{outcome="ok"} 1' in body
|
||||
assert 'ghstats_fetch_total{outcome="rate_limited"} 1' in body
|
||||
# Every outcome is emitted even at zero so rate() has a baseline sample.
|
||||
assert 'ghstats_fetch_total{outcome="not_found"} 0' in body
|
||||
|
||||
|
||||
@resp_lib.activate
|
||||
def test_data_auto_fetches_on_miss(client, monkeypatch):
|
||||
# The fetcher fires the independent GitHub calls in parallel, so we
|
||||
|
||||
Reference in New Issue
Block a user