Skip to content
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

refactor(core): Bifurcate handling of webhooks vs. triggers and pollers (no-changelog) #8494

Conversation

ivov
Copy link
Contributor

@ivov ivov commented Jan 30, 2024

As our understanding of multi-main setup continues to evolve, this PR again refactors all flows to match what we currently think is the best approach.

  • Changes to init flows: On init, only the leader should add triggers and pollers. On init, neither leader nor follower should add webhooks, in line with skipping webhook deregistration on shutdown. No changes to leadershipChange init.
  • Changes to update flows: On update, the main that received the workflow update request, whether leader or follower, should add or remove webhooks, and send a message for the leader to add or remove triggers and pollers. The prior approach of having only the leader remove webhooks fails to deregister webhooks in cases where e.g. we replace an active webhook with an active trigger without deactivation. Note that in this setup a main should be able to message itself, as opposed to before where only followers could message the leader.
  • Changes to event handlers: On leader-stepdown (former leader realizes they lost leadership), the former leader should remove all triggers and pollers for all workflows and stop pruning. On leader-takeover (follower became leader), the new leader should add all triggers and pollers for all workflows and start pruning. These events used to be leadershipVacant and leadershipChange with slightly different effects.

Notes:

  • Switched some logs to warn to make them easier to scan while debugging. Will revert these before merging.
  • Passing versionId to every message when adding webhooks, triggers and pollers increases complexity in the already complex add and remove operations. versionId is only needed in case we need to deactivate a workflow that failed to activate in the leader in reaction to a message. Is it safe to deactivate on failure without referencing the versionId?
  • Tore down all obsolete tests from the prior approach, as they are no longer relevant to this setup. Coming up with a testing approach that accounts for this new setup is more time-consuming than the time available skipping this for now. Did some basic testing - will test all variants listed in the battery of manual tests after review, as discussed. Let me know otherwise.

@n8n-assistant n8n-assistant bot added core Enhancement outside /nodes-base and /editor-ui n8n team Authored by the n8n team labels Jan 30, 2024
@ivov ivov marked this pull request as ready for review January 30, 2024 15:16
@@ -388,7 +389,7 @@ export class ActiveWorkflowRunner {
responsePromise?: IDeferredPromise<IExecuteResponsePromiseData>,
donePromise?: IDeferredPromise<IRun | undefined>,
): void => {
this.logger.debug(`Received trigger for workflow "${workflow.name}"`);
this.logger.warn(`Received trigger for workflow "${workflow.name}"`);
Copy link
Contributor

Choose a reason for hiding this comment

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

This change will make the logs quite verbose IMO

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Did this on purpose - this highlighting makes finding relevant logs while testing much easier. They're only temporary, see above:

Switched some logs to warn to make them easier to scan while debugging. Will revert these before merging.

/**
* Stop running active triggers and pollers for a workflow.
*/
async removeWorkflowTriggersAndPollers(workflowId: string) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we can deduplicate the remove function above to use this function as well wdyt?

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks so much nicer now :D

Copy link
Contributor

✅ All Cypress E2E specs passed

Copy link

cypress bot commented Jan 31, 2024

3 flaky tests on run #3973 ↗︎

0 338 5 0 Flakiness 3

Details:

🌳 🖥️ browsers:node18.12.0-chrome107 🤖 ivov 🗃️ e2e/*
Project: n8n Commit: 616976f29a
Status: Passed Duration: 03:29 💡
Started: Jan 31, 2024 1:05 PM Ended: Jan 31, 2024 1:08 PM
Flakiness  5-ndv.cy.ts • 1 flaky test

View Output Video

Test Artifacts
NDV > should not retrieve remote options when required params throw errors Test Replay Screenshots Video
Flakiness  24-ndv-paired-item.cy.ts • 1 flaky test

View Output Video

Test Artifacts
NDV > resolves expression with default item when input node is not parent, while still pairing items Test Replay Screenshots Video
Flakiness  28-debug.cy.ts • 1 flaky test

View Output Video

Test Artifacts
Debug > should be able to debug executions Test Replay Screenshots Video

Review all test suite changes for PR #8494 ↗︎

@ivov ivov merged commit 8fcca43 into simplify-flows-in-multi-main-mode Jan 31, 2024
30 checks passed
@ivov ivov deleted the bifurcate-handling-of-webhooks-vs-triggers-and-pollers-in-multi-main-mode branch January 31, 2024 13:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Enhancement outside /nodes-base and /editor-ui n8n team Authored by the n8n team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants