-
-
Notifications
You must be signed in to change notification settings - Fork 742
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
chore: handle aggregation queries sequentially follow up #8450
Changes from 6 commits
9bf5ed5
7b585f1
8cda5cd
e2cd347
73f3559
4806106
05a338c
f5cf84c
5edd0f8
e7de20f
e97f748
add3bed
1a977fe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,7 +57,7 @@ export default class MetricsMonitor { | |
|
||
const { eventStore, environmentStore } = stores; | ||
const { flagResolver } = config; | ||
const dbMetrics = new DbMetricsMonitor(); | ||
const dbMetrics = new DbMetricsMonitor(config); | ||
|
||
const cachedEnvironments: () => Promise<IEnvironment[]> = memoizee( | ||
async () => environmentStore.getAll(), | ||
|
@@ -117,15 +117,29 @@ export default class MetricsMonitor { | |
help: 'Number of times a feature flag has been used', | ||
labelNames: ['toggle', 'active', 'appName'], | ||
}); | ||
const featureFlagsTotal = createGauge({ | ||
|
||
// schedule and execute immediately | ||
await dbMetrics.registerGaugeDbMetric({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These tasks need to execute immediately because the tests expect that. I'd argue that some of these can be delayed, but maybe they are important because of other components depending on these. So I'm delaying this decision until we migrated all gauges to dbMetrics |
||
name: 'feature_toggles_total', | ||
help: 'Number of feature flags', | ||
labelNames: ['version'], | ||
}); | ||
const maxFeatureEnvironmentStrategies = createGauge({ | ||
query: () => instanceStatsService.getToggleCount(), | ||
map: (count) => ({ count, labels: { version } }), | ||
})(); | ||
|
||
dbMetrics.registerGaugeDbMetric({ | ||
name: 'max_feature_environment_strategies', | ||
help: 'Maximum number of environment strategies in one feature', | ||
labelNames: ['feature', 'environment'], | ||
query: () => | ||
stores.featureStrategiesReadModel.getMaxFeatureEnvironmentStrategies(), | ||
map: (result) => ({ | ||
count: result.count, | ||
labels: { | ||
environment: result.environment, | ||
feature: result.feature, | ||
}, | ||
}), | ||
}); | ||
|
||
dbMetrics.registerGaugeDbMetric({ | ||
|
@@ -246,11 +260,18 @@ export default class MetricsMonitor { | |
help: 'Number of strategies', | ||
}); | ||
|
||
const clientAppsTotal = createGauge({ | ||
// execute immediately to get initial values | ||
await dbMetrics.registerGaugeDbMetric({ | ||
name: 'client_apps_total', | ||
help: 'Number of registered client apps aggregated by range by last seen', | ||
labelNames: ['range'], | ||
}); | ||
query: () => instanceStatsService.getLabeledAppCounts(), | ||
map: (result) => | ||
Object.entries(result).map(([range, count]) => ({ | ||
count, | ||
labels: { range }, | ||
})), | ||
})(); | ||
|
||
const samlEnabled = createGauge({ | ||
name: 'saml_enabled', | ||
|
@@ -408,7 +429,6 @@ export default class MetricsMonitor { | |
|
||
const stats = await instanceStatsService.getStats(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. getStats was triggering many queries in parallel, some of which were not used in prometheus. |
||
const [ | ||
maxEnvironmentStrategies, | ||
maxConstraintValuesResult, | ||
maxConstraintsPerStrategyResult, | ||
stageCountByProjectResult, | ||
|
@@ -419,7 +439,6 @@ export default class MetricsMonitor { | |
instanceOnboardingMetrics, | ||
projectsOnboardingMetrics, | ||
] = await Promise.all([ | ||
stores.featureStrategiesReadModel.getMaxFeatureEnvironmentStrategies(), | ||
stores.featureStrategiesReadModel.getMaxConstraintValues(), | ||
stores.featureStrategiesReadModel.getMaxConstraintsPerStrategy(), | ||
stores.featureLifecycleReadModel.getStageCountByProject(), | ||
|
@@ -439,9 +458,6 @@ export default class MetricsMonitor { | |
: Promise.resolve([]), | ||
]); | ||
|
||
featureFlagsTotal.reset(); | ||
featureFlagsTotal.labels({ version }).set(stats.featureToggles); | ||
|
||
featureTogglesArchivedTotal.reset(); | ||
featureTogglesArchivedTotal.set(stats.archivedFeatureToggles); | ||
|
||
|
@@ -460,30 +476,6 @@ export default class MetricsMonitor { | |
.set(stage.duration); | ||
}); | ||
|
||
eventBus.on( | ||
events.STAGE_ENTERED, | ||
(entered: { stage: string; feature: string }) => { | ||
if (flagResolver.isEnabled('trackLifecycleMetrics')) { | ||
logger.info( | ||
`STAGE_ENTERED listened ${JSON.stringify(entered)}`, | ||
); | ||
} | ||
featureLifecycleStageEnteredCounter.increment({ | ||
stage: entered.stage, | ||
}); | ||
}, | ||
); | ||
|
||
eventBus.on( | ||
events.EXCEEDS_LIMIT, | ||
({ | ||
resource, | ||
limit, | ||
}: { resource: string; limit: number }) => { | ||
exceedsLimitErrorCounter.increment({ resource, limit }); | ||
}, | ||
); | ||
Comment on lines
-463
to
-485
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved up to line 485 on the right side. Now lives inside |
||
|
||
featureLifecycleStageCountByProject.reset(); | ||
stageCountByProjectResult.forEach((stageResult) => | ||
featureLifecycleStageCountByProject | ||
|
@@ -512,16 +504,6 @@ export default class MetricsMonitor { | |
legacyTokensActive.reset(); | ||
legacyTokensActive.set(deprecatedTokens.activeLegacyTokens); | ||
|
||
if (maxEnvironmentStrategies) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This got migrated to: https://github.com/Unleash/unleash/pull/8450/files#diff-0610ce1595d1dcf150ca2efb2f0c5806d082f5bc6b8429a437970c7d60171cbdR181-R194 where both the gauge definition and refresh query are together |
||
maxFeatureEnvironmentStrategies.reset(); | ||
maxFeatureEnvironmentStrategies | ||
.labels({ | ||
environment: maxEnvironmentStrategies.environment, | ||
feature: maxEnvironmentStrategies.feature, | ||
}) | ||
.set(maxEnvironmentStrategies.count); | ||
} | ||
|
||
if (maxConstraintValuesResult) { | ||
maxConstraintValues.reset(); | ||
maxConstraintValues | ||
|
@@ -653,11 +635,6 @@ export default class MetricsMonitor { | |
oidcEnabled.reset(); | ||
oidcEnabled.set(stats.OIDCenabled ? 1 : 0); | ||
|
||
clientAppsTotal.reset(); | ||
stats.clientApps.forEach(({ range, count }) => | ||
clientAppsTotal.labels({ range }).set(count), | ||
); | ||
|
||
rateLimits.reset(); | ||
rateLimits | ||
.labels({ | ||
|
@@ -720,7 +697,27 @@ export default class MetricsMonitor { | |
collectStaticCounters.bind(this), | ||
hoursToMilliseconds(2), | ||
'collectStaticCounters', | ||
0, // no jitter | ||
); | ||
|
||
eventBus.on( | ||
events.EXCEEDS_LIMIT, | ||
({ resource, limit }: { resource: string; limit: number }) => { | ||
exceedsLimitErrorCounter.increment({ resource, limit }); | ||
}, | ||
); | ||
|
||
eventBus.on( | ||
events.STAGE_ENTERED, | ||
(entered: { stage: string; feature: string }) => { | ||
if (flagResolver.isEnabled('trackLifecycleMetrics')) { | ||
logger.info( | ||
`STAGE_ENTERED listened ${JSON.stringify(entered)}`, | ||
); | ||
} | ||
featureLifecycleStageEnteredCounter.increment({ | ||
stage: entered.stage, | ||
}); | ||
}, | ||
); | ||
|
||
eventBus.on( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A single task can output different counts for different labels. This is useful for cases like
client_apps_total
at line 40