Page MenuHomePhabricator

Load Google Search Console data from BigQuery as soon as it's available and reload when data corrections occur
Open, In Progress, MediumPublic

Description

Currently, we start loading Google Search Console data for day D into the Data Lake at D+4.7. The data is generally available in BigQuery on D+2.

There are two problems with this schedule:

  • The longer-than-necessary delay makes it impossible to use this data in the weekly reporting process
  • We have now seen corrected data arrive as late as 8.4 days from the end of the data date (and, as it happens, that correction had a substantial impact so ignoring it isn't acceptable—see T436144)

So we need to make two changes:

  • Load the data roughly as soon as it becomes available (a fixed delay like 2 days after the end of the data date is fine)
  • Monitor for corrections and, when one occurs, reload the affected data
    • We (metric steward/analysts) need a notification when this happens (and it would be really useful if that notification gave the per-day impact of the correction on the total count of impressions and clicks)

I'm assuming that Google will not insert the corrected data into BigQuery if we've already deleted that day's partition (Google doesn't seem to have documented this anywhere, so if it becomes important, we could ask through our contacts). So we'll need to pick how long to retain the data in BigQuery based on how long we want to be able to receive corrections (or recover from errors inserting into the Data Lake).

I suggest 1 month. That's a round number well over the 8.4 days that's the highest time-to-correction we've seen so far. Based on the storage cost estimate I did in April, the ongoing cost for retaining a month of data will be about $220 per month, which seems acceptable (according to that estimate, we could further cut the cost by about 80% by switching to the physical storage billing model).

Appendix: time to correction

So far, during roughly one year of exporting search data to BigQuery, we've seen 2 different data corrections affecting a total of 7 days of data.

Query:

SELECT
  data_date,
  MAX(publish_time) AS correction_time,
  -- Days between the end of the data date and the corrected data
  -- landing in BigQuery
  ROUND(TIMESTAMP_DIFF(
    MAX(publish_time),
    CAST(DATE_ADD(data_date, INTERVAL 1 DAY) AS TIMESTAMP),
    HOUR
  ) / 24, 2) AS days_until_correction
FROM `search-console-export-470421`.searchconsole_wikipedia_org.ExportLog
WHERE epoch_version > 0
GROUP BY data_date
ORDER BY data_date

Results:

data_datecorrection_timedays_until_correction
2026-04-232026-04-27 03:57:10.697000+00:003.13
2026-04-242026-04-27 23:35:14.174000+00:002.96
2026-08-132026-08-21 06:05:06.418000+00:007.25
2026-08-142026-08-23 10:32:25.836000+00:008.42
2026-08-152026-08-23 05:31:58.106000+00:007.21
2026-08-162026-08-23 19:08:08.577000+00:006.79
2026-08-172026-08-23 03:52:28.206000+00:005.13

Appendix: time to data

Query:

WITH time_to_data AS (
    SELECT
    -- Days between the end of the data date and the data landing in BigQuery
    -- (corrections excluded)
    ROUND(TIMESTAMP_DIFF(
        publish_time,
        CAST(DATE_ADD(data_date, INTERVAL 1 DAY) AS TIMESTAMP),
        HOUR
    ) / 24, 2) AS days_to_data
    FROM `search-console-export-470421`.searchconsole_wikipedia_org.ExportLog
    WHERE epoch_version = 0
)
SELECT DISTINCT
    PERCENTILE_CONT(days_to_data, 0.5) OVER () AS median_days_to_data,
    PERCENTILE_CONT(days_to_data, 0.9) OVER () As p90_days_to_data,
    MAX(days_to_data) OVER () AS max_days_to_data
FROM time_to_data

Results:

median_days_to_datap90_days_to_datamax_days_to_data
1.422.466.96

Details

Related Changes in GitLab:
TitleReferenceAuthorSource BranchDest Branch
GSC: alert DE on corrections, longer gate waitrepos/data-engineering/airflow-dags!2856aquT436193_gsc_alert_de_longer_gate_timeoutmain
GSC: give mapped backup pod k8s-API accessrepos/data-engineering/airflow-dags!2739aquT436193_fix_kpo_mapped_operatormain
Fix recent extension of GSC import dagrepos/data-engineering/airflow-dags!2671aquT436193_gcs_handle_late_update_fix_2main
GSC: reload data on late BigQuery correctionsrepos/data-engineering/airflow-dags!2610aquT436193_gcs_handle_late_updatemain
Customize query in GitLab

Event Timeline

@nshahquinn-wmf Would an immediate daily update paired with a 2-4 days backfill make sense? That way we could ingest recent data timely, but have accurate data long-term. We can evaluate the technical effort.

Given that corrections are pretty rare and can happen well after 4 days later, it seems like a better solution is to check the export log in BigQuery for corrections (epoch_version > 0) whenever we check for new data, and reload if we see any we haven't seen before.

So we'll need to pick how long to retain the data in BigQuery based on how long we want to be able to receive corrections (or recover from errors inserting into the Data Lake).

I suggest 1 month.

I'm going to run this by Maryana to confirm she's okay with the trade-off.

Maryana agrees that retaining a month of data (just to be extremely clear: a rolling 30 days of data, not the current calendar month) is enough.

@nshahquinn-wmf would it make sense re-load individual days at a fixed delay, e.g. 7 days?
That way we would download the data twice, but it would simplify the pipeline logic greatly.

@nshahquinn-wmf would it make sense re-load individual days at a fixed delay, e.g. 7 days?
That way we would download the data twice, but it would simplify the pipeline logic greatly.

Unfortunately, I don't think that would work.

Without automated monitoring for corrections, we would likely miss any that happen after the fixed delay (I only noticed T436144 because I happen to still be pulling data from BigQuery directly and noticed by chance it didn't match the Superset dashboard built on Data Lake data). We could avoid that by making the fixed delay the full retention time (e.g. 30 days), but then we would be waiting unnecessarily long before incorporating most corrections.

Additionally, regardless of the timing of the delay, silently reloading every single day's data would mean we wouldn't know when a correction actually happened, which is important so we can check if we need to repeat analyses or correct our metric reporting (which, again, was the case with this latest correction).

Just confirmed the immediate loading is already working: wmf_raw.google_search_console_site_impression has data through 1 September (the same as the web console and BigQuery).

Thank you @Antoine_Quhen and @Ahoelzl! 🎉

Closing: everything requested here is in production in the google_search_console_to_hdfs_daily DAG.

Load as soon as the data is available

  • Each day is enqueued 25h after the data date ends, and a gate on ExportLog polls every 30 min until both tables are logged (live since 2026-09-03).
  • The gate now gives up after 36h instead of 30h, about 2.5 days after the data date ends, above the observed p90 time-to-data of 2.46 days.

Detect and reload corrections

  • Each run checks each property's ExportLog for corrections (epoch_version > 0). Each affected HDFS partition is backed up, then its chain is cleared and reloaded, and wmf_readership.google_sitedata_daily_aggregate is recomputed for that day.
  • Added in https://gitlab.wikimedia.org/repos/data-engineering/airflow-dags/-/merge_requests/2610; fixed in !2671, !2734 and !2739 (the last two after the first real-world correction, for data_date 2026-09-30).

Notification

  • Before reloading, a warning email goes to movement-insights+alerts@wikimedia.org and now also to data-engineering-alerts@wikimedia.org. It lists each affected partition and its backup path under /user/analytics/google_search_console_to_hdfs_daily_correction_backup.
  • Google doesn't tell us what a correction changed, so the per-day impact on impressions and clicks is computed by comparing the backup with the reloaded partition, as the email explains. Please delete the backups once you're done with them.

Retention in BigQuery
The rolling 30-day retention (and the switch to physical storage billing) is tracked in T444242: https://gitlab.wikimedia.org/repos/data-engineering/gcp-management/-/merge_requests/1, waiting for validation. 30 days stays well above the latest correction seen so far (8.4 days).