Skip to content

[Webhook] Allow request parsers to return multiple RemoteEvent's #58248

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 27, 2024

Conversation

kbond
Copy link
Member

@kbond kbond commented Sep 13, 2024

Q A
Branch? 7.2
Bug fix? no
New feature? yes
Deprecations? no
Issues Unblocks #50324
License MIT

I've run into services that send their webhook events in bulk - a single request containing multiple events.

This is one idea to allow this. I'd like to get some input before going further.

TODO:

  • Update changelog
  • Update/add tests

@carsonbot carsonbot added Status: Needs Review Feature RFC RFC = Request For Comments (proposals about features that you want to be discussed) Webhook labels Sep 13, 2024
@carsonbot carsonbot added this to the 7.2 milestone Sep 13, 2024
@carsonbot carsonbot changed the title [RFC][Webhook] Allow request parsers to return multiple RemoteEvent's [Webhook] Allow request parsers to return multiple RemoteEvent's Sep 13, 2024
@kbond kbond force-pushed the feat/webhook-bulk-request-parser branch from db75e57 to fc5d44b Compare September 13, 2024 00:37
@alexandre-daubois
Copy link
Member

Makes sense to me. I think I never came across a service that sends webhook events by batches like this. But to me, that's a nice idea if this exists. I'd be 👍 on this, especially since the implementation is pretty simple!

@kbond
Copy link
Member Author

kbond commented Sep 13, 2024

I think I never came across a service that sends webhook events by batches like this.

Until yesterday, I hadn't either. When working on #58252 I discovered Mailtrap does this and then saw #50324 is blocked because of this also.

@stof
Copy link
Member

stof commented Sep 13, 2024

This is technically a BC break for callers of the parser (as the caller needs to be able to deal with an array).

However, as the typical usage of this parser is to be called by the WebhookController of symfony/webhook (while external packages implement the interface), I would not oppose shipping that in a minor version of the component, with an explicit mention about that in the changelog and upgrade guide. But I'd like to know what other members of the core team think about it.

@stof
Copy link
Member

stof commented Sep 13, 2024

Based on the comment in #50324 (comment), it seems like Sendgrid also batches webhooks but our parser silently ignore all events except the first one.

@kbond
Copy link
Member Author

kbond commented Sep 13, 2024

our parser silently ignore all events except the first one.

😬

Once multiple messages can be parsed in one request, what are your thoughts on what to do when just one fails? Each parser could do there own thing if I'm understanding correctly.

@stof
Copy link
Member

stof commented Sep 13, 2024

Each parser can have its own logic to decide when it returns null (to ignore the webhook) and when it throws an exception

@kbond kbond force-pushed the feat/webhook-bulk-request-parser branch from fc5d44b to 74f7331 Compare September 13, 2024 16:44
@kbond kbond force-pushed the feat/webhook-bulk-request-parser branch 2 times, most recently from 34c4903 to 130ae1b Compare September 14, 2024 16:10
kbond added a commit that referenced this pull request Sep 14, 2024
This PR was merged into the 7.2 branch.

Discussion
----------

[Webhook] add `WebhookController` tests

| Q             | A
| ------------- | ---
| Branch?       | 7.2
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Issues        | n/a
| License       | MIT

Just adds tests to WebhookController to prepare for possible changes in #58248.

Commits
-------

5bcd490 [Webhook] add WebhookController tests
@kbond kbond force-pushed the feat/webhook-bulk-request-parser branch from 130ae1b to dde7b45 Compare September 14, 2024 18:18
@kbond
Copy link
Member Author

kbond commented Sep 14, 2024

I've added tests, updated changelog and upgrade guide. If this minor BC Break is acceptable, I think this is good to go.

it seems like Sendgrid also batches webhooks but our parser silently ignore all events except the first one.

When/if merged, I'll fix the sendgrid bridge.

@kbond kbond force-pushed the feat/webhook-bulk-request-parser branch from dde7b45 to da9aafb Compare September 14, 2024 23:56
@fabpot
Copy link
Member

fabpot commented Sep 16, 2024

As we already have 3 bridges that would work correctly without this change, I would consider this BC break as something we need to fix in 7.2.

@kbond kbond removed the RFC RFC = Request For Comments (proposals about features that you want to be discussed) label Sep 16, 2024
Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

What about introducing a parseAll method?
RemoteEvent|array<RemoteEvent> is tricky to deal with I fear.

@stof
Copy link
Member

stof commented Sep 16, 2024

Adding a new method will be a BC break for all implementations . And right now, we have dozens of implementation, all in external packages (either in bridge components or third-party) while we have only 1 known caller in the webhook component itself (and so no impacted by a BC break as its update is shipped in the same package).

@kbond kbond force-pushed the feat/webhook-bulk-request-parser branch from da9aafb to 42fec2e Compare September 16, 2024 15:23
@nicolas-grekas
Copy link
Member

With an @method of course.

@nicolas-grekas
Copy link
Member

nicolas-grekas commented Sep 16, 2024

Or a new interface / abstract class.

@stof
Copy link
Member

stof commented Sep 16, 2024

but that would still force bridges to implement the parse method returning a single one (and so being broken for batched webhooks)

@mahono
Copy link

mahono commented Sep 17, 2024

Just for curiosity: does this somehow allow streaming events to a webhook?

@kbond
Copy link
Member Author

kbond commented Sep 17, 2024

Just for curiosity: does this somehow allow streaming events to a webhook?

No, just accounts for some webhook providers that send multiple events in a single request.

@kbond
Copy link
Member Author

kbond commented Sep 18, 2024

What about introducing a parseAll method?

I thought about this and then, in WebhookController, use parseAll when available and parse if not (trigger deprecation in this case). I ran into the same thing that @stof describes - a lot more 3rd party code that would need updating.

FYI, I did a search on packagist and couldn't find any open source code that consumes parsers.

@kbond kbond force-pushed the feat/webhook-bulk-request-parser branch from 35c4f77 to a1fcfae Compare September 27, 2024 08:15
@fabpot
Copy link
Member

fabpot commented Sep 27, 2024

Thank you @kbond.

@fabpot fabpot merged commit 0ff1704 into symfony:7.2 Sep 27, 2024
6 of 10 checks passed
fabpot added a commit that referenced this pull request Sep 27, 2024
This PR was merged into the 7.2 branch.

Discussion
----------

[Mailer][Webhook] Fix SendGrid Webhook parsing

| Q             | A
| ------------- | ---
| Branch?       | 7.2
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Issues        | Fix #58398
| License       | MIT

Sendgrid sends multiple webhook events in a single request. Previously, only the first was parsed and the rest were silently ignored. This fix parses them all, but is only available on 7.2 because #58248 is required.

Commits
-------

9ae908e [Mailer] enable Sendgrid to parse multiple events
@fabpot fabpot mentioned this pull request Oct 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants