Skip to content

util/gate: add wait duration histogram metric#18403

Open
AdeshDeshmukh wants to merge 1 commit intoprometheus:mainfrom
AdeshDeshmukh:feat/gate-waiting-metric
Open

util/gate: add wait duration histogram metric#18403
AdeshDeshmukh wants to merge 1 commit intoprometheus:mainfrom
AdeshDeshmukh:feat/gate-waiting-metric

Conversation

@AdeshDeshmukh
Copy link
Copy Markdown

What this PR does

Adds prometheus.Histogram to Gate to track how long operations wait for a gate slot. This allows operators to identify whether the gate is becoming a bottleneck.

Design

  • Gate accepts prometheus.Registerer for flexible metric registration
  • Caller provides metric name prefix (e.g., prometheus_remote_read_handler)
  • Histogram observed after successful gate acquisition
  • Optional registration: if registerer is nil, no metric recorded

Implementation

  • Gate.New() now accepts (length, registerer, metricPrefix) parameters
  • Metric name: "{metricPrefix}_gate_wait_duration_seconds"
  • Time measured from Start() call to gate slot acquisition
  • Follows prometheus pattern used in util/notifications

Testing

  • Tests verify metric observation for normal operation
  • Tests verify nil registerer (optional registration) works correctly
  • Tests verify cancelled contexts don't record metrics
  • All tests pass: 3/3 ✅

Which issue(s) does the PR fix:

Fixes #11365


Release notes for end users

[ENHANCEMENT] util/gate: Add gate_wait_duration_seconds histogram metric to track how long requests wait for gate availability. Callers control metric naming via the Registerer pattern, enabling both prometheus_remote_read_handler_gate_wait_duration_seconds and component-specific variants.

Adds prometheus.Histogram to Gate to track how long operations wait
for a gate slot. This allows operators to identify whether the gate
is becoming a bottleneck.

Design:
- Gate accepts prometheus.Registerer for flexible metric registration
- Caller provides metric name prefix (e.g., prometheus_remote_read_handler)
- Histogram observed after successful gate acquisition
- Optional registration: if registerer is nil, no metric recorded

Implementation:
- Gate.New() now accepts (length, registerer, metricPrefix) parameters
- Metric name: "{metricPrefix}_gate_wait_duration_seconds"
- Time measured from Start() call to gate slot acquisition
- Follows prometheus pattern used in util/notifications

Testing:
- Tests verify metric observation for normal operation
- Tests verify nil registerer (optional registration) works correctly
- Tests verify cancelled contexts don't record metrics

Fixes prometheus#11365

Signed-off-by: AdeshDeshmukh <[email protected]>
@bboreham
Copy link
Copy Markdown
Member

PR #18355 also claims to fix the same issue. Is there some particular reason why we should prefer this one?

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

2 participants