Skip to content

Commit

Permalink
fix: extend feature_toggle_update counter with details about action
Browse files Browse the repository at this point in the history
  • Loading branch information
ivarconr committed Sep 20, 2024
1 parent bb32336 commit 34a9856
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
1 change: 0 additions & 1 deletion src/lib/__snapshots__/create-config.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ exports[`should create default config 1`] = `
"_events": {},
"_eventsCount": 0,
"_maxListeners": undefined,
Symbol(shapeMode): false,
Symbol(kCapture): false,
},
"feedbackUriPath": undefined,
Expand Down
4 changes: 2 additions & 2 deletions src/lib/metrics.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ test('should collect metrics for updated toggles', async () => {

const metrics = await prometheusRegister.metrics();
expect(metrics).toMatch(
/feature_toggle_update_total\{toggle="TestToggle",project="default",environment="default",environmentType="production"\} 1/,
/feature_toggle_update_total\{toggle="TestToggle",project="default",environment="default",environmentType="production",action="updated"\} 1/,
);
});

Expand All @@ -166,7 +166,7 @@ test('should set environmentType when toggle is flipped', async () => {
const metrics = await prometheusRegister.metrics();

expect(metrics).toMatch(
/feature_toggle_update_total\{toggle="TestToggle",project="default",environment="testEnvironment",environmentType="testType"\} 1/,
/feature_toggle_update_total\{toggle="TestToggle",project="default",environment="testEnvironment",environmentType="testType",action="updated"\} 1/,
);
});

Expand Down
19 changes: 18 additions & 1 deletion src/lib/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,13 @@ export default class MetricsMonitor {
const featureFlagUpdateTotal = createCounter({
name: 'feature_toggle_update_total',
help: 'Number of times a toggle has been updated. Environment label would be "n/a" when it is not available, e.g. when a feature flag is created.',
labelNames: ['toggle', 'project', 'environment', 'environmentType'],
labelNames: [
'toggle',
'project',
'environment',
'environmentType',
'action',
],
});
const featureFlagUsageTotal = createCounter({
name: 'feature_toggle_usage_total',
Expand Down Expand Up @@ -782,6 +788,7 @@ export default class MetricsMonitor {
project,
environment: 'n/a',
environmentType: 'n/a',
action: 'created',
});
});
eventStore.on(FEATURE_VARIANTS_UPDATED, ({ featureName, project }) => {
Expand All @@ -790,6 +797,7 @@ export default class MetricsMonitor {
project,
environment: 'n/a',
environmentType: 'n/a',
action: 'updated',
});
});
eventStore.on(FEATURE_METADATA_UPDATED, ({ featureName, project }) => {
Expand All @@ -798,6 +806,7 @@ export default class MetricsMonitor {
project,
environment: 'n/a',
environmentType: 'n/a',
action: 'updated',
});
});
eventStore.on(FEATURE_UPDATED, ({ featureName, project }) => {
Expand All @@ -806,6 +815,7 @@ export default class MetricsMonitor {
project,
environment: 'default',
environmentType: 'production',
action: 'updated',
});
});
eventStore.on(
Expand All @@ -820,6 +830,7 @@ export default class MetricsMonitor {
project,
environment,
environmentType,
action: 'updated',
});
},
);
Expand All @@ -835,6 +846,7 @@ export default class MetricsMonitor {
project,
environment,
environmentType,
action: 'updated',
});
},
);
Expand All @@ -850,6 +862,7 @@ export default class MetricsMonitor {
project,
environment,
environmentType,
action: 'updated',
});
},
);
Expand All @@ -865,6 +878,7 @@ export default class MetricsMonitor {
project,
environment,
environmentType,
action: 'updated',
});
},
);
Expand All @@ -880,6 +894,7 @@ export default class MetricsMonitor {
project,
environment,
environmentType,
action: 'updated',
});
},
);
Expand All @@ -889,6 +904,7 @@ export default class MetricsMonitor {
project,
environment: 'n/a',
environmentType: 'n/a',
action: 'archived',
});
});
eventStore.on(FEATURE_REVIVED, ({ featureName, project }) => {
Expand All @@ -897,6 +913,7 @@ export default class MetricsMonitor {
project,
environment: 'n/a',
environmentType: 'n/a',
action: 'revived',
});
});
eventStore.on(PROJECT_CREATED, () => {
Expand Down

0 comments on commit 34a9856

Please sign in to comment.