1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-10-27 11:02:16 +01:00

feat: measure time in release plan read model (#10788)

This commit is contained in:
Mateusz Kwasniewski 2025-10-13 15:06:56 +02:00 committed by GitHub
parent aaf8e37d45
commit c74ca0d8ed
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 18 additions and 3 deletions

View File

@ -143,7 +143,7 @@ export const createFeatureToggleService = (
const resourceLimitsService = new ResourceLimitsService(config);
const releasePlanReadModel = new ReleasePlanReadModel(db);
const releasePlanReadModel = new ReleasePlanReadModel(db, eventBus);
const featureToggleService = new FeatureToggleService(
{

View File

@ -1,4 +1,5 @@
import { ulid } from 'ulidx';
import { EventEmitter } from 'events';
import dbInit, {
type ITestDb,
} from '../../../test/e2e/helpers/database-init.js';
@ -16,10 +17,12 @@ let featureToggleStore: IFeatureToggleStore;
let releasePlanStore: ReleasePlanStore;
let releasePlanMilestoneStore: ReleasePlanMilestoneStore;
let featureEnvironmentStore: IFeatureEnvironmentStore;
let eventBus: EventEmitter;
beforeAll(async () => {
db = await dbInit('release_plan_read_model', getLogger);
releasePlanReadModel = new ReleasePlanReadModel(db.rawDatabase);
eventBus = new EventEmitter();
releasePlanReadModel = new ReleasePlanReadModel(db.rawDatabase, eventBus);
featureToggleStore = db.stores.featureToggleStore;
releasePlanStore = db.stores.releasePlanStore;
releasePlanMilestoneStore = db.stores.releasePlanMilestoneStore;

View File

@ -1,6 +1,8 @@
import type { Db } from '../../db/db.js';
import type { IReleasePlanReadModel } from './release-plan-read-model-type.js';
import type { ReleasePlan } from './release-plan.js';
import metricsHelper from '../../util/metrics-helper.js';
import type EventEmitter from 'events';
const TABLE = 'release_plan_definitions';
@ -140,15 +142,24 @@ const processReleasePlanRows = (templateRows): ReleasePlan[] =>
export class ReleasePlanReadModel implements IReleasePlanReadModel {
private db: Db;
constructor(db: Db) {
private timer: Function;
constructor(db: Db, eventBus: EventEmitter) {
this.db = db;
this.timer = (action: string) =>
metricsHelper.wrapTimer(eventBus, 'db_time', {
store: 'release-plan-read-model',
action,
});
}
async getReleasePlans(
featureName: string,
environments: string[],
): Promise<Record<string, ReleasePlan[]>> {
const endTimer = this.timer('getReleasePlans');
if (environments.length === 0) {
endTimer();
return {};
}
@ -193,6 +204,7 @@ export class ReleasePlanReadModel implements IReleasePlanReadModel {
}
}
endTimer();
return plansByEnvironment;
}
}