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 new query stats metrics to track prometheus querystats #6228

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

SungJin1212
Copy link
Contributor

What this PR does:
Add new query stats metrics cortex_query_total_queryable_samples_total and cortex_query_peak_samples.
These track TotalQueryableSamples and PeakSamples for each in https://github.com/prometheus/prometheus/blob/main/util/stats/query_stats.go

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-metrics-for-queryable-samples-and-peak-samples branch 4 times, most recently from 0a571de to d4ddae7 Compare September 23, 2024 12:20

h.queryPeakSamples = promauto.With(reg).NewCounterVec(prometheus.CounterOpts{
Name: "cortex_query_peak_samples_total",
Help: "Highest count of samples considered to execute a query.",
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please explain the usecase of tracking peak samples using a counter metric?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think like promQL: sum by (user) (irate(cortex_query_peak_samples_total[5m])), the cortex user can track the rate of how many samples are loaded in memory for each tenant's overall queries.

One usecase is:

  • The cortex user can track query memory usage (used by loaded samples) for each tenant and turn promQL to reduce query memory usage.

Copy link
Contributor

Choose a reason for hiding this comment

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

OK. For a counter metric I feel it is more useful to just track total samples, not peak samples.
Would it be more useful to use native histogram instead?

Copy link
Contributor Author

@SungJin1212 SungJin1212 Sep 26, 2024

Choose a reason for hiding this comment

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

Yes, I think the histogram is the best.

@@ -122,6 +124,16 @@ func NewHandler(cfg HandlerConfig, roundTripper http.RoundTripper, log log.Logge
Help: "Number of samples fetched to execute a query.",
}, []string{"user"})

h.queryTotalQueryableSamples = promauto.With(reg).NewCounterVec(prometheus.CounterOpts{
Name: "cortex_query_total_queryable_samples_total",
Help: "Number of total queryable samples to execute a query.",
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel queryable samples is a bit confusing.
What about cortex_query_samples_processed_total or cortex_query_samples_scanned_total?
You can add a comment to reference it to https://github.com/prometheus/prometheus/blob/main/util/stats/query_stats.go#L237

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For me, cortex_query_samples_processed_total is more good. Thank you!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How about changing the variable name queryTotalQueryableSamples to queryProcessedSamples and querySamples to queryFetchedSamples?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can keep queryTotalQueryableSamples as it is clear that it refers to Total Samples.
Makes sense to rename querySamples to queryFetchedSamples.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have fixed it.

@SungJin1212 SungJin1212 force-pushed the Add-metrics-for-queryable-samples-and-peak-samples branch 3 times, most recently from afea4c7 to 1e37e70 Compare September 27, 2024 01:47
@SungJin1212
Copy link
Contributor Author

@yeya24
Could you please take a look?

@SungJin1212 SungJin1212 force-pushed the Add-metrics-for-queryable-samples-and-peak-samples branch from 1e37e70 to 0cfa84b Compare October 1, 2024 11:59
Signed-off-by: SungJin1212 <tjdwls1201@gmail.com>
@SungJin1212 SungJin1212 force-pushed the Add-metrics-for-queryable-samples-and-peak-samples branch from 0cfa84b to 797b6ee Compare October 3, 2024 00:34
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.

2 participants