Skip to content

Commit

Permalink
Add counter metric to gate (#6008)
Browse files Browse the repository at this point in the history
* add counter metric to gate

Signed-off-by: Ben Ye <benye@amazon.com>

* update changelog

Signed-off-by: Ben Ye <benye@amazon.com>

* lint

Signed-off-by: Ben Ye <benye@amazon.com>

* update changelog

Signed-off-by: Ben Ye <benye@amazon.com>

Signed-off-by: Ben Ye <benye@amazon.com>
  • Loading branch information
yeya24 authored Jan 3, 2023
1 parent 6ef005c commit 3327c51
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

### Fixed
- [#5995] (https://github.com/thanos-io/thanos/pull/5993) Sidecar: Loads the TLS certificate during startup.
Expand Down
41 changes: 38 additions & 3 deletions pkg/gate/gate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down Expand Up @@ -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),
),
),
)
}
Expand Down Expand Up @@ -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()
}

0 comments on commit 3327c51

Please sign in to comment.