mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
fix(core)!: Change last activity to use unix time (#15951)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { GlobalConfig } from '@n8n/config';
|
||||
import { WorkflowRepository } from '@n8n/db';
|
||||
import { Container } from '@n8n/di';
|
||||
import { DateTime } from 'luxon';
|
||||
import { parse as semverParse } from 'semver';
|
||||
import request, { type Response } from 'supertest';
|
||||
|
||||
@@ -53,6 +54,11 @@ describe('PrometheusMetricsService', () => {
|
||||
prometheusService.disableAllLabels();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
// Make sure fake timers aren't in effect after a test
|
||||
jest.useRealTimers();
|
||||
});
|
||||
|
||||
it('should return n8n version', async () => {
|
||||
/**
|
||||
* Arrange
|
||||
@@ -211,9 +217,11 @@ describe('PrometheusMetricsService', () => {
|
||||
/**
|
||||
* Arrange
|
||||
*/
|
||||
const startTime = DateTime.now().toUnixInteger();
|
||||
jest.useFakeTimers().setSystemTime(startTime * 1000);
|
||||
|
||||
prometheusService.enableMetric('routes');
|
||||
await prometheusService.init(server.app);
|
||||
await agent.get('/api/v1/workflows');
|
||||
|
||||
/**
|
||||
* Act
|
||||
@@ -230,26 +238,30 @@ describe('PrometheusMetricsService', () => {
|
||||
|
||||
expect(lines).toContainEqual(expect.stringContaining('n8n_test_last_activity'));
|
||||
|
||||
const lastActivityLine = lines.find((line) =>
|
||||
line.startsWith('n8n_test_last_activity{timestamp='),
|
||||
);
|
||||
const lastActivityLine = lines.find((line) => line.startsWith('n8n_test_last_activity'));
|
||||
|
||||
expect(lastActivityLine).toBeDefined();
|
||||
expect(lastActivityLine?.endsWith('1')).toBe(true);
|
||||
|
||||
const value = lastActivityLine!.split(' ')[1];
|
||||
|
||||
expect(parseInt(value, 10)).toBe(startTime);
|
||||
|
||||
// Update last activity
|
||||
jest.advanceTimersByTime(1000);
|
||||
await agent.get('/api/v1/workflows');
|
||||
|
||||
response = await agent.get('/metrics');
|
||||
const updatedLines = toLines(response);
|
||||
|
||||
const newLastActivityLine = updatedLines.find((line) =>
|
||||
line.startsWith('n8n_test_last_activity{timestamp='),
|
||||
line.startsWith('n8n_test_last_activity'),
|
||||
);
|
||||
|
||||
expect(newLastActivityLine).toBeDefined();
|
||||
// Timestamp label should be different
|
||||
expect(newLastActivityLine).not.toBe(lastActivityLine);
|
||||
|
||||
const newValue = newLastActivityLine!.split(' ')[1];
|
||||
|
||||
expect(parseInt(newValue, 10)).toBe(startTime + 1);
|
||||
});
|
||||
|
||||
it('should return labels in route metrics if enabled', async () => {
|
||||
|
||||
Reference in New Issue
Block a user