mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-25 00:07:47 +01:00
fix: add env and project labels to feature updated metrics. (#2043)
This commit is contained in:
parent
6e52718eab
commit
a7ed7557ec
@ -57,12 +57,13 @@ test('should collect metrics for requests', async () => {
|
|||||||
test('should collect metrics for updated toggles', async () => {
|
test('should collect metrics for updated toggles', async () => {
|
||||||
stores.eventStore.emit(FEATURE_UPDATED, {
|
stores.eventStore.emit(FEATURE_UPDATED, {
|
||||||
featureName: 'TestToggle',
|
featureName: 'TestToggle',
|
||||||
|
project: 'default',
|
||||||
data: { name: 'TestToggle' },
|
data: { name: 'TestToggle' },
|
||||||
});
|
});
|
||||||
|
|
||||||
const metrics = await prometheusRegister.metrics();
|
const metrics = await prometheusRegister.metrics();
|
||||||
expect(metrics).toMatch(
|
expect(metrics).toMatch(
|
||||||
/feature_toggle_update_total{toggle="TestToggle"} 1/,
|
/feature_toggle_update_total{toggle="TestToggle",project="default",environment="default"} 1/,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -10,6 +10,10 @@ import {
|
|||||||
FEATURE_STRATEGY_ADD,
|
FEATURE_STRATEGY_ADD,
|
||||||
FEATURE_STRATEGY_REMOVE,
|
FEATURE_STRATEGY_REMOVE,
|
||||||
FEATURE_STRATEGY_UPDATE,
|
FEATURE_STRATEGY_UPDATE,
|
||||||
|
FEATURE_ENVIRONMENT_ENABLED,
|
||||||
|
FEATURE_ENVIRONMENT_DISABLED,
|
||||||
|
FEATURE_VARIANTS_UPDATED,
|
||||||
|
FEATURE_METADATA_UPDATED,
|
||||||
FEATURE_UPDATED,
|
FEATURE_UPDATED,
|
||||||
CLIENT_METRICS,
|
CLIENT_METRICS,
|
||||||
CLIENT_REGISTER,
|
CLIENT_REGISTER,
|
||||||
@ -68,8 +72,8 @@ export default class MetricsMonitor {
|
|||||||
});
|
});
|
||||||
const featureToggleUpdateTotal = new client.Counter({
|
const featureToggleUpdateTotal = new client.Counter({
|
||||||
name: 'feature_toggle_update_total',
|
name: 'feature_toggle_update_total',
|
||||||
help: 'Number of times a toggle has been updated',
|
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 toggle is created.',
|
||||||
labelNames: ['toggle'],
|
labelNames: ['toggle', 'project', 'environment'],
|
||||||
});
|
});
|
||||||
const featureToggleUsageTotal = new client.Counter({
|
const featureToggleUsageTotal = new client.Counter({
|
||||||
name: 'feature_toggle_usage_total',
|
name: 'feature_toggle_usage_total',
|
||||||
@ -148,26 +152,65 @@ export default class MetricsMonitor {
|
|||||||
dbDuration.labels(store, action).observe(time);
|
dbDuration.labels(store, action).observe(time);
|
||||||
});
|
});
|
||||||
|
|
||||||
eventStore.on(FEATURE_CREATED, ({ featureName }) => {
|
eventStore.on(FEATURE_CREATED, ({ featureName, project }) => {
|
||||||
featureToggleUpdateTotal.labels(featureName).inc();
|
featureToggleUpdateTotal.labels(featureName, project, 'n/a').inc();
|
||||||
});
|
});
|
||||||
eventStore.on(FEATURE_UPDATED, ({ featureName }) => {
|
eventStore.on(FEATURE_VARIANTS_UPDATED, ({ featureName, project }) => {
|
||||||
featureToggleUpdateTotal.labels(featureName).inc();
|
featureToggleUpdateTotal.labels(featureName, project, 'n/a').inc();
|
||||||
});
|
});
|
||||||
eventStore.on(FEATURE_STRATEGY_ADD, ({ featureName }) => {
|
eventStore.on(FEATURE_METADATA_UPDATED, ({ featureName, project }) => {
|
||||||
featureToggleUpdateTotal.labels(featureName).inc();
|
featureToggleUpdateTotal.labels(featureName, project, 'n/a').inc();
|
||||||
});
|
});
|
||||||
eventStore.on(FEATURE_STRATEGY_REMOVE, ({ featureName }) => {
|
eventStore.on(FEATURE_UPDATED, ({ featureName, project }) => {
|
||||||
featureToggleUpdateTotal.labels(featureName).inc();
|
featureToggleUpdateTotal
|
||||||
|
.labels(featureName, project, 'default')
|
||||||
|
.inc();
|
||||||
});
|
});
|
||||||
eventStore.on(FEATURE_STRATEGY_UPDATE, ({ featureName }) => {
|
eventStore.on(
|
||||||
featureToggleUpdateTotal.labels(featureName).inc();
|
FEATURE_STRATEGY_ADD,
|
||||||
|
({ featureName, project, environment }) => {
|
||||||
|
featureToggleUpdateTotal
|
||||||
|
.labels(featureName, project, environment)
|
||||||
|
.inc();
|
||||||
|
},
|
||||||
|
);
|
||||||
|
eventStore.on(
|
||||||
|
FEATURE_STRATEGY_REMOVE,
|
||||||
|
({ featureName, project, environment }) => {
|
||||||
|
featureToggleUpdateTotal
|
||||||
|
.labels(featureName, project, environment)
|
||||||
|
.inc();
|
||||||
|
},
|
||||||
|
);
|
||||||
|
eventStore.on(
|
||||||
|
FEATURE_STRATEGY_UPDATE,
|
||||||
|
({ featureName, project, environment }) => {
|
||||||
|
featureToggleUpdateTotal
|
||||||
|
.labels(featureName, project, environment)
|
||||||
|
.inc();
|
||||||
|
},
|
||||||
|
);
|
||||||
|
eventStore.on(
|
||||||
|
FEATURE_ENVIRONMENT_DISABLED,
|
||||||
|
({ featureName, project, environment }) => {
|
||||||
|
featureToggleUpdateTotal
|
||||||
|
.labels(featureName, project, environment)
|
||||||
|
.inc();
|
||||||
|
},
|
||||||
|
);
|
||||||
|
eventStore.on(
|
||||||
|
FEATURE_ENVIRONMENT_ENABLED,
|
||||||
|
({ featureName, project, environment }) => {
|
||||||
|
featureToggleUpdateTotal
|
||||||
|
.labels(featureName, project, environment)
|
||||||
|
.inc();
|
||||||
|
},
|
||||||
|
);
|
||||||
|
eventStore.on(FEATURE_ARCHIVED, ({ featureName, project }) => {
|
||||||
|
featureToggleUpdateTotal.labels(featureName, project, 'n/a').inc();
|
||||||
});
|
});
|
||||||
eventStore.on(FEATURE_ARCHIVED, ({ featureName }) => {
|
eventStore.on(FEATURE_REVIVED, ({ featureName, project }) => {
|
||||||
featureToggleUpdateTotal.labels(featureName).inc();
|
featureToggleUpdateTotal.labels(featureName, project, 'n/a').inc();
|
||||||
});
|
|
||||||
eventStore.on(FEATURE_REVIVED, ({ featureName }) => {
|
|
||||||
featureToggleUpdateTotal.labels(featureName).inc();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
eventBus.on(CLIENT_METRICS, (m) => {
|
eventBus.on(CLIENT_METRICS, (m) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user