Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: extend feature_toggle_update counter with details about action #8202

Merged
merged 2 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading