-
Notifications
You must be signed in to change notification settings - Fork 9.1k
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): Decouple workflow created, saved, deleted events from internal hooks (no-changelog) #10264
Merged
ivov
merged 1 commit into
master
from
decouple-workflow-created-saved-deleted-events-from-internal-hooks
Aug 1, 2024
Merged
refactor(core): Decouple workflow created, saved, deleted events from internal hooks (no-changelog) #10264
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,10 @@ import { License } from '@/License'; | |
import { GlobalConfig } from '@n8n/config'; | ||
import { N8N_VERSION } from '@/constants'; | ||
import { WorkflowRepository } from '@/databases/repositories/workflow.repository'; | ||
import { TelemetryHelpers } from 'n8n-workflow'; | ||
import { NodeTypes } from '@/NodeTypes'; | ||
import { SharedWorkflowRepository } from '@/databases/repositories/sharedWorkflow.repository'; | ||
import { ProjectRelationRepository } from '@/databases/repositories/projectRelation.repository'; | ||
|
||
@Service() | ||
export class TelemetryEventRelay { | ||
|
@@ -17,6 +21,9 @@ export class TelemetryEventRelay { | |
private readonly license: License, | ||
private readonly globalConfig: GlobalConfig, | ||
private readonly workflowRepository: WorkflowRepository, | ||
private readonly nodeTypes: NodeTypes, | ||
private readonly sharedWorkflowRepository: SharedWorkflowRepository, | ||
private readonly projectRelationRepository: ProjectRelationRepository, | ||
) {} | ||
|
||
async init() { | ||
|
@@ -101,6 +108,16 @@ export class TelemetryEventRelay { | |
this.eventService.on('login-failed-due-to-ldap-disabled', (event) => { | ||
this.loginFailedDueToLdapDisabled(event); | ||
}); | ||
|
||
this.eventService.on('workflow-created', (event) => { | ||
this.workflowCreated(event); | ||
}); | ||
this.eventService.on('workflow-deleted', (event) => { | ||
this.workflowDeleted(event); | ||
}); | ||
this.eventService.on('workflow-saved', async (event) => { | ||
await this.workflowSaved(event); | ||
}); | ||
} | ||
|
||
private teamProjectUpdated({ userId, role, members, projectId }: Event['team-project-updated']) { | ||
|
@@ -431,6 +448,79 @@ export class TelemetryEventRelay { | |
this.telemetry.track('User login failed since ldap disabled', { user_ud: userId }); | ||
} | ||
|
||
private workflowCreated({ | ||
user, | ||
workflow, | ||
publicApi, | ||
projectId, | ||
projectType, | ||
}: Event['workflow-created']) { | ||
const { nodeGraph } = TelemetryHelpers.generateNodesGraph(workflow, this.nodeTypes); | ||
|
||
this.telemetry.track('User created workflow', { | ||
user_id: user.id, | ||
workflow_id: workflow.id, | ||
node_graph_string: JSON.stringify(nodeGraph), | ||
public_api: publicApi, | ||
project_id: projectId, | ||
project_type: projectType, | ||
}); | ||
} | ||
|
||
private workflowDeleted({ user, workflowId, publicApi }: Event['workflow-deleted']) { | ||
this.telemetry.track('User deleted workflow', { | ||
user_id: user.id, | ||
workflow_id: workflowId, | ||
public_api: publicApi, | ||
}); | ||
} | ||
|
||
private async workflowSaved({ user, workflow, publicApi }: Event['workflow-saved']) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved content but otherwise untouched. |
||
const isCloudDeployment = config.getEnv('deployment.type') === 'cloud'; | ||
|
||
const { nodeGraph } = TelemetryHelpers.generateNodesGraph(workflow, this.nodeTypes, { | ||
isCloudDeployment, | ||
}); | ||
|
||
let userRole: 'owner' | 'sharee' | 'member' | undefined = undefined; | ||
const role = await this.sharedWorkflowRepository.findSharingRole(user.id, workflow.id); | ||
if (role) { | ||
userRole = role === 'workflow:owner' ? 'owner' : 'sharee'; | ||
} else { | ||
const workflowOwner = await this.sharedWorkflowRepository.getWorkflowOwningProject( | ||
workflow.id, | ||
); | ||
|
||
if (workflowOwner) { | ||
const projectRole = await this.projectRelationRepository.findProjectRole({ | ||
userId: user.id, | ||
projectId: workflowOwner.id, | ||
}); | ||
|
||
if (projectRole && projectRole !== 'project:personalOwner') { | ||
userRole = 'member'; | ||
} | ||
} | ||
} | ||
|
||
const notesCount = Object.keys(nodeGraph.notes).length; | ||
const overlappingCount = Object.values(nodeGraph.notes).filter( | ||
(note) => note.overlapping, | ||
).length; | ||
|
||
this.telemetry.track('User saved workflow', { | ||
user_id: user.id, | ||
workflow_id: workflow.id, | ||
node_graph_string: JSON.stringify(nodeGraph), | ||
notes_count_overlapping: overlappingCount, | ||
notes_count_non_overlapping: notesCount - overlappingCount, | ||
version_cli: N8N_VERSION, | ||
num_tags: workflow.tags?.length ?? 0, | ||
public_api: publicApi, | ||
sharing_role: userRole, | ||
}); | ||
} | ||
|
||
private async serverStarted() { | ||
const cpus = os.cpus(); | ||
const binaryDataConfig = config.getEnv('binaryDataManager'); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like we have Sentry's
OnUnhandledRejection
integration enabled, so having a dangling promise chain is not causing us any issues