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

instrumented gate: observe permitted and non-permitted queries separately #512

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@
* `gate_duration_seconds`
* `kv_request_duration_seconds`
* `operation_duration_seconds`
* [ENHANCEMENT] Add `outcome` label to `gate_duration_seconds` metric. Possible values are `rejected_canceled`, `rejected_deadline_exceeded`, `rejected_other`, and `permitted`. #512
* [BUGFIX] spanlogger: Support multiple tenant IDs. #59
* [BUGFIX] Memberlist: fixed corrupted packets when sending compound messages with more than 255 messages or messages bigger than 64KB. #85
* [BUGFIX] Ring: `ring_member_ownership_percent` and `ring_tokens_owned` metrics are not updated on scale down. #109
Expand Down
20 changes: 14 additions & 6 deletions gate/gate.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ func NewInstrumented(reg prometheus.Registerer, maxConcurrent int, gate Gate) Ga
Name: "gate_queries_in_flight",
Help: "Number of queries that are currently in flight.",
}),
duration: promauto.With(reg).NewHistogram(prometheus.HistogramOpts{
duration: promauto.With(reg).NewHistogramVec(prometheus.HistogramOpts{
Name: "gate_duration_seconds",
Help: "How many seconds it took for queries to wait at the gate.",
Buckets: []float64{0.01, 0.1, 0.3, 0.6, 1, 3, 6, 9, 20, 30, 60, 90, 120, 240, 360, 720},
// Use defaults recommended by Prometheus for native histograms.
NativeHistogramBucketFactor: 1.1,
NativeHistogramMaxBucketNumber: 100,
NativeHistogramMinResetDuration: time.Hour,
}),
}, []string{"outcome"}),
}

g.max.Set(float64(maxConcurrent))
Expand All @@ -84,20 +84,28 @@ type instrumentedGate struct {

max prometheus.Gauge
inflight prometheus.Gauge
duration prometheus.Histogram
duration *prometheus.HistogramVec
}

func (g *instrumentedGate) Start(ctx context.Context) error {
start := time.Now()
defer func() {
g.duration.Observe(time.Since(start).Seconds())
}()

err := g.gate.Start(ctx)
if err != nil {
var reason string
switch {
case errors.Is(err, context.Canceled):
reason = "rejected_canceled"
case errors.Is(err, context.DeadlineExceeded):
reason = "rejected_deadline_exceeded"
default:
reason = "rejected_other"
}
g.duration.WithLabelValues(reason).Observe(time.Since(start).Seconds())
return err
}

g.duration.WithLabelValues("permitted").Observe(time.Since(start).Seconds())
g.inflight.Inc()
return nil
}
Expand Down