diff --git a/CHANGELOG.md b/CHANGELOG.md index aba37ddea6..81a27b5746 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ We use *breaking :warning:* to mark changes that are not backward compatible (re ### Added - [#5990](https://github.com/thanos-io/thanos/pull/5990) Cache/Redis: add support for Redis Sentinel via new option `master_name`. +- [#6008](https://github.com/thanos-io/thanos/pull/6008) *: Add counter metric `gate_queries_total` to gate. ## [v0.30.0](https://github.com/thanos-io/thanos/tree/release-0.30) - in progress. diff --git a/pkg/gate/gate.go b/pkg/gate/gate.go index ae6ecf9872..36a16a3112 100644 --- a/pkg/gate/gate.go +++ b/pkg/gate/gate.go @@ -21,6 +21,10 @@ var ( Name: "gate_queries_in_flight", Help: "Number of queries that are currently in flight.", } + TotalCounterOpts = prometheus.CounterOpts{ + Name: "gate_queries_total", + Help: "Total number of queries.", + } DurationHistogramOpts = prometheus.HistogramOpts{ Name: "gate_duration_seconds", Help: "How many seconds it took for queries to wait at the gate.", @@ -87,9 +91,12 @@ func New(reg prometheus.Registerer, maxConcurrent int) Gate { return InstrumentGateDuration( promauto.With(reg).NewHistogram(DurationHistogramOpts), - InstrumentGateInFlight( - promauto.With(reg).NewGauge(InFlightGaugeOpts), - promgate.New(maxConcurrent), + InstrumentGateTotal( + promauto.With(reg).NewCounter(TotalCounterOpts), + InstrumentGateInFlight( + promauto.With(reg).NewGauge(InFlightGaugeOpts), + promgate.New(maxConcurrent), + ), ), ) } @@ -159,3 +166,31 @@ func (g *instrumentedInFlightGate) Done() { g.inflight.Dec() g.g.Done() } + +type instrumentedTotalGate struct { + g Gate + total prometheus.Counter +} + +// InstrumentGateTotal instruments the provided Gate to track total requests. +func InstrumentGateTotal(total prometheus.Counter, g Gate) Gate { + return &instrumentedTotalGate{ + g: g, + total: total, + } +} + +// Start implements the Gate interface. +func (g *instrumentedTotalGate) Start(ctx context.Context) error { + g.total.Inc() + if err := g.g.Start(ctx); err != nil { + return err + } + + return nil +} + +// Done implements the Gate interface. +func (g *instrumentedTotalGate) Done() { + g.g.Done() +}