-
-
Notifications
You must be signed in to change notification settings - Fork 735
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: add a class to handle aggreggation queries #8446
chore: add a class to handle aggreggation queries #8446
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
1 Skipped Deployment
|
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.OpenSSF Scorecard
Scanned Manifest Files |
f02fe87
to
3cbbeff
Compare
src/lib/metrics.ts
Outdated
dbMetrics.registerGaugeDbMetric({ | ||
name: 'max_feature_strategies', | ||
help: 'Maximum number of strategies in one feature', | ||
labelNames: ['feature'], | ||
query: () => | ||
stores.featureStrategiesReadModel.getMaxFeatureStrategies(), | ||
map: (result) => ({ | ||
count: result.count, | ||
labels: { feature: result.feature }, | ||
}), |
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.
Gauge and query are now declared together
@@ -408,7 +419,6 @@ export default class MetricsMonitor { | |||
instanceOnboardingMetrics, | |||
projectsOnboardingMetrics, | |||
] = await Promise.all([ |
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.
We do not need to run these in parallel. I would be to get rid of promise all.
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.
Exactly, we are going to do that gradually. When we register a new metric into this new implementation, the new implementation will run them sequentially
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.
Super nice!
Co-authored-by: Nuno Góis <[email protected]>
…ies-sequentially' into proposal/handle-aggregation-queries-sequentially
This is a follow up on #8446 - migrating some metrics (check the commits) - moving event listener registration outside metric calculation (every 2 hs we are adding new listeners) - adding jitter to metric refresh - manually executing some of the tasks immediately to avoid changing the test logic (with jitter now we'd have to force or wait until the first execution of the scheduled task that collect the metrics). We might decide to change this later after the migration - try catch the execution of the task - register metrics now "just registers" and returns functions for refreshing metrics. In the future, we'll return an object with the ability of independently updating specific metrics so we can tweak the frequency of updates
…gation-queries-sequentially
About the changes
We have many aggregation queries that run on a schedule:
unleash/src/lib/metrics.ts
Lines 714 to 719 in f63496d
These staticCounters are usually doing db query aggregations that traverse tables and we run all of them in parallel:
unleash/src/lib/metrics.ts
Lines 410 to 412 in f63496d
This can add strain to the db. This PR suggests a way of handling these queries in a more structured way, allowing us to run them sequentially (therefore spreading the load):
unleash/src/lib/metrics-gauge.ts
Lines 38 to 40 in f02fe87
As an additional benefit, we get both the gauge definition and the queries in a single place:
unleash/src/lib/metrics.ts
Lines 131 to 141 in f02fe87
This PR only tackles 1 metric, and it only focuses on gauges to gather initial feedback. The plan is to migrate these metrics and eventually incorporate more types (e.g. counters)