mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-06 00:07:44 +01:00
fe4bb4f227
See linear issue: https://linear.app/unleash/issue/1-1656/add-scheduler-observability As per post mortem actions, we are adding observability to scheduled functions. This PR adds prometheus observability to our scheduled functions via a summary. In addition to timing these functions with the more accurate process.hrtime, we are getting a counter for free per scheduled job id. Prometheus example: <img width="731" alt="Skjermbilde 2023-11-21 kl 13 36 33" src="https://github.com/Unleash/unleash/assets/16081982/08a2064d-5152-4b4f-8a08-eb06e726757a">
54 lines
1.8 KiB
TypeScript
54 lines
1.8 KiB
TypeScript
import { SchedulerService } from '../features/scheduler/scheduler-service';
|
|
import MaintenanceService from './maintenance-service';
|
|
import SettingService from './setting-service';
|
|
import { createTestConfig } from '../../test/config/test-config';
|
|
import FakeSettingStore from '../../test/fixtures/fake-setting-store';
|
|
import EventService from './event-service';
|
|
|
|
test('Scheduler should run scheduled functions if maintenance mode is off', async () => {
|
|
const config = createTestConfig();
|
|
const settingStore = new FakeSettingStore();
|
|
const settingService = new SettingService({ settingStore }, config, {
|
|
storeEvent() {},
|
|
} as unknown as EventService);
|
|
const maintenanceService = new MaintenanceService(config, settingService);
|
|
const schedulerService = new SchedulerService(
|
|
config.getLogger,
|
|
maintenanceService,
|
|
config.eventBus,
|
|
);
|
|
|
|
const job = jest.fn();
|
|
|
|
await schedulerService.schedule(job, 10, 'test-id');
|
|
|
|
expect(job).toBeCalledTimes(1);
|
|
schedulerService.stop();
|
|
});
|
|
|
|
test('Scheduler should not run scheduled functions if maintenance mode is on', async () => {
|
|
const config = createTestConfig();
|
|
const settingStore = new FakeSettingStore();
|
|
const settingService = new SettingService({ settingStore }, config, {
|
|
storeEvent() {},
|
|
} as unknown as EventService);
|
|
const maintenanceService = new MaintenanceService(config, settingService);
|
|
const schedulerService = new SchedulerService(
|
|
config.getLogger,
|
|
maintenanceService,
|
|
config.eventBus,
|
|
);
|
|
|
|
await maintenanceService.toggleMaintenanceMode(
|
|
{ enabled: true },
|
|
'irrelevant user',
|
|
);
|
|
|
|
const job = jest.fn();
|
|
|
|
await schedulerService.schedule(job, 10, 'test-id');
|
|
|
|
expect(job).toBeCalledTimes(0);
|
|
schedulerService.stop();
|
|
});
|