refactor(outgoing_webhooks): raise errors in the analytics pipeline in case of API client errors or non-2xx responses #4894
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Type of Change
Description
This PR refactors the outgoing webhooks logic to raise errors to the analytics pipeline (involving Kafka and ClickHouse) in case the webhook was not at all sent due to API client errors, or if the merchant server returns a non-2xx HTTP response.
This was done in two steps:
Since it's easier to follow along when reviewing one commit at a time, I'd suggest the reviewers to do the same.
Motivation and Context
This fixes a bug where failed webhook deliveries were falsely displayed as successful on the control center, since the analytics pipeline had no information that an error had occurred.
How did you test it?
With a local Kafka and ClickHouse setup:
In case of successful deliveries, the
is_error
field must befalse
anderror
field must not be populated in the Kafka and ClickHouse events:Kafke:

ClickHouse:

In case of failed webhook deliveries due to errors where no HTTP response was involved (non-existent domain name, some configuration issues with the client, etc.), the
is_error
field must betrue
and theerror
field must be populated withCallToMerchantFailed
:Kafka:

ClickHouse:

In case of failed webhook deliveries due to the merchant server returning a non-2xx HTTP status code, the
is_error
field must betrue
and theerror
field must be populated withNotReceivedByMerchant
:Kafka:

ClickHouse:

Checklist
cargo +nightly fmt --all
cargo clippy