Skip to content

Commit a602a7f

Browse files
authored
Add counter metrics for total requests going to queue (#5030)
* add counter metrics for total requests going to queue Signed-off-by: Ben Ye <[email protected]> * update changelog Signed-off-by: Ben Ye <[email protected]> * fix lint Signed-off-by: Ben Ye <[email protected]> * lint Signed-off-by: Ben Ye <[email protected]> Signed-off-by: Ben Ye <[email protected]>
1 parent 30b8aa5 commit a602a7f

File tree

6 files changed

+17
-4
lines changed

6 files changed

+17
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
* [FEATURE] Ingester: Added `-blocks-storage.tsdb.head-chunks-write-queue-size` allowing to configure the size of the in-memory queue used before flushing chunks to the disk . #5000
1212
* [FEATURE] Query Frontend: Log query params in query frontend even if error happens. #5005
1313
* [FEATURE] Ingester: Enable snapshotting of In-memory TSDB on disk during shutdown via `-blocks-storage.tsdb.memory-snapshot-on-shutdown`. #5011
14+
* [FEATURE] Query Frontend/Scheduler: Add a new counter metric `cortex_request_queue_requests_total` for total requests going to queue. #5030
1415
* [BUGFIX] Updated `golang.org/x/net` dependency to fix CVE-2022-27664. #5008
1516

1617
## 1.14.0 2022-12-02

pkg/frontend/v1/frontend.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func New(cfg Config, limits Limits, log log.Logger, registerer prometheus.Regist
112112
}),
113113
}
114114

115-
f.requestQueue = queue.NewRequestQueue(cfg.MaxOutstandingPerTenant, cfg.QuerierForgetDelay, f.queueLength, f.discardedRequests, f.limits)
115+
f.requestQueue = queue.NewRequestQueue(cfg.MaxOutstandingPerTenant, cfg.QuerierForgetDelay, f.queueLength, f.discardedRequests, f.limits, registerer)
116116
f.activeUsers = util.NewActiveUsersCleanupWithDefaultValues(f.cleanupInactiveUserMetrics)
117117

118118
var err error

pkg/frontend/v1/frontend_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ func TestFrontendCheckReady(t *testing.T) {
133133
prometheus.NewGaugeVec(prometheus.GaugeOpts{}, []string{"user"}),
134134
prometheus.NewCounterVec(prometheus.CounterOpts{}, []string{"user"}),
135135
limits,
136+
nil,
136137
),
137138
}
138139
for i := 0; i < tt.connectedClients; i++ {

pkg/scheduler/queue/queue.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77

88
"github.com/pkg/errors"
99
"github.com/prometheus/client_golang/prometheus"
10+
"github.com/prometheus/client_golang/prometheus/promauto"
1011
"go.uber.org/atomic"
1112

1213
"github.com/cortexproject/cortex/pkg/util/services"
@@ -58,15 +59,20 @@ type RequestQueue struct {
5859
stopped bool
5960

6061
queueLength *prometheus.GaugeVec // Per user and reason.
62+
totalRequests *prometheus.CounterVec // Per user.
6163
discardedRequests *prometheus.CounterVec // Per user.
6264
}
6365

64-
func NewRequestQueue(maxOutstandingPerTenant int, forgetDelay time.Duration, queueLength *prometheus.GaugeVec, discardedRequests *prometheus.CounterVec, limits Limits) *RequestQueue {
66+
func NewRequestQueue(maxOutstandingPerTenant int, forgetDelay time.Duration, queueLength *prometheus.GaugeVec, discardedRequests *prometheus.CounterVec, limits Limits, registerer prometheus.Registerer) *RequestQueue {
6567
q := &RequestQueue{
6668
queues: newUserQueues(maxOutstandingPerTenant, forgetDelay, limits),
6769
connectedQuerierWorkers: atomic.NewInt32(0),
6870
queueLength: queueLength,
69-
discardedRequests: discardedRequests,
71+
totalRequests: promauto.With(registerer).NewCounterVec(prometheus.CounterOpts{
72+
Name: "cortex_request_queue_requests_total",
73+
Help: "Total number of query requests going to the request queue.",
74+
}, []string{"user"}),
75+
discardedRequests: discardedRequests,
7076
}
7177

7278
q.cond = sync.NewCond(&q.mtx)
@@ -94,6 +100,7 @@ func (q *RequestQueue) EnqueueRequest(userID string, req Request, maxQueriers in
94100
return errors.New("no queue found")
95101
}
96102

103+
q.totalRequests.WithLabelValues(userID).Inc()
97104
select {
98105
case queue <- req:
99106
q.queueLength.WithLabelValues(userID).Inc()

pkg/scheduler/queue/queue_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ func BenchmarkGetNextRequest(b *testing.B) {
2727
prometheus.NewGaugeVec(prometheus.GaugeOpts{}, []string{"user"}),
2828
prometheus.NewCounterVec(prometheus.CounterOpts{}, []string{"user"}),
2929
MockLimits{MaxOutstanding: 100},
30+
nil,
3031
)
3132
queues = append(queues, queue)
3233

@@ -85,6 +86,7 @@ func BenchmarkQueueRequest(b *testing.B) {
8586
prometheus.NewGaugeVec(prometheus.GaugeOpts{}, []string{"user"}),
8687
prometheus.NewCounterVec(prometheus.CounterOpts{}, []string{"user"}),
8788
MockLimits{MaxOutstanding: 100},
89+
nil,
8890
)
8991

9092
for ix := 0; ix < queriers; ix++ {
@@ -119,6 +121,7 @@ func TestRequestQueue_GetNextRequestForQuerier_ShouldGetRequestAfterReshardingBe
119121
prometheus.NewGaugeVec(prometheus.GaugeOpts{}, []string{"user"}),
120122
prometheus.NewCounterVec(prometheus.CounterOpts{}, []string{"user"}),
121123
MockLimits{MaxOutstanding: 100},
124+
nil,
122125
)
123126

124127
// Start the queue service.

pkg/scheduler/scheduler.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ func NewScheduler(cfg Config, limits Limits, log log.Logger, registerer promethe
111111
Name: "cortex_query_scheduler_discarded_requests_total",
112112
Help: "Total number of query requests discarded.",
113113
}, []string{"user"})
114-
s.requestQueue = queue.NewRequestQueue(cfg.MaxOutstandingPerTenant, cfg.QuerierForgetDelay, s.queueLength, s.discardedRequests, s.limits)
114+
115+
s.requestQueue = queue.NewRequestQueue(cfg.MaxOutstandingPerTenant, cfg.QuerierForgetDelay, s.queueLength, s.discardedRequests, s.limits, registerer)
115116

116117
s.queueDuration = promauto.With(registerer).NewHistogram(prometheus.HistogramOpts{
117118
Name: "cortex_query_scheduler_queue_duration_seconds",

0 commit comments

Comments
 (0)