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): Refactor nodes loading (no-changelog) #7283

Merged
merged 14 commits into from Oct 9, 2023

Conversation

netroy
Copy link
Member

@netroy netroy commented Sep 27, 2023

This also fixes PAY-605

@github-actions
Copy link
Contributor

Great PR! Please pay attention to the following items before merging:

Files matching packages/**:

  • If fixing bug, added test to cover scenario.
  • If addressing forum or Github issue, added link to description.

Files matching packages/**/*.ts:

  • Added unit tests to cover new or updated functionality.

Make sure to check off this list before asking for review.

@n8n-assistant n8n-assistant bot added core Enhancement outside /nodes-base and /editor-ui n8n team Authored by the n8n team ui Enhancement in /editor-ui or /design-system labels Sep 27, 2023
Copy link
Contributor

@ivov ivov left a comment

Choose a reason for hiding this comment

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

Tested manually, still working, only minor comments.

@@ -571,9 +570,11 @@ export class Server extends AbstractServer {
}

if (config.getEnv('nodes.communityPackages.enabled')) {
controllers.push(
new NodesController(config, this.loadNodesAndCredentials, this.push, internalHooks),
// eslint-disable-next-line @typescript-eslint/naming-convention
Copy link
Contributor

Choose a reason for hiding this comment

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

Now or later, maybe it's time to relax or remove this rule. Every dynamically loaded class will trigger it.

@netroy netroy requested a review from ivov September 29, 2023 15:25
@codecov
Copy link

codecov bot commented Sep 29, 2023

Codecov Report

Attention: 161 lines in your changes are missing coverage. Please review.

Comparison is base (789e1e7) 33.46% compared to head (5a59e1f) 33.41%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7283      +/-   ##
==========================================
- Coverage   33.46%   33.41%   -0.05%     
==========================================
  Files        3389     3389              
  Lines      206599   206610      +11     
  Branches    22288    22284       -4     
==========================================
- Hits        69143    69049      -94     
- Misses     136337   136444     +107     
+ Partials     1119     1117       -2     
Files Coverage Δ
packages/cli/src/CredentialsOverwrites.ts 28.84% <100.00%> (-0.25%) ⬇️
packages/cli/src/WorkflowRunnerProcess.ts 0.00% <ø> (ø)
packages/cli/src/commands/BaseCommand.ts 31.91% <100.00%> (-2.78%) ⬇️
packages/cli/src/config/schema.ts 81.81% <ø> (ø)
packages/cli/src/controllers/index.ts 100.00% <ø> (ø)
packages/workflow/src/Interfaces.ts 77.77% <ø> (ø)
packages/cli/src/CredentialsHelper.ts 23.45% <75.00%> (-0.34%) ⬇️
packages/cli/src/NodeTypes.ts 31.37% <75.00%> (-5.47%) ⬇️
packages/cli/src/audit/risks/nodes.risk.ts 82.05% <80.00%> (-1.74%) ⬇️
packages/cli/src/commands/worker.ts 26.72% <0.00%> (ø)
... and 8 more

... and 5 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@netroy netroy changed the title refactor(core): Refactor community-packages endpoints (no-changelog) refactor(core): Refactor nodes loading (no-changelog) Sep 29, 2023
@@ -50,20 +40,20 @@ export class LoadNodesAndCredentials implements INodesAndCredentials {

includeNodes = config.getEnv('nodes.include');

credentialTypes: ICredentialTypes;
Copy link
Member Author

Choose a reason for hiding this comment

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

this dependency tree was too messy. by moving code out into CommunityPackagesService and FrontendService, this class is a lot more leaner, and there are fewer cyclic dependencies now.
Also, the code that got moved out isn't loaded in webhook and worker services anymore.

import { LoadNodesAndCredentials } from '@/LoadNodesAndCredentials';

@Service()
export class FrontendService {
Copy link
Member Author

Choose a reason for hiding this comment

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

will move all fronted-settings out of Server.ts and into this class in a separate PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

I can take this over as well if you like.

packages/cli/src/NodeTypes.ts Outdated Show resolved Hide resolved
packages/cli/src/Server.ts Outdated Show resolved Hide resolved
packages/cli/src/services/communityPackages.service.ts Outdated Show resolved Hide resolved
packages/cli/src/NodeTypes.ts Outdated Show resolved Hide resolved
packages/cli/src/services/frontend.service.ts Outdated Show resolved Hide resolved

LoggerProxy.init(getLogger());
LoggerProxy.init(mock<ILogger>());
Copy link
Contributor

Choose a reason for hiding this comment

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

I love this, we should be mocking the logger more often.

Copy link
Member Author

Choose a reason for hiding this comment

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

I have a branch to convert Logger into a service, and mock that everywhere. no more LoggerProxy in the cli package.


class CredentialsOverwritesClass {
@Service()
export class CredentialsOverwrites {
Copy link
Contributor

Choose a reason for hiding this comment

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

For understanding: What's the difference between the overwrites that happen in CredentialsOverwrites vs. the overwrites that happen in the FrontendService? Why do we need both and for them to be separate?

Copy link
Member Author

Choose a reason for hiding this comment

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

The overwrites in FrontendService are only used in the frontend, and that code should not run on worker or webhooks. That said, we could still move that code into a method on CredentialsOverwrites, if that looks cleaner.
let me know.

Copy link
Contributor

Choose a reason for hiding this comment

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

Skimming through them they look very similar and with no context or method documentation I do not find the difference clear. Running low on time so I'll leave this be for now.


await writeStaticJSON('nodes', this.types.nodes);
await writeStaticJSON('credentials', this.types.credentials);
addPostProcessor(fn: () => Promise<void>) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I take it we went for this to avoid adding more dependencies.

There are only two post-processors for now, but over time I worry it can become rather hard to keep track of what's getting added and later called when and in what order.

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah. I couldn't come up with a better way to decouple this processing pipeline. This works for now, but I'm very much open to suggestions.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'll keep thinking if there's another way but let's not block on this.

packages/cli/src/Server.ts Outdated Show resolved Hide resolved
@netroy netroy requested a review from ivov October 6, 2023 16:02
Copy link
Contributor

@ivov ivov left a comment

Choose a reason for hiding this comment

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

I'll come back to test manually: community nodes, hot reload, overwrites, etc.

Edit: Tested, all fine

packages/cli/package.json Show resolved Hide resolved
return filePath;
}
}
return undefined;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return undefined;

Copy link
Member Author

Choose a reason for hiding this comment

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

removing this makes eslint complain about

Not all code paths return a value

Comment on lines +372 to +374
this.frontendService.generateTypes(),
);
await this.frontendService.generateTypes();
Copy link
Contributor

Choose a reason for hiding this comment

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

So we have to both register and call generateTypes because LoadNodesAndCredentials.init() was already called during startup at BaseCommand but without this postprocessor? So we registering this postprocessor only for cases where we reload as in with community packages or hot reload?

Copy link
Member Author

Choose a reason for hiding this comment

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

unfortunately yes. but that also makes sense as LoadNodesAndCredentials.init is called in webhook and worker services as well. It would have been cool to be able to defer postProcessLoaders somehow, but everything I tried so far made this code even more twisted.
I'd definitely like to simplify this, but I'm out of ideas for now.

Comment on lines -815 to -826
packagesMissing: {
// Used to have a persistent list of packages
doc: 'Contains a comma separated list of packages that failed to load during startup',
format: String,
default: '',
},
Copy link
Contributor

Choose a reason for hiding this comment

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

@krynble Is this fine to remove? Or was there a reason this needed to be an env in the first place?

Copy link
Member Author

Choose a reason for hiding this comment

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

there was never an env variable for this. and this should never have been a config variable either. looking at the code where this was originally added, it looks like we needed a central place to store this string while the application was running, because the code using this flag was scattered across multiple files.
now, this info is centralized in the CommunityPackagesService.

packages/cli/src/services/frontend.service.ts Outdated Show resolved Hide resolved
@netroy netroy requested a review from ivov October 9, 2023 13:00
@cypress
Copy link

cypress bot commented Oct 9, 2023

Passing run #2436 ↗︎

0 250 0 0 Flakiness 0

Details:

🌳 refactor-community-endpoints 🖥️ browsers:node18.12.0-chrome107 🤖 netroy 🗃️...
Project: n8n Commit: 5a59e1fefe
Status: Passed Duration: 09:11 💡
Started: Oct 9, 2023 1:59 PM Ended: Oct 9, 2023 2:08 PM

Review all test suite changes for PR #7283 ↗︎

@github-actions
Copy link
Contributor

github-actions bot commented Oct 9, 2023

✅ All Cypress E2E specs passed

@netroy netroy merged commit c5ee06c into master Oct 9, 2023
55 checks passed
@netroy netroy deleted the refactor-community-endpoints branch October 9, 2023 14:09
MiloradFilipovic added a commit that referenced this pull request Oct 10, 2023
* master: (42 commits)
  fix(editor): Make workflow history button available only for dev builds (#7392)
  refactor: Upgrade to pnpm 8.9 (no-changelog) (#7393)
  ci: Identify NPM releases as `stable` (no-changelog)
  fix(editor): Implement canvas zoom UX improvements (#7376)
  feat(core): Switch binary filesystem mode to nested path structure (#7307)
  fix(editor): Fix completions for `.json` on quoted node name in Code node (#7382)
  fix(Notion Node): Handle empty values correctly for Notion selects + multi selects (#7383)
  feat(editor): Make PDF and Audio binary-data viewable in the UI (#7367)
  fix(Google Sheets Node): Fix "Maximum call stack size exceeded" error on too many rows (#7384)
  refactor(core): Refactor nodes loading (no-changelog) (#7283)
  fix(core): Add an option to enable postgres ssl with default certs (#6889)
  feat(editor): Workflow history [WIP]- Add restore and clone into new workflow actions (no-changelog) (#7359)
  fix(HTML Node): Update property fields to not use expressions on drag (#7379)
  fix: Add role check for upgrade path (#7374)
  fix(editor): Remove excess margin below run data editor (#7372)
  fix(Google Drive Trigger Node): Add Shared Drives support (#7369)
  feat(core): Add Job Summary to Worker response (#7360)
  feat(Execute Workflow Node): Run once for each item mode (#7289)
  refactor(core): Move `copyInputItems` to node helpers (no-changelog) (#7299)
  refactor(core): Create controller for binary data (no-changelog) (#7363)
  ...

# Conflicts:
#	cypress/e2e/5-ndv.cy.ts
@janober
Copy link
Member

janober commented Oct 11, 2023

Got released with n8n@1.11.0

ivov added a commit that referenced this pull request Oct 11, 2023
elsmr pushed a commit that referenced this pull request Oct 19, 2023
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 Released ui Enhancement in /editor-ui or /design-system
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants