Skip to content

gate: add metric for wait - #11369

Closed
GiedriusS wants to merge 1 commit into
prometheus:mainfrom
vinted:add_wait_metric
Closed

GiedriusS wants to merge 1 commit into
prometheus:mainfrom
vinted:add_wait_metric

Conversation

@GiedriusS

Copy link
Copy Markdown
Contributor

Add a metric that shows how long we need to wait before a request in the remote read handler gets executed. It is useful to have it to understand whether the concurrency limit needs to be lifted or not.

Closes #11365.

Signed-off-by: Giedrius Statkevičius [email protected]

Comment thread util/gate/gate.go Outdated
Namespace: "prometheus",
Subsystem: "api",
Help: "How long was the wait at the gate before the query execution",
Buckets: prometheus.ExponentialBuckets(0.1, 2, 10),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just a question from the sidelines: this adds 13 new time series (10 buckets + Inf bucket + sum + count series). That's not terrible, but I wonder if what you want to get out of the metric could be achieved even simpler? For example, this is how the Linux kernel measures CPU/memory/... resource pressure: https://facebookmicrosites.github.io/psi/docs/overview

Or maybe in this case it could also just be the cumulative number of seconds spent in the queue, without a full distribution? Then if you divide that (rate-ed) by the number of queries, you get the average wait time, which also gives you a good idea of whether you're hitting any limits at all.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@juliusv thanks for the review and sorry for the delay. Your suggestion makes sense. I have updated my code.

@juliusv juliusv left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Great, yeah that's better! Now the one thing I'm still thinking about: the Gate is implemented as a general utility, but it's currently only used in one place (the remote read handler). Currently the metric help text suggests that it's used to gate some queries, but isn't clear about the type of queries it gates. If it's only ever meant to be used by remote read queries, then it should probably say that, or if it's meant to be a general gate however, it might even be incorrect to mention queries at all (if it's ever used by something else). I think the cleanest way to resolve that would be one of these alternatives:

  • A: Just move the gate functionality out of util to the single usage site and make the metric name even more remote-read specific.
  • B: Keep it in util but allow passing in the metric (instead of a registerer) so that the specific caller can name and describe the metric appropriately.
  • C: Keep it in util but allow passing in the name of the thing being gated, which could then be put into a label (would have to think about the proper label name for that).

Honestly A or B are probably most reasonable IMO.

Add a metric that shows how long we need to wait before a request in the
remote read handler gets executed. It is useful to have it to understand
whether the concurrency limit needs to be lifted or not.

Signed-off-by: Giedrius Statkevičius <[email protected]>
@GiedriusS

Copy link
Copy Markdown
Contributor Author

Very valid points! I have done B as it permits code reuse in projects and has maximum flexibility.

@GiedriusS

Copy link
Copy Markdown
Contributor Author

@juliusv kind ping 🤗

Namespace: "prometheus",
Subsystem: "api",
Help: "Total sum of how long was the wait at the gate before query execution",
Name: "gate_total_wait_duration_seconds",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The structure of the code looks good now, but given that we are passing the metric into the gate, we can now also change the metric name and its description to be more specific to how the gate's usage. We have some precedent at

queries: prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: "prometheus",
Subsystem: "api", // TODO: changes to storage in Prometheus 3.0.
Name: "remote_read_queries",
Help: "The current number of remote read queries being executed or waiting.",
}),
for a remote-read-related metric already, so how about prometheus_api_remote_read_wait_duration_seconds_total (for the fully expanded metric name), with a description of Total number of seconds spent waiting at the query gate before remote read query execution?

@roidelapluie

Copy link
Copy Markdown
Member

cc @GiedriusS Can you please address Julius' comment and rebase this pull request please? Thanks!

@beorn7

beorn7 commented Dec 12, 2023

Copy link
Copy Markdown
Contributor

Looking at this during the bug scrub again.

We'll close this for now as there was no follow-up, but we would love to see @GiedriusS (or anyone else) to pick up the work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Gate needs a waiting duration metric

4 participants