fix(core): Load insights module on webhook instance to save insights on webhook workflows (#15433)

This commit is contained in:
Guillaume Jacquart
2025-05-19 10:03:45 +02:00
committed by GitHub
parent d9fdef3bf9
commit bf5551d711
2 changed files with 14 additions and 11 deletions

View File

@@ -1,22 +1,25 @@
import { mock } from 'jest-mock-extended'; import { mock } from 'jest-mock-extended';
import type { InstanceSettings } from 'n8n-core'; import type { InstanceSettings, InstanceType } from 'n8n-core';
import type { ModulePreInitContext } from '@/modules/modules.config'; import type { ModulePreInitContext } from '@/modules/modules.config';
import { shouldLoadModule } from '../insights.pre-init'; import { shouldLoadModule } from '../insights.pre-init';
describe('InsightsModulePreInit', () => { describe('InsightsModulePreInit', () => {
it('should return false if instance type is not "main"', () => { it('should return false if instance type is worker', () => {
const ctx: ModulePreInitContext = { const ctx: ModulePreInitContext = {
instance: mock<InstanceSettings>({ instanceType: 'worker' }), instance: mock<InstanceSettings>({ instanceType: 'worker' }),
}; };
expect(shouldLoadModule(ctx)).toBe(false); expect(shouldLoadModule(ctx)).toBe(false);
}); });
it('should return true if instance type is "main"', () => { it.each<InstanceType>(['main', 'webhook'])(
const ctx: ModulePreInitContext = { 'should return true if instance type is "%s"',
instance: mock<InstanceSettings>({ instanceType: 'main' }), (instanceType) => {
}; const ctx: ModulePreInitContext = {
expect(shouldLoadModule(ctx)).toBe(true); instance: mock<InstanceSettings>({ instanceType }),
}); };
expect(shouldLoadModule(ctx)).toBe(true);
},
);
}); });

View File

@@ -1,6 +1,6 @@
import type { ModulePreInitContext } from '../modules.config'; import type { ModulePreInitContext } from '../modules.config';
export const shouldLoadModule = (ctx: ModulePreInitContext) => export const shouldLoadModule = (ctx: ModulePreInitContext) =>
// Only main instance(s) should collect insights // Only main and webhook instance(s) should collect insights
// Because main instances are informed of all finished workflow executions, whatever the mode // Because main and webhooks instances are the ones informed of all finished workflow executions, whatever the mode
ctx.instance.instanceType === 'main'; ctx.instance.instanceType === 'main' || ctx.instance.instanceType === 'webhook';