Skip to content

Commit

Permalink
fix: ignore metrics for non-existent features (#6945)
Browse files Browse the repository at this point in the history
  • Loading branch information
kwasniew committed Apr 26, 2024
1 parent 8ed1516 commit 31ab38e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
15 changes: 14 additions & 1 deletion src/lib/features/feature-lifecycle/feature-lifecycle-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,22 @@ export class FeatureLifecycleStore implements IFeatureLifecycleStore {
async insert(
featureLifecycleStages: FeatureLifecycleStage[],
): 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')
.insert(
featureLifecycleStages.map((stage) => ({
validStages.map((stage) => ({
feature: stage.feature,
stage: stage.stage,
})),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,12 @@ test('should return lifecycle stages', async () => {
await reachedStage('initial');
await expectFeatureStage('initial');
eventBus.emit(CLIENT_METRICS, {
bucket: { toggles: { my_feature_a: 'irrelevant' } },
bucket: {
toggles: {
my_feature_a: 'irrelevant',
non_existent_feature: 'irrelevent',
},
},
environment: 'default',
});
// missing feature
Expand Down

0 comments on commit 31ab38e

Please sign in to comment.