mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
feat(core): Add metrics option to cache (#6846)
* add metrics to cache * use events for metrics * pr comments / broken test * lint fix * update the test * improve tests * Update packages/cli/src/config/schema.ts * disable flaky test * lint fix --------- Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <aditya@netroy.in> Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <netroy@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
fdfc6c5a92
commit
adcf5a96e8
78
packages/cli/test/integration/metrics.test.ts
Normal file
78
packages/cli/test/integration/metrics.test.ts
Normal file
@@ -0,0 +1,78 @@
|
||||
import { setupTestServer } from './shared/utils';
|
||||
import config from '@/config';
|
||||
import request from 'supertest';
|
||||
import Container from 'typedi';
|
||||
import { MetricsService } from '../../src/services/metrics.service';
|
||||
import { N8N_VERSION } from '../../src/constants';
|
||||
import { parse as semverParse } from 'semver';
|
||||
|
||||
jest.unmock('@/eventbus/MessageEventBus/MessageEventBus');
|
||||
config.set('endpoints.metrics.enable', true);
|
||||
config.set('endpoints.metrics.includeDefaultMetrics', false);
|
||||
config.set('endpoints.metrics.prefix', 'n8n_test_');
|
||||
const testServer = setupTestServer({ endpointGroups: ['metrics'] });
|
||||
|
||||
let testAgent = request.agent(testServer.app);
|
||||
|
||||
async function getMetricsResponseAsLines() {
|
||||
const response = await testAgent.get('/metrics');
|
||||
expect(response.status).toEqual(200);
|
||||
expect(response.type).toEqual('text/plain');
|
||||
|
||||
const lines = response.text.trim().split('\n');
|
||||
return lines;
|
||||
}
|
||||
|
||||
describe('Metrics', () => {
|
||||
it('should return n8n version', async () => {
|
||||
const n8nVersion = semverParse(N8N_VERSION || '0.0.0');
|
||||
expect(n8nVersion).toBeTruthy();
|
||||
const lines = await getMetricsResponseAsLines();
|
||||
expect(lines).toContain(
|
||||
`n8n_test_version_info{version="v${n8nVersion!.version}",major="${
|
||||
n8nVersion!.major
|
||||
}",minor="${n8nVersion!.minor}",patch="${n8nVersion!.patch}"} 1`,
|
||||
);
|
||||
});
|
||||
|
||||
it('should return cache metrics when enabled', async () => {
|
||||
config.set('endpoints.metrics.includeCacheMetrics', true);
|
||||
await Container.get(MetricsService).configureMetrics(testServer.app);
|
||||
const lines = await getMetricsResponseAsLines();
|
||||
expect(lines).toContain('n8n_test_cache_hits_total 0');
|
||||
expect(lines).toContain('n8n_test_cache_misses_total 0');
|
||||
expect(lines).toContain('n8n_test_cache_updates_total 0');
|
||||
});
|
||||
|
||||
// TODO: Commented out due to flakiness in CI
|
||||
// it('should return event metrics when enabled', async () => {
|
||||
// config.set('endpoints.metrics.includeMessageEventBusMetrics', true);
|
||||
// await Container.get(MetricsService).configureMetrics(testServer.app);
|
||||
// await eventBus.initialize();
|
||||
// await eventBus.send(
|
||||
// new EventMessageGeneric({
|
||||
// eventName: 'n8n.destination.test',
|
||||
// }),
|
||||
// );
|
||||
// const lines = await getMetricsResponseAsLines();
|
||||
// expect(lines).toContain('n8n_test_destination_test_total 1');
|
||||
// await eventBus.close();
|
||||
// jest.mock('@/eventbus/MessageEventBus/MessageEventBus');
|
||||
// });
|
||||
|
||||
it('should return default metrics', async () => {
|
||||
config.set('endpoints.metrics.includeDefaultMetrics', true);
|
||||
await Container.get(MetricsService).configureMetrics(testServer.app);
|
||||
const lines = await getMetricsResponseAsLines();
|
||||
expect(lines).toContain('nodejs_heap_space_size_total_bytes{space="read_only"} 0');
|
||||
config.set('endpoints.metrics.includeDefaultMetrics', false);
|
||||
});
|
||||
|
||||
it('should not return default metrics only when disabled', async () => {
|
||||
config.set('endpoints.metrics.includeDefaultMetrics', false);
|
||||
await Container.get(MetricsService).configureMetrics(testServer.app);
|
||||
const lines = await getMetricsResponseAsLines();
|
||||
expect(lines).not.toContain('nodejs_heap_space_size_total_bytes{space="read_only"} 0');
|
||||
config.set('endpoints.metrics.includeDefaultMetrics', true);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user