1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-25 00:07:47 +01:00

fix: ignore metrics for non-existent features (#6945)

This commit is contained in:
Mateusz Kwasniewski 2024-04-26 10:30:12 +02:00 committed by GitHub
parent 8ed15165d2
commit 31ab38e162
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 20 additions and 2 deletions

View File

@ -22,9 +22,22 @@ export class FeatureLifecycleStore implements IFeatureLifecycleStore {
async insert( async insert(
featureLifecycleStages: FeatureLifecycleStage[], featureLifecycleStages: FeatureLifecycleStage[],
): Promise<void> { ): Promise<void> {
const existingFeatures = await this.db('features')
.select('name')
.whereIn(
'name',
featureLifecycleStages.map((stage) => stage.feature),
);
const existingFeaturesSet = new Set(
existingFeatures.map((item) => item.name),
);
const validStages = featureLifecycleStages.filter((stage) =>
existingFeaturesSet.has(stage.feature),
);
await this.db('feature_lifecycles') await this.db('feature_lifecycles')
.insert( .insert(
featureLifecycleStages.map((stage) => ({ validStages.map((stage) => ({
feature: stage.feature, feature: stage.feature,
stage: stage.stage, stage: stage.stage,
})), })),

View File

@ -87,7 +87,12 @@ test('should return lifecycle stages', async () => {
await reachedStage('initial'); await reachedStage('initial');
await expectFeatureStage('initial'); await expectFeatureStage('initial');
eventBus.emit(CLIENT_METRICS, { eventBus.emit(CLIENT_METRICS, {
bucket: { toggles: { my_feature_a: 'irrelevant' } }, bucket: {
toggles: {
my_feature_a: 'irrelevant',
non_existent_feature: 'irrelevent',
},
},
environment: 'default', environment: 'default',
}); });
// missing feature // missing feature