fix(core): Do not track errored workflow executions for automated executions (no-changelog) (#6322)

* fix(core): Do not track errored workflow executions for automated executions

* fix test

* fix test

* fix test

* do not track 'Workflow execution count' event when all counts are 0

* fix test

* fix test

* fix test

* fix test

* fix test

* fix test

* fix test

* fix test

* fix test
This commit is contained in:
Cornelius Suermann 2023-05-28 12:08:46 +02:00 committed by GitHub
parent d94c20ada5
commit 0e4c615d0d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 16 deletions

View file

@ -79,19 +79,29 @@ export class Telemetry {
return;
}
const allPromises = Object.keys(this.executionCountsBuffer).map(async (workflowId) => {
const promise = this.track(
'Workflow execution count',
{
event_version: '2',
workflow_id: workflowId,
...this.executionCountsBuffer[workflowId],
},
{ withPostHog: true },
);
const allPromises = Object.keys(this.executionCountsBuffer)
.filter((workflowId) => {
const data = this.executionCountsBuffer[workflowId];
const sum =
(data.manual_error?.count ?? 0) +
(data.manual_success?.count ?? 0) +
(data.prod_error?.count ?? 0) +
(data.prod_success?.count ?? 0);
return sum > 0;
})
.map(async (workflowId) => {
const promise = this.track(
'Workflow execution count',
{
event_version: '2',
workflow_id: workflowId,
...this.executionCountsBuffer[workflowId],
},
{ withPostHog: true },
);
return promise;
});
return promise;
});
this.executionCountsBuffer = {};
@ -128,7 +138,11 @@ export class Telemetry {
this.executionCountsBuffer[workflowId][key]!.count++;
}
if (!properties.success && properties.error_node_type?.startsWith('n8n-nodes-base')) {
if (
!properties.success &&
properties.is_manual &&
properties.error_node_type?.startsWith('n8n-nodes-base')
) {
void this.track('Workflow execution errored', properties);
}
}

View file

@ -211,7 +211,6 @@ describe('Telemetry', () => {
await telemetry.trackWorkflowExecution(payload);
expect(spyTrack).toHaveBeenCalledTimes(0);
execBuffer = telemetry.getCountsBuffer();
expect(execBuffer['1'].manual_error).toBeUndefined();
@ -254,19 +253,20 @@ describe('Telemetry', () => {
// failed execution n8n node
payload.success = false;
payload.error_node_type = 'n8n-nodes-base.merge';
payload.is_manual = true;
await telemetry.trackWorkflowExecution(payload);
expect(spyTrack).toHaveBeenCalledTimes(1);
execBuffer = telemetry.getCountsBuffer();
expect(execBuffer['1'].manual_error).toBeUndefined();
expect(execBuffer['1'].manual_error?.count).toBe(1);
expect(execBuffer['1'].manual_success).toBeUndefined();
expect(execBuffer['2'].manual_error).toBeUndefined();
expect(execBuffer['2'].manual_success).toBeUndefined();
expect(execBuffer['2'].prod_error).toBeUndefined();
expect(execBuffer['1'].prod_success?.count).toBe(2);
expect(execBuffer['1'].prod_error?.count).toBe(2);
expect(execBuffer['1'].prod_error?.count).toBe(1);
expect(execBuffer['2'].prod_success?.count).toBe(2);
expect(execBuffer['1'].prod_error?.first).toEqual(execTime2);