From 73a2aa0c008bcb9ca62a68151b3b1f2e5540fd1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E0=A4=95=E0=A4=BE=E0=A4=B0=E0=A4=A4=E0=A5=8B=E0=A4=AB?= =?UTF-8?q?=E0=A5=8D=E0=A4=AB=E0=A5=87=E0=A4=B2=E0=A4=B8=E0=A5=8D=E0=A4=95?= =?UTF-8?q?=E0=A5=8D=E0=A4=B0=E0=A4=BF=E0=A4=AA=E0=A5=8D=E0=A4=9F=E2=84=A2?= Date: Fri, 13 Dec 2024 16:07:32 +0100 Subject: [PATCH] feat(core): Add `is_docker` info to telemetry payload on `server-started` (no-changelog) (#12187) --- .../__tests__/telemetry-event-relay.test.ts | 42 ++++++++++++++++--- .../events/relays/telemetry.event-relay.ts | 3 ++ 2 files changed, 40 insertions(+), 5 deletions(-) diff --git a/packages/cli/src/events/__tests__/telemetry-event-relay.test.ts b/packages/cli/src/events/__tests__/telemetry-event-relay.test.ts index 58d694e556..4448dbc41e 100644 --- a/packages/cli/src/events/__tests__/telemetry-event-relay.test.ts +++ b/packages/cli/src/events/__tests__/telemetry-event-relay.test.ts @@ -1,5 +1,6 @@ import type { GlobalConfig } from '@n8n/config'; import { mock } from 'jest-mock-extended'; +import { InstanceSettings } from 'n8n-core'; import type { IWorkflowBase } from 'n8n-workflow'; import { N8N_VERSION } from '@/constants'; @@ -14,6 +15,7 @@ import type { IWorkflowDb } from '@/interfaces'; import type { License } from '@/license'; import type { NodeTypes } from '@/node-types'; import type { Telemetry } from '@/telemetry'; +import { mockInstance } from '@test/mocking'; const flushPromises = async () => await new Promise((resolve) => setImmediate(resolve)); @@ -41,6 +43,7 @@ describe('TelemetryEventRelay', () => { outputs: ['console'], }, }); + const instanceSettings = mockInstance(InstanceSettings, { isDocker: false, n8nFolder: '/test' }); const workflowRepository = mock(); const nodeTypes = mock(); const sharedWorkflowRepository = mock(); @@ -55,6 +58,7 @@ describe('TelemetryEventRelay', () => { telemetry, license, globalConfig, + instanceSettings, workflowRepository, nodeTypes, sharedWorkflowRepository, @@ -65,11 +69,8 @@ describe('TelemetryEventRelay', () => { }); beforeEach(() => { - globalConfig.diagnostics.enabled = true; - }); - - afterEach(() => { jest.clearAllMocks(); + globalConfig.diagnostics.enabled = true; }); describe('init', () => { @@ -80,6 +81,7 @@ describe('TelemetryEventRelay', () => { telemetry, license, globalConfig, + instanceSettings, workflowRepository, nodeTypes, sharedWorkflowRepository, @@ -101,6 +103,7 @@ describe('TelemetryEventRelay', () => { telemetry, license, globalConfig, + instanceSettings, workflowRepository, nodeTypes, sharedWorkflowRepository, @@ -942,7 +945,36 @@ describe('TelemetryEventRelay', () => { await flushPromises(); - // expect(telemetry.identify).toHaveBeenCalled(); + expect(telemetry.identify).toHaveBeenCalledWith( + expect.objectContaining({ + version_cli: N8N_VERSION, + metrics: { + metrics_category_cache: false, + metrics_category_default: true, + metrics_category_logs: false, + metrics_category_queue: false, + metrics_category_routes: false, + metrics_enabled: true, + }, + n8n_binary_data_mode: 'default', + n8n_deployment_type: 'default', + saml_enabled: false, + smtp_set_up: true, + system_info: { + is_docker: false, + cpus: expect.objectContaining({ + count: expect.any(Number), + model: expect.any(String), + speed: expect.any(Number), + }), + memory: expect.any(Number), + os: expect.objectContaining({ + type: expect.any(String), + version: expect.any(String), + }), + }, + }), + ); expect(telemetry.track).toHaveBeenCalledWith( 'Instance started', expect.objectContaining({ diff --git a/packages/cli/src/events/relays/telemetry.event-relay.ts b/packages/cli/src/events/relays/telemetry.event-relay.ts index 0a352087e5..a34646f100 100644 --- a/packages/cli/src/events/relays/telemetry.event-relay.ts +++ b/packages/cli/src/events/relays/telemetry.event-relay.ts @@ -1,5 +1,6 @@ import { GlobalConfig } from '@n8n/config'; import { snakeCase } from 'change-case'; +import { InstanceSettings } from 'n8n-core'; import type { ExecutionStatus, INodesGraphResult, ITelemetryTrackProperties } from 'n8n-workflow'; import { TelemetryHelpers } from 'n8n-workflow'; import os from 'node:os'; @@ -28,6 +29,7 @@ export class TelemetryEventRelay extends EventRelay { private readonly telemetry: Telemetry, private readonly license: License, private readonly globalConfig: GlobalConfig, + private readonly instanceSettings: InstanceSettings, private readonly workflowRepository: WorkflowRepository, private readonly nodeTypes: NodeTypes, private readonly sharedWorkflowRepository: SharedWorkflowRepository, @@ -760,6 +762,7 @@ export class TelemetryEventRelay extends EventRelay { model: cpus[0].model, speed: cpus[0].speed, }, + is_docker: this.instanceSettings.isDocker, }, execution_variables: { executions_mode: config.getEnv('executions.mode'),