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

View File

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