fix(gdelt): ingest the 15-minute GKG bulk file, keep the DOC API as fallback #70

Merged
sirius merged 1 commit from fix/gdelt-bulk-gkg into master 2026-11-21 23:37:47 +00:00
Owner

Why

osint-dashboard#69 made a GDELT 429 back off instead of tracebacking, but that
only stopped the noise. The DOC 2.0 API is per-IP quota'd from every egress we
have, and events.source_type='gdel-t2' was 634 rows total over 5 days with
hour-long gaps (measured: 0-50/hour, most hours 1-15).

GDELT publishes the same article coverage every 15 minutes as static files with
no key and no quota: https://data.gdeltproject.org/gdeltv2/lastupdate.txt
(200 from inside the ingester pod) indexes *.export.CSV.zip,
*.mentions.CSV.zip and *.gkg.csv.zip.

What

ingest_gdelt now:

  1. reads lastupdate.txt, picks the newest *.gkg.csv.zip (GKG is the file with
    article URL + title + geo), and skips the cycle if it is the file already parsed;
  2. streams the zip and filters rows to the CONFIG GDELT query terms
    ((unrest OR protest OR outage OR cyber OR "power outage")) matched against the
    GKG V1Themes tokens — POWER_OUTAGE, VIOLENT_UNREST, CYBER_ATTACK, …
    so a 500-1000 row window publishes a bounded subset, not the whole file;
  3. maps each surviving row into the exact events.gdelt shape the NATS consumer
    already expects:
    • url = DocumentIdentifier → event_dedup on URL still works unchanged
    • title = <PAGE_TITLE> from the V2ExtrasXML column (html-unescaped)
    • body = source domain, location_name/location_lat/location_lon from
      V2Locations (map pins get real geo)
    • source_timestamp = <PAGE_PRECISEPUBTIMESTAMP>, falling back to the window stamp
    • tags = matched query terms + matching theme tokens (max 10)
    • raw = compact GKG subset (record id, domain, themes[:12], tone, bulk file)
  4. publishes through _publish_unknown, so URLs already in event_dedup never
    reach NATS, and GDELT_BULK_MAX_EVENTS (default 100) caps a single file.

The DOC 2.0 path is kept as _ingest_gdelt_doc, with its 300s→1800s 429
backoff, and only runs when the bulk fetch raises. On the happy path GDELT gets
zero API requests.

Volume

GKG windows measured today: 451-1082 rows, 32-87 matching the CONFIG terms;
events is on a 180-day retention policy, so ~100-250 new rows/hour is within
comfort at 12 MB for 10k rows.

Tests

tests/test_gdelt_bulk.py (9 new): query-term parsing, lastupdate selection,
row mapping (title/geo/timestamp/tone), non-matching and URL-less rows dropped,
cap, repeat-file skip, DOC fallback on bulk failure.
tests/test_gdelt_backoff.py fixture now disables the bulk path so it keeps
pinning DOC behaviour. Full suite: 432 passed, 3 failed
(test_geodence::test_camera_publish_and_insert_do_not_notify,
test_hud_chrome x2) — those 3 fail identically on unmodified master at fc0cd41.

## Why `osint-dashboard#69` made a GDELT 429 back off instead of tracebacking, but that only stopped the noise. The DOC 2.0 API is per-IP quota'd from every egress we have, and `events.source_type='gdel-t2'` was 634 rows total over 5 days with hour-long gaps (measured: 0-50/hour, most hours 1-15). GDELT publishes the same article coverage every 15 minutes as static files with no key and no quota: `https://data.gdeltproject.org/gdeltv2/lastupdate.txt` (200 from inside the ingester pod) indexes `*.export.CSV.zip`, `*.mentions.CSV.zip` and `*.gkg.csv.zip`. ## What `ingest_gdelt` now: 1. reads `lastupdate.txt`, picks the newest `*.gkg.csv.zip` (GKG is the file with article URL + title + geo), and skips the cycle if it is the file already parsed; 2. streams the zip and filters rows to the CONFIG GDELT query terms (`(unrest OR protest OR outage OR cyber OR "power outage")`) matched against the GKG **V1Themes** tokens — `POWER_OUTAGE`, `VIOLENT_UNREST`, `CYBER_ATTACK`, … so a 500-1000 row window publishes a bounded subset, not the whole file; 3. maps each surviving row into the exact `events.gdelt` shape the NATS consumer already expects: - `url` = `DocumentIdentifier` → `event_dedup` on URL still works unchanged - `title` = `<PAGE_TITLE>` from the V2ExtrasXML column (html-unescaped) - `body` = source domain, `location_name`/`location_lat`/`location_lon` from `V2Locations` (map pins get real geo) - `source_timestamp` = `<PAGE_PRECISEPUBTIMESTAMP>`, falling back to the window stamp - `tags` = matched query terms + matching theme tokens (max 10) - `raw` = compact GKG subset (record id, domain, themes[:12], tone, bulk file) 4. publishes through `_publish_unknown`, so URLs already in `event_dedup` never reach NATS, and `GDELT_BULK_MAX_EVENTS` (default 100) caps a single file. The DOC 2.0 path is **kept** as `_ingest_gdelt_doc`, with its 300s→1800s 429 backoff, and only runs when the bulk fetch raises. On the happy path GDELT gets zero API requests. ## Volume GKG windows measured today: 451-1082 rows, 32-87 matching the CONFIG terms; `events` is on a 180-day retention policy, so ~100-250 new rows/hour is within comfort at 12 MB for 10k rows. ## Tests `tests/test_gdelt_bulk.py` (9 new): query-term parsing, lastupdate selection, row mapping (title/geo/timestamp/tone), non-matching and URL-less rows dropped, cap, repeat-file skip, DOC fallback on bulk failure. `tests/test_gdelt_backoff.py` fixture now disables the bulk path so it keeps pinning DOC behaviour. Full suite: 432 passed, 3 failed (`test_geodence::test_camera_publish_and_insert_do_not_notify`, `test_hud_chrome` x2) — those 3 fail identically on unmodified `master` at fc0cd41.
The DOC 2.0 API is per-IP quota'd (429 with no Retry-After) and only lands a
fetch every 5-6 cycles, so gdel-t2 coverage was near zero. GDELT publishes the
same articles every 15 minutes as static files with no key and no quota.

ingest_gdelt now parses lastupdate.txt, downloads the newest *.gkg.csv.zip,
filters rows to the CONFIG GDELT query terms (matched against GKG theme
tokens), and maps each surviving row into the existing events.gdelt shape:
title from PAGE_TITLE, url from DocumentIdentifier (so event_dedup on URL is
unchanged), body = source domain, location_name/lat/lon from V2Locations, and
PAGE_PRECISEPUBTIMESTAMP as source_timestamp. Publishing goes through
_publish_unknown, so known URLs are skipped before they hit NATS.

The DOC path (with its 429 backoff) still runs, but only when the bulk fetch
itself fails.
sirius merged commit 76035535bc into master 2026-11-21 23:37:47 +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!70
No description provided.