Skip to content

Add script for retrying all missed job webhooks - #1049

Draft
mvandenburgh wants to merge 2 commits into
mainfrom
webhook-backfill-script
Draft

Add script for retrying all missed job webhooks#1049
mvandenburgh wants to merge 2 commits into
mainfrom
webhook-backfill-script

Conversation

@mvandenburgh

@mvandenburgh mvandenburgh commented Jan 30, 2025

Copy link
Copy Markdown
Member

This adds a Django management script that

  1. Queries the web_hook_logs table of the GitLab DB for all webhook events in the past n seconds (n is an argument to the script)
  2. Cross checks each of those rows with the Analytics DB, to figure out if any jobs had webhooks fired but do not exist in the analytics DB (i.e. jobs that were "missed" for any reason)
  3. Uses the GitLab API to resend those webhook events.

I've ran variations of this script in the past to retry missed job webhooks after fixing bugs in the webhook handler, downtime of the webhook handler, etc. and it works.

@mvandenburgh
mvandenburgh force-pushed the webhook-backfill-script branch 3 times, most recently from d13a646 to b234057 Compare February 6, 2025 20:40
@mvandenburgh
mvandenburgh force-pushed the webhook-backfill-script branch from b234057 to fd35a07 Compare May 29, 2025 01:29
@mvandenburgh
mvandenburgh marked this pull request as ready for review May 29, 2025 01:30
@mvandenburgh

mvandenburgh commented May 29, 2025

Copy link
Copy Markdown
Member Author

@jjnesbitt with the analytics webhook being down the last couple days, it seems like now would be a good time to test this out and get it merged. IIRC I ran it a while back and it appeared to work, but I don't think we've needed to retry this many job events before.

@mvandenburgh
mvandenburgh requested a review from jjnesbitt May 29, 2025 01:33
@mvandenburgh
mvandenburgh force-pushed the webhook-backfill-script branch from fd35a07 to 600ef38 Compare May 29, 2025 13:57
@mvandenburgh
mvandenburgh removed the request for review from jjnesbitt May 29, 2025 14:01
@mvandenburgh

Copy link
Copy Markdown
Member Author

Just realized this has to be updated for the new job model. So not ready for review yet, sorry for the confusion

@mvandenburgh
mvandenburgh force-pushed the webhook-backfill-script branch 2 times, most recently from fdb5af8 to 3dde210 Compare May 29, 2025 14:52
@mvandenburgh

Copy link
Copy Markdown
Member Author

This should be ready now.

@mvandenburgh
mvandenburgh requested a review from jjnesbitt May 29, 2025 16:12
@mvandenburgh
mvandenburgh force-pushed the webhook-backfill-script branch from 4b5691b to a9f4488 Compare May 29, 2025 17:53
Comment on lines +30 to +40
def retry_webhook(webhook_event: WebhookEvent, dry_run: bool) -> None:
if dry_run:
click.echo(f"Would retry webhook {webhook_event}")
return

click.echo(f"Retrying webhook {webhook_event}")
gl = get_gitlab_handle()

# https://docs.gitlab.com/ee/api/project_webhooks.html#resend-a-project-webhook-event
retry_url = f"/projects/{webhook_event.project_id}/hooks/{webhook_event.webhook_id}/events/{webhook_event.webhook_event_id}/resend"
gl.http_post(retry_url)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: try fetching the webhook payload from the web_hook_logs table and invoke the ingest function directly instead of sending a webhook

@mvandenburgh
mvandenburgh removed the request for review from jjnesbitt June 2, 2025 16:40
@mvandenburgh
mvandenburgh marked this pull request as draft June 2, 2025 16:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant