Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/n8n-io/n8n into node-2022-…
Browse files Browse the repository at this point in the history
…community-issue-n8n-form-node-failure-when-completion
  • Loading branch information
michael-radency committed Nov 19, 2024
2 parents 7df0ca6 + 6cd9b99 commit f8cde6e
Show file tree
Hide file tree
Showing 45 changed files with 874 additions and 513 deletions.
8 changes: 8 additions & 0 deletions packages/@n8n/api-types/src/push/execution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ type ExecutionStarted = {
};
};

type ExecutionWaiting = {
type: 'executionWaiting';
data: {
executionId: string;
};
};

type ExecutionFinished = {
type: 'executionFinished';
data: {
Expand Down Expand Up @@ -45,6 +52,7 @@ type NodeExecuteAfter = {

export type ExecutionPushMessage =
| ExecutionStarted
| ExecutionWaiting
| ExecutionFinished
| ExecutionRecovered
| NodeExecuteBefore
Expand Down
30 changes: 30 additions & 0 deletions packages/@n8n/config/src/configs/diagnostics.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { Config, Env, Nested } from '../decorators';

@Config
class PostHogConfig {
/** API key for PostHog. */
@Env('N8N_DIAGNOSTICS_POSTHOG_API_KEY')
apiKey: string = 'phc_4URIAm1uYfJO7j8kWSe0J8lc8IqnstRLS7Jx8NcakHo';

/** API host for PostHog. */
@Env('N8N_DIAGNOSTICS_POSTHOG_API_HOST')
apiHost: string = 'https://ph.n8n.io';
}

@Config
export class DiagnosticsConfig {
/** Whether diagnostics are enabled. */
@Env('N8N_DIAGNOSTICS_ENABLED')
enabled: boolean = false;

/** Diagnostics config for frontend. */
@Env('N8N_DIAGNOSTICS_CONFIG_FRONTEND')
frontendConfig: string = '1zPn9bgWPzlQc0p8Gj1uiK6DOTn;https://telemetry.n8n.io';

/** Diagnostics config for backend. */
@Env('N8N_DIAGNOSTICS_CONFIG_BACKEND')
backendConfig: string = '1zPn7YoGC3ZXE9zLeTKLuQCB4F6;https://telemetry.n8n.io';

@Nested
posthogConfig: PostHogConfig;
}
4 changes: 4 additions & 0 deletions packages/@n8n/config/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { CacheConfig } from './configs/cache.config';
import { CredentialsConfig } from './configs/credentials.config';
import { DatabaseConfig } from './configs/database.config';
import { DiagnosticsConfig } from './configs/diagnostics.config';
import { EndpointsConfig } from './configs/endpoints.config';
import { EventBusConfig } from './configs/event-bus.config';
import { ExternalSecretsConfig } from './configs/external-secrets.config';
Expand Down Expand Up @@ -117,4 +118,7 @@ export class GlobalConfig {

@Nested
pruning: PruningConfig;

@Nested
diagnostics: DiagnosticsConfig;
}
9 changes: 9 additions & 0 deletions packages/@n8n/config/test/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,15 @@ describe('GlobalConfig', () => {
hardDeleteInterval: 15,
softDeleteInterval: 60,
},
diagnostics: {
enabled: false,
frontendConfig: '1zPn9bgWPzlQc0p8Gj1uiK6DOTn;https://telemetry.n8n.io',
backendConfig: '1zPn7YoGC3ZXE9zLeTKLuQCB4F6;https://telemetry.n8n.io',
posthogConfig: {
apiKey: 'phc_4URIAm1uYfJO7j8kWSe0J8lc8IqnstRLS7Jx8NcakHo',
apiHost: 'https://ph.n8n.io',
},
},
};

it('should use all default values when no env variables are defined', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,36 @@ export class EmbeddingsAzureOpenAi implements INodeType {
'Maximum amount of time a request is allowed to take in seconds. Set to -1 for no timeout.',
type: 'number',
},
{
displayName: 'Dimensions',
name: 'dimensions',
default: undefined,
description:
'The number of dimensions the resulting output embeddings should have. Only supported in text-embedding-3 and later models.',
type: 'options',
options: [
{
name: '256',
value: 256,
},
{
name: '512',
value: 512,
},
{
name: '1024',
value: 1024,
},
{
name: '1536',
value: 1536,
},
{
name: '3072',
value: 3072,
},
],
},
],
},
],
Expand All @@ -105,6 +135,7 @@ export class EmbeddingsAzureOpenAi implements INodeType {
batchSize?: number;
stripNewLines?: boolean;
timeout?: number;
dimensions?: number | undefined;
};

if (options.timeout === -1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,36 @@ export class EmbeddingsOpenAi implements INodeType {
type: 'collection',
default: {},
options: [
{
displayName: 'Dimensions',
name: 'dimensions',
default: undefined,
description:
'The number of dimensions the resulting output embeddings should have. Only supported in text-embedding-3 and later models.',
type: 'options',
options: [
{
name: '256',
value: 256,
},
{
name: '512',
value: 512,
},
{
name: '1024',
value: 1024,
},
{
name: '1536',
value: 1536,
},
{
name: '3072',
value: 3072,
},
],
},
{
displayName: 'Base URL',
name: 'baseURL',
Expand Down Expand Up @@ -179,6 +209,7 @@ export class EmbeddingsOpenAi implements INodeType {
batchSize?: number;
stripNewLines?: boolean;
timeout?: number;
dimensions?: number | undefined;
};

if (options.timeout === -1) {
Expand Down
37 changes: 0 additions & 37 deletions packages/cli/src/config/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,43 +296,6 @@ export const schema = {
},
},

diagnostics: {
enabled: {
doc: 'Whether diagnostic mode is enabled.',
format: Boolean,
default: true,
env: 'N8N_DIAGNOSTICS_ENABLED',
},
config: {
posthog: {
apiKey: {
doc: 'API key for PostHog',
format: String,
default: 'phc_4URIAm1uYfJO7j8kWSe0J8lc8IqnstRLS7Jx8NcakHo',
env: 'N8N_DIAGNOSTICS_POSTHOG_API_KEY',
},
apiHost: {
doc: 'API host for PostHog',
format: String,
default: 'https://ph.n8n.io',
env: 'N8N_DIAGNOSTICS_POSTHOG_API_HOST',
},
},
frontend: {
doc: 'Diagnostics config for frontend.',
format: String,
default: '1zPn9bgWPzlQc0p8Gj1uiK6DOTn;https://telemetry.n8n.io',
env: 'N8N_DIAGNOSTICS_CONFIG_FRONTEND',
},
backend: {
doc: 'Diagnostics config for backend.',
format: String,
default: '1zPn7YoGC3ZXE9zLeTKLuQCB4F6;https://telemetry.n8n.io',
env: 'N8N_DIAGNOSTICS_CONFIG_BACKEND',
},
},
},

defaultLocale: {
doc: 'Default locale for the UI',
format: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type { GlobalConfig } from '@n8n/config';
import { mock } from 'jest-mock-extended';
import type { IWorkflowBase } from 'n8n-workflow';

import config from '@/config';
import { N8N_VERSION } from '@/constants';
import type { WorkflowEntity } from '@/databases/entities/workflow-entity';
import type { ProjectRelationRepository } from '@/databases/repositories/project-relation.repository';
Expand Down Expand Up @@ -66,7 +65,7 @@ describe('TelemetryEventRelay', () => {
});

beforeEach(() => {
config.set('diagnostics.enabled', true);
globalConfig.diagnostics.enabled = true;
});

afterEach(() => {
Expand All @@ -75,7 +74,7 @@ describe('TelemetryEventRelay', () => {

describe('init', () => {
it('with diagnostics enabled, should init telemetry and register listeners', async () => {
config.set('diagnostics.enabled', true);
globalConfig.diagnostics.enabled = true;
const telemetryEventRelay = new TelemetryEventRelay(
eventService,
telemetry,
Expand All @@ -96,7 +95,7 @@ describe('TelemetryEventRelay', () => {
});

it('with diagnostics disabled, should neither init telemetry nor register listeners', async () => {
config.set('diagnostics.enabled', false);
globalConfig.diagnostics.enabled = false;
const telemetryEventRelay = new TelemetryEventRelay(
eventService,
telemetry,
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/events/relays/telemetry.event-relay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class TelemetryEventRelay extends EventRelay {
}

async init() {
if (!config.getEnv('diagnostics.enabled')) return;
if (!this.globalConfig.diagnostics.enabled) return;

await this.telemetry.init();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
deepCopy,
ErrorReporterProxy,
type IRunExecutionData,
type ITaskData,
Expand Down Expand Up @@ -87,37 +86,6 @@ test('should update execution when saving progress is enabled', async () => {
expect(reporterSpy).not.toHaveBeenCalled();
});

test('should update execution when saving progress is disabled, but waitTill is defined', async () => {
jest.spyOn(fnModule, 'toSaveSettings').mockReturnValue({
...commonSettings,
progress: false,
});

const reporterSpy = jest.spyOn(ErrorReporterProxy, 'error');

executionRepository.findSingleExecution.mockResolvedValue({} as IExecutionResponse);

const args = deepCopy(commonArgs);
args[4].waitTill = new Date();
await saveExecutionProgress(...args);

expect(executionRepository.updateExistingExecution).toHaveBeenCalledWith('some-execution-id', {
data: {
executionData: undefined,
resultData: {
lastNodeExecuted: 'My Node',
runData: {
'My Node': [{}],
},
},
startData: {},
},
status: 'running',
});

expect(reporterSpy).not.toHaveBeenCalled();
});

test('should report error on failure', async () => {
jest.spyOn(fnModule, 'toSaveSettings').mockReturnValue({
...commonSettings,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export async function saveExecutionProgress(
) {
const saveSettings = toSaveSettings(workflowData.settings);

if (!saveSettings.progress && !executionData.waitTill) return;
if (!saveSettings.progress) return;

const logger = Container.get(Logger);

Expand Down
28 changes: 14 additions & 14 deletions packages/cli/src/execution-lifecycle-hooks/to-save-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@ export function toSaveSettings(workflowSettings: IWorkflowSettings = {}) {
PROGRESS: config.getEnv('executions.saveExecutionProgress'),
};

const {
saveDataErrorExecution = DEFAULTS.ERROR,
saveDataSuccessExecution = DEFAULTS.SUCCESS,
saveManualExecutions = DEFAULTS.MANUAL,
saveExecutionProgress = DEFAULTS.PROGRESS,
} = workflowSettings;

return {
error: workflowSettings.saveDataErrorExecution
? workflowSettings.saveDataErrorExecution !== 'none'
: DEFAULTS.ERROR !== 'none',
success: workflowSettings.saveDataSuccessExecution
? workflowSettings.saveDataSuccessExecution !== 'none'
: DEFAULTS.SUCCESS !== 'none',
manual:
workflowSettings === undefined || workflowSettings.saveManualExecutions === 'DEFAULT'
? DEFAULTS.MANUAL
: (workflowSettings.saveManualExecutions ?? DEFAULTS.MANUAL),
progress:
workflowSettings === undefined || workflowSettings.saveExecutionProgress === 'DEFAULT'
? DEFAULTS.PROGRESS
: (workflowSettings.saveExecutionProgress ?? DEFAULTS.PROGRESS),
error: saveDataErrorExecution === 'DEFAULT' ? DEFAULTS.ERROR : saveDataErrorExecution === 'all',
success:
saveDataSuccessExecution === 'DEFAULT'
? DEFAULTS.SUCCESS
: saveDataSuccessExecution === 'all',
manual: saveManualExecutions === 'DEFAULT' ? DEFAULTS.MANUAL : saveManualExecutions,
progress: saveExecutionProgress === 'DEFAULT' ? DEFAULTS.PROGRESS : saveExecutionProgress,
};
}
8 changes: 3 additions & 5 deletions packages/cli/src/posthog/__tests__/posthog.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { mock } from 'jest-mock-extended';
import { InstanceSettings } from 'n8n-core';
import { PostHog } from 'posthog-node';

import config from '@/config';
import { PostHogClient } from '@/posthog';
import { mockInstance } from '@test/mocking';

Expand All @@ -20,12 +19,11 @@ describe('PostHog', () => {
const globalConfig = mock<GlobalConfig>({ logging: { level: 'debug' } });

beforeAll(() => {
config.set('diagnostics.config.posthog.apiKey', apiKey);
config.set('diagnostics.config.posthog.apiHost', apiHost);
globalConfig.diagnostics.posthogConfig = { apiKey, apiHost };
});

beforeEach(() => {
config.set('diagnostics.enabled', true);
globalConfig.diagnostics.enabled = true;
jest.resetAllMocks();
});

Expand All @@ -37,7 +35,7 @@ describe('PostHog', () => {
});

it('does not initialize or track if diagnostics are not enabled', async () => {
config.set('diagnostics.enabled', false);
globalConfig.diagnostics.enabled = false;

const ph = new PostHogClient(instanceSettings, globalConfig);
await ph.init();
Expand Down
Loading

0 comments on commit f8cde6e

Please sign in to comment.