fix(gdelt): stop retrying 429 over http, back off instead of tracebacking #69

Merged
sirius merged 1 commit from fix/gdelt-429-backoff into master 2026-11-21 23:13:19 +00:00
Owner

Symptom

deploy/osint-ingester logged a full traceback on every producer cycle (17:19, 17:24, 18:01 local, and 14 times in 12h):

WARNING osint.sources: GDELT HTTPS failed (...429...); retrying HTTP
ERROR osint.ingester: GDELT fetch failed
httpx.HTTPStatusError: Client error '429 Too Many Requests'

USGS/EONET/CISA KEV/FIRMS in the same cycle returned 200.

What the quota actually looks like (measured 2026-11-21)

  • GET https://api.gdeltproject.org/api/v2/doc/doc?... from three independent egress paths (ingester pod on linode 10.244.2.0/16, the linode host itself, home/137.118.156.124) returns 429 with body Please limit requests to one every 5 seconds ... and no Retry-After header.
  • It is not a hard IP block: successful cycles did land (GDELT -> 50 articles at 17:35, 17:46 local; 634 gdel-t2 events in the DB), roughly 1 cycle in 5-6. Every failure was charged twice by the https->http retry.
  • 200 with a prose body is the documented GDELT error style too, so a naive resp.json() can throw on a throttle.

Change

  • app/sources.py:ingest_gdelt
    • On 429 (or 200 + non-JSON body): set a backoff window and return 0 instead of raising.
      GDELT_BACKOFF_BASE (300s) doubling per consecutive throttle up to GDELT_BACKOFF_MAX (1800s); Retry-After (Δ-seconds or HTTP-date) honoured when present.
    • Cycles inside the window skip the call entirely and log one line.
    • The https->http fallback now only covers httpx.TransportError (TLS/connect, the expired-cert case it was written for), never an HTTP error status.
  • app/run_ingester.py:producer_loop logs a GDELT failure as a single WARNING, no traceback.
  • tests/test_gdelt_backoff.py: 7 unit tests (no retry on 429, cooldown skip, doubling+cap, Retry-After, 200-prose, success resets, transport fallback still works).

Verification

pytest tests/test_gdelt_backoff.py tests/test_event_ingest.py -q -> 13 passed.
Full suite: 416 passed, 10 pre-existing failures unrelated to this diff (test_news_scraper needs a scraper dep not in the app image; test_hud_chrome/test_geofence fail identically on unmodified master).

Live proof in the cluster follows the image build (pin amd64-<sha12> in homek8s): 3 consecutive cycles with a single GDELT 429 ... backing off until <ts> line and no traceback.

## Symptom `deploy/osint-ingester` logged a full traceback on every producer cycle (17:19, 17:24, 18:01 local, and 14 times in 12h): ``` WARNING osint.sources: GDELT HTTPS failed (...429...); retrying HTTP ERROR osint.ingester: GDELT fetch failed httpx.HTTPStatusError: Client error '429 Too Many Requests' ``` USGS/EONET/CISA KEV/FIRMS in the same cycle returned 200. ## What the quota actually looks like (measured 2026-11-21) - `GET https://api.gdeltproject.org/api/v2/doc/doc?...` from **three** independent egress paths (ingester pod on linode `10.244.2.0/16`, the linode host itself, home/137.118.156.124) returns `429` with body `Please limit requests to one every 5 seconds ...` and **no `Retry-After` header**. - It is not a hard IP block: successful cycles did land (`GDELT -> 50 articles` at 17:35, 17:46 local; 634 `gdel-t2` events in the DB), roughly 1 cycle in 5-6. Every failure was charged twice by the https->http retry. - `200` with a prose body is the documented GDELT error style too, so a naive `resp.json()` can throw on a throttle. ## Change - `app/sources.py:ingest_gdelt` - On `429` (or `200` + non-JSON body): set a backoff window and `return 0` instead of raising. `GDELT_BACKOFF_BASE` (300s) doubling per consecutive throttle up to `GDELT_BACKOFF_MAX` (1800s); `Retry-After` (Δ-seconds or HTTP-date) honoured when present. - Cycles inside the window skip the call entirely and log one line. - The https->http fallback now only covers `httpx.TransportError` (TLS/connect, the expired-cert case it was written for), never an HTTP error status. - `app/run_ingester.py:producer_loop` logs a GDELT failure as a single `WARNING`, no traceback. - `tests/test_gdelt_backoff.py`: 7 unit tests (no retry on 429, cooldown skip, doubling+cap, Retry-After, 200-prose, success resets, transport fallback still works). ## Verification `pytest tests/test_gdelt_backoff.py tests/test_event_ingest.py -q` -> 13 passed. Full suite: 416 passed, 10 pre-existing failures unrelated to this diff (`test_news_scraper` needs a scraper dep not in the app image; `test_hud_chrome`/`test_geofence` fail identically on unmodified master). Live proof in the cluster follows the image build (pin `amd64-<sha12>` in homek8s): 3 consecutive cycles with a single `GDELT 429 ... backing off until <ts>` line and no traceback.
GDELT's DOC 2.0 API answers 429 with a plain-text body, no Retry-After, and
a per-IP block window that widens with request volume. The https->http retry
only doubled the request count against that quota and could never succeed,
and every cycle logged a full traceback.

- ingest_gdelt: a 429 (or a 200 with a prose body) now sets a backoff window
  (GDELT_BACKOFF_BASE=300s, doubling to GDELT_BACKOFF_MAX=1800s, Retry-After
  honoured when present) and returns 0 instead of raising.
- cycles inside the window skip the call entirely, logging one line.
- the https->http fallback now only covers TransportError (TLS/connect), not
  HTTP error statuses.
- producer_loop logs a GDELT failure as one WARNING line, no traceback.
- tests/test_gdelt_backoff.py covers no-retry-on-429, cooldown skip, doubling
  and cap, Retry-After, 200-prose, success reset, transport fallback.
sirius merged commit fc0cd41b7a into master 2026-11-21 23:13:19 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
sirius/osint-dashboard!69
No description provided.