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

Add counter metric to gate #6008

Merged
merged 4 commits into from
Jan 3, 2023
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 @@ -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.

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()
}