mozilla / jira-bugzilla-integration

Jira Bugzilla Integration (JBI) - system to sync bugs and issues
Mozilla Public License 2.0
8 stars 22 forks source link

How to handle invalid webhook payloads? #967

Open leplatrem opened 2 months ago

leplatrem commented 2 months ago

JBI could fail at parsing Webhook incoming request with:

Currently, JBI logs the error and returns HTTP 422.

We may want to leverage the queue to return HTTP 200 instead and store the payload.

option 0: status quo

Do not change current behaviour

option 1: refactor queue code to allow arbitrary payloads

Current code uses track_failed(payload: bugzilla.WebhookRequest, exc: Exception)

In order to be able to store the invalid incoming payload in the queue, we would have to modify the queue methods and models to allow arbitrary payloads.

This would prevent us from accessing payload attributes like this:

https://github.com/mozilla/jira-bugzilla-integration/blob/7f99b9ee2498a951cc4f3e4ec13d653c0990a9db/jbi/queue.py#L80

Turning the arbitrary payload into WebhookRequest would happen explicitly in the retry_failed() code before calling execute_action()

option 2: add new queue method

Instead of changing the models we could add backend and queue methods:

This would store the content in the queue, assuming that the retry job won't be able to process the content until the code is changed and redeployed.