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,23 @@ def test_upsert_and_get_round_trip(tmp_db):
|
||||
assert row["fetched_at"]
|
||||
|
||||
|
||||
def test_fetch_metrics_round_trip(tmp_db):
|
||||
# Zero-filled for every known outcome before anything is recorded.
|
||||
assert dbmod.read_fetch_metrics() == {o: 0 for o in dbmod.FETCH_OUTCOMES}
|
||||
dbmod.bump_fetch_metric("ok")
|
||||
dbmod.bump_fetch_metric("ok")
|
||||
dbmod.bump_fetch_metric("rate_limited")
|
||||
counts = dbmod.read_fetch_metrics()
|
||||
assert counts["ok"] == 2
|
||||
assert counts["rate_limited"] == 1
|
||||
assert counts["not_found"] == 0
|
||||
|
||||
|
||||
def test_fetch_metric_unknown_outcome_buckets_to_error(tmp_db):
|
||||
dbmod.bump_fetch_metric("bogus")
|
||||
assert dbmod.read_fetch_metrics()["error"] == 1
|
||||
|
||||
|
||||
def test_payload_hash_is_deterministic_and_changes_on_diff():
|
||||
h1 = dbmod.payload_hash({"a": 1, "b": 2})
|
||||
h2 = dbmod.payload_hash({"b": 2, "a": 1})
|
||||
|
||||
Reference in New Issue
Block a user