Skip to content

Commit

Permalink
fix: feature toggle update total needs 4 labels (#5946) (#5966)
Browse files Browse the repository at this point in the history
So, this was causing a lot of ERROR in our logs, due to the metric
having gotten an extra label the last month.

Two things for this fix.
1. add the missing label to the two calls that did not have it added
2. update the log line to include the error as another argument to the
logger, so we actually get a stacktrace from the error.
  • Loading branch information
Christopher Kolstad authored Jan 19, 2024
1 parent e6c7f44 commit 228d994
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 42 deletions.
45 changes: 17 additions & 28 deletions src/lib/features/scheduler/scheduler-service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,15 @@ test('Can handle crash of a async job', async () => {
await ms(75);

schedulerService.stop();
expect(getRecords()).toEqual([
['scheduled job failed | id: test-id-10 | async reason'],
['scheduled job failed | id: test-id-10 | async reason'],
]);
const records = getRecords();
expect(records[0][0]).toContain(
'initial scheduled job failed | id: test-id-10',
);
expect(records[0][1]).toContain('async reason');
expect(records[1][0]).toContain(
'interval scheduled job failed | id: test-id-10',
);
expect(records[1][1]).toContain('async reason');
});

test('Can handle crash of a sync job', async () => {
Expand All @@ -196,30 +201,14 @@ test('Can handle crash of a sync job', async () => {
await ms(75);

schedulerService.stop();
expect(getRecords()).toEqual([
['scheduled job failed | id: test-id-11 | Error: sync reason'],
['scheduled job failed | id: test-id-11 | Error: sync reason'],
]);
});

test('Can handle crash of a async job', async () => {
const { logger, getRecords } = getLogger();
const { schedulerService } = createSchedulerTestService({
loggerOverride: logger,
});

const job = async () => {
await Promise.reject('async reason');
};

await schedulerService.schedule(job, 50, 'test-id-10');
await ms(75);

schedulerService.stop();
expect(getRecords()).toEqual([
['scheduled job failed | id: test-id-10 | async reason'],
['scheduled job failed | id: test-id-10 | async reason'],
]);
const records = getRecords();
expect(records[0][0]).toContain(
'initial scheduled job failed | id: test-id-11',
);
expect(records[0][1].message).toContain('sync reason');
expect(records[1][0]).toContain(
'interval scheduled job failed | id: test-id-11',
);
});

it('should emit scheduler job time event when scheduled function is run', async () => {
Expand Down
5 changes: 3 additions & 2 deletions src/lib/features/scheduler/scheduler-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ export class SchedulerService {
}
} catch (e) {
this.logger.error(
`scheduled job failed | id: ${id} | ${e}`,
`interval scheduled job failed | id: ${id}`,
e,
);
}
}, timeMs).unref(),
Expand All @@ -64,7 +65,7 @@ export class SchedulerService {
await runScheduledFunctionWithEvent();
}
} catch (e) {
this.logger.error(`scheduled job failed | id: ${id} | ${e}`);
this.logger.error(`initial scheduled job failed | id: ${id}`, e);
}
}

Expand Down
8 changes: 6 additions & 2 deletions src/lib/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -450,10 +450,14 @@ export default class MetricsMonitor {
},
);
eventStore.on(FEATURE_ARCHIVED, ({ featureName, project }) => {
featureToggleUpdateTotal.labels(featureName, project, 'n/a').inc();
featureToggleUpdateTotal
.labels(featureName, project, 'n/a', 'n/a')
.inc();
});
eventStore.on(FEATURE_REVIVED, ({ featureName, project }) => {
featureToggleUpdateTotal.labels(featureName, project, 'n/a').inc();
featureToggleUpdateTotal
.labels(featureName, project, 'n/a', 'n/a')
.inc();
});

eventBus.on(CLIENT_METRICS, (m: ValidatedClientMetrics) => {
Expand Down
26 changes: 16 additions & 10 deletions src/lib/services/scheduler-service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import SettingService from './setting-service';
import EventService from './event-service';
import MaintenanceService from '../features/maintenance/maintenance-service';

function ms(timeMs) {
function ms(timeMs: number) {
return new Promise((resolve) => setTimeout(resolve, timeMs));
}

Expand All @@ -29,7 +29,7 @@ const getLogger = () => {
};

let schedulerService: SchedulerService;
let getRecords;
let getRecords: () => any[];

beforeEach(() => {
const config = createTestConfig();
Expand Down Expand Up @@ -100,10 +100,13 @@ test('Can handle crash of a async job', async () => {
await ms(75);

schedulerService.stop();
expect(getRecords()).toEqual([
['scheduled job failed | id: test-id-10 | async reason'],
['scheduled job failed | id: test-id-10 | async reason'],
]);
const records = getRecords();
expect(records[0][0]).toContain(
'initial scheduled job failed | id: test-id-10',
);
expect(records[1][0]).toContain(
'interval scheduled job failed | id: test-id-10',
);
});

test('Can handle crash of a sync job', async () => {
Expand All @@ -115,8 +118,11 @@ test('Can handle crash of a sync job', async () => {
await ms(75);

schedulerService.stop();
expect(getRecords()).toEqual([
['scheduled job failed | id: test-id-11 | Error: sync reason'],
['scheduled job failed | id: test-id-11 | Error: sync reason'],
]);
const records = getRecords();
expect(records[0][0]).toContain(
'initial scheduled job failed | id: test-id-11',
);
expect(records[1][0]).toContain(
'interval scheduled job failed | id: test-id-11',
);
});

0 comments on commit 228d994

Please sign in to comment.