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): Move Logger to core (no-changelog) #12310

Merged
merged 8 commits into from
Dec 23, 2024
Merged

Conversation

netroy
Copy link
Member

@netroy netroy commented Dec 19, 2024

Summary

This PR moved the Logger to n8n-core, so that we can stop using console.* and Loggerproxy in more places.

Review / Merge checklist

  • PR title and summary are descriptive. (conventions)
  • Docs updated or follow-up ticket created.
  • Tests included.
  • PR Labeled with release/backport (if the PR is an urgent fix that needs to be backported)

@n8n-assistant n8n-assistant bot added core Enhancement outside /nodes-base and /editor-ui n8n team Authored by the n8n team labels Dec 19, 2024
@netroy netroy requested a review from ivov December 19, 2024 14:56
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.

Thanks for taking this on! Code looks good, will give it a spin soon!

PS: I think we can omit (no-changelog) for refactor PRs

packages/cli/src/config/index.ts Outdated Show resolved Hide resolved
packages/core/src/InstanceSettingsConfig.ts Outdated Show resolved Hide resolved
if (!this.isScopingEnabled) return info;

const { scopes } = info.metadata;
const { scopes } = (info as unknown as { metadata: LogMetadata }).metadata;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this better than the original?

Copy link
Member Author

Choose a reason for hiding this comment

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

not sure why, but I'm getting this error
image

Copy link
Contributor

Choose a reason for hiding this comment

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

So confused, this should've been erroring out in cli then? Also the TransformableInfo type is left open [key: string | symbol]: any; so worst case we shouldn't need the unknown intermediary or? info.metadata as LogMetadata

packages/core/src/utils.ts Outdated Show resolved Hide resolved
Comment on lines +2394 to +2404
export type LogMetadata = {
[key: string]: unknown;
scopes?: LogScope[];
file?: string;
function?: string;
};
export type Logger = Record<
Exclude<LogLevel, 'silent'>,
(message: string, metadata?: LogMetadata) => void
>;
export type LogLocationMetadata = Pick<LogMetadata, 'file' | 'function'>;
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. Instead of picking from LogMetadata I wonder if it'd be more readable to define LogLocationMetadata as those two properties and intersect this type to create LogMetadata?
  2. I'm not clear just from this what Logger is here as opposed to the Logger service. The proxy? Maybe we can docline this?

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 just copied this code over. I think we can refactor this bit in the next step when we get rid of more of the LoggerProxy code.

@netroy netroy requested a review from ivov December 19, 2024 16:29
if (!this.isScopingEnabled) return info;

const { scopes } = info.metadata;
const { scopes } = (info as unknown as { metadata: LogMetadata }).metadata;
Copy link
Contributor

Choose a reason for hiding this comment

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

So confused, this should've been erroring out in cli then? Also the TransformableInfo type is left open [key: string | symbol]: any; so worst case we shouldn't need the unknown intermediary or? info.metadata as LogMetadata

Copy link
Contributor

Choose a reason for hiding this comment

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

Why remove the .service. infix?

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 prefer the file name and the DI class names to align. I can add the .service back, but then I prefer to rename the class to LoggerService. Would that be acceptable?

Copy link
Contributor

@ivov ivov Dec 20, 2024

Choose a reason for hiding this comment

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

Turning all the logger references to loggerService makes the code everywhere more verbose for little gain. Do we need to be so consistent? I always thought of the -Service suffix as an easy way to name classes that otherwise would be hard to name like WorklowService but that doesn't really apply for the logger.

If the alternative is making all code more verbose, I'd rather omit the .service. infix here. But I also notice that this is also inconsistent in that we're having some DI services infixed and some not.

Copy link
Member Author

Choose a reason for hiding this comment

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

we don't need to rename all variables. I just meant the class. So the only change would be change the class name in this file to LoggerService, and renaming the file back to logger.service.ts.
however I personally the Service suffix in this particular case not very useful.

Copy link
Contributor

Choose a reason for hiding this comment

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

however I personally the Service suffix in this particular case not very useful.

Agree! In any case if this renaming won't cause lots of changes everywhere, I'd be happy with what you decide.

packages/core/src/utils.ts Outdated Show resolved Hide resolved
@netroy netroy requested a review from a team as a code owner December 20, 2024 15:11
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.

Changes look good. There are some failing tests, likely needs merging master.

@netroy netroy requested a review from ivov December 23, 2024 09:49
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.

Workflow tests seem to be failing for other PRs so I expect they're unrelated: https://github.com/n8n-io/n8n/actions/runs/12432707679/job/34712821182

Copy link
Contributor

⚠️ Some Cypress E2E specs are failing, please fix them before merging

Copy link

cypress bot commented Dec 23, 2024

n8n    Run #8464

Run Properties:  status check failed Failed #8464  •  git commit 471d7b9420: 🌳 master 🖥️ browsers:node18.12.0-chrome107 🤖 PR User 🗃️ e2e/*
Project n8n
Branch Review master
Run status status check failed Failed #8464
Run duration 04m 14s
Commit git commit 471d7b9420: 🌳 master 🖥️ browsers:node18.12.0-chrome107 🤖 PR User 🗃️ e2e/*
Committer कारतोफ्फेलस्क्रिप्ट™
View all properties for this run ↗︎

Test results
Tests that failed  Failures 1
Tests that were flaky  Flaky 2
Tests that did not run due to a developer annotating a test with .skip  Pending 0
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 276
View all changes introduced in this branch ↗︎

Tests for review

Failed  14-mapping.cy.ts • 1 failed test

View Output Video

Test Artifacts
Data mapping > maps expressions from json view Test Replay Screenshots Video
Failed  45-workflow-selector-parameter.cy.ts • 0 failed tests

View Output

Test Artifacts
Failed  20-workflow-executions.cy.ts • 0 failed tests

View Output

Test Artifacts
Failed  30-editor-after-route-changes.cy.ts • 0 failed tests

View Output

Test Artifacts
Failed  48-subworkflow-inputs.cy.ts • 0 failed tests

View Output

Test Artifacts

The first 5 failed specs are shown, see all 52 specs in Cypress Cloud.

Flakiness  45-ai-assistant.cy.ts • 1 flaky test

View Output Video

Test Artifacts
AI Assistant::enabled > should resize assistant chat down Test Replay Screenshots Video
Flakiness  19-execution.cy.ts • 1 flaky test

View Output Video

Test Artifacts
Execution > connections should be colored differently for pinned data > when executing a node Test Replay Screenshots Video

Copy link
Contributor

✅ All Cypress E2E specs passed

@netroy netroy merged commit 471d7b9 into master Dec 23, 2024
43 of 44 checks passed
@netroy netroy deleted the move-logger-to-core branch December 23, 2024 12:46
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