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

Add query metrics to ruler query stats #6173

Conversation

SungJin1212
Copy link
Member

@SungJin1212 SungJin1212 commented Aug 20, 2024

What this PR does:
Add query statistics metrics to Ruler when --ruler.query-stats-enabled=true to track how many data are fetched by the alerting rule or recording rules for each tenants.
Which issue(s) this PR fixes:
Fixes #

Checklist

  • Tests updated
  • Documentation added
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]

@SungJin1212 SungJin1212 force-pushed the Add-query-metrics-to-ruler-query-stats branch 2 times, most recently from 0f39329 to 2ef5183 Compare August 20, 2024 04:42
@pull-request-size pull-request-size bot added size/M and removed size/L labels Aug 20, 2024
@SungJin1212 SungJin1212 force-pushed the Add-query-metrics-to-ruler-query-stats branch 2 times, most recently from dbb3cca to f0d770d Compare August 21, 2024 01:36
@pull-request-size pull-request-size bot added size/L and removed size/M labels Aug 21, 2024
Comment on lines 315 to 320
queryTime := evalMetrics.RulerQuerySeconds.WithLabelValues(userID)
querySeries := evalMetrics.RulerQuerySeries.WithLabelValues(userID)
querySample := evalMetrics.RulerQuerySamples.WithLabelValues(userID)
queryChunkBytes := evalMetrics.RulerQuerySamples.WithLabelValues(userID)
queryDataBytes := evalMetrics.RulerQueryDataBytes.WithLabelValues(userID)
queryFunc = RecordAndReportRuleQueryMetrics(metricsQueryFunc, queryTime, querySeries, querySample, queryChunkBytes, queryDataBytes, logger)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I think you can pass just evalMetrics as parameter to RecordAndReportRuleQueryMetrics and to all initialization inside it.

Suggested change
queryTime := evalMetrics.RulerQuerySeconds.WithLabelValues(userID)
querySeries := evalMetrics.RulerQuerySeries.WithLabelValues(userID)
querySample := evalMetrics.RulerQuerySamples.WithLabelValues(userID)
queryChunkBytes := evalMetrics.RulerQuerySamples.WithLabelValues(userID)
queryDataBytes := evalMetrics.RulerQueryDataBytes.WithLabelValues(userID)
queryFunc = RecordAndReportRuleQueryMetrics(metricsQueryFunc, queryTime, querySeries, querySample, queryChunkBytes, queryDataBytes, logger)
queryFunc = RecordAndReportRuleQueryMetrics(metricsQueryFunc, userID, evalMetrics)

This way if new query stats metrics are added in the future, we don't need to change function signatures.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

However this will not be consistent with the other functions, such as MetricsQueryFunc and NewPusherAppandable, therefore I think it is ok to ignore my nit, unless anyone wants to chime in.

@rapphil
Copy link
Contributor

rapphil commented Aug 23, 2024

Overall this change looks good to me. It is a useful addition to the project and will help troubleshoot issues faster.

@SungJin1212 SungJin1212 force-pushed the Add-query-metrics-to-ruler-query-stats branch from f0d770d to ed9acee Compare August 24, 2024 00:20
@SungJin1212
Copy link
Member Author

@rapphil
Thank you for the review. It would be more clean to take your approach. So, I have updated the pr!

@SungJin1212
Copy link
Member Author

@alanprot
Could you please take a look?

Comment on lines 234 to 238
queryTime := evalMetrics.RulerQuerySeconds.WithLabelValues(userID)
querySeries := evalMetrics.RulerQuerySeries.WithLabelValues(userID)
querySample := evalMetrics.RulerQuerySamples.WithLabelValues(userID)
queryChunkBytes := evalMetrics.RulerQueryChunkBytes.WithLabelValues(userID)
queryDataBytes := evalMetrics.RulerQueryDataBytes.WithLabelValues(userID)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these should be outside of the scope of this anonymous function. they should be in the scope of RecordAndReportRuleQueryMetrics.

Copy link
Member Author

@SungJin1212 SungJin1212 Aug 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have fixed it. Thank you.

@SungJin1212 SungJin1212 force-pushed the Add-query-metrics-to-ruler-query-stats branch from ed9acee to 9a75d4c Compare August 27, 2024 01:14
@rapphil
Copy link
Contributor

rapphil commented Aug 28, 2024

LGTM.

Thanks for this valuable contribution

@alanprot
Copy link
Member

Nice.. this LGTM as well.

@SungJin1212
Copy link
Member Author

@alanprot
Could you please merge this pr?

CHANGELOG.md Outdated
@@ -54,6 +54,7 @@
* [ENHANCEMENT] Compactor: Introduce cleaner visit marker. #6113
* [ENHANCEMENT] Query Frontend: Add cortex_query_samples_total metric. #6142
* [ENHANCEMENT] Ingester: Implement metadata API limit. #6128
* [ENHANCEMENT] Ruler: Add query statistics metrics when --ruler.query-stats-enabled=true. #6173
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to fix changelog. Can we move this to master section?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have moved it.

@SungJin1212 SungJin1212 force-pushed the Add-query-metrics-to-ruler-query-stats branch from 9a75d4c to b75be24 Compare August 29, 2024 01:40
@yeya24 yeya24 merged commit 2f4e1fd into cortexproject:master Aug 29, 2024
16 checks passed
danielblando pushed a commit to danielblando/cortex that referenced this pull request Sep 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants