Skip to content

Commit 7b247fc

Browse files
committed
add cortex_query_samples_total metric
Signed-off-by: kade.lee <[email protected]>
1 parent df270ee commit 7b247fc

File tree

3 files changed

+22
-12
lines changed

3 files changed

+22
-12
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
* [ENHANCEMENT] Ruler: Add support for filtering by `state` and `health` field on Rules API. #6040
4141
* [ENHANCEMENT] Compactor: Split cleaner cycle for active and deleted tenants. #6112
4242
* [ENHANCEMENT] Compactor: Introduce cleaner visit marker. #6113
43+
* [ENHANCEMENT] Query Frontend: Add cortex_query_samples_total metric. #6142
4344
* [BUGFIX] Configsdb: Fix endline issue in db password. #5920
4445
* [BUGFIX] Ingester: Fix `user` and `type` labels for the `cortex_ingester_tsdb_head_samples_appended_total` TSDB metric. #5952
4546
* [BUGFIX] Querier: Enforce max query length check for `/api/v1/series` API even though `ignoreMaxQueryLength` is set to true. #6018

pkg/frontend/transport/handler.go

+8
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ type Handler struct {
9191
// Metrics.
9292
querySeconds *prometheus.CounterVec
9393
querySeries *prometheus.CounterVec
94+
querySamples *prometheus.CounterVec
9495
queryChunkBytes *prometheus.CounterVec
9596
queryDataBytes *prometheus.CounterVec
9697
rejectedQueries *prometheus.CounterVec
@@ -116,6 +117,11 @@ func NewHandler(cfg HandlerConfig, roundTripper http.RoundTripper, log log.Logge
116117
Help: "Number of series fetched to execute a query.",
117118
}, []string{"user"})
118119

120+
h.querySamples = promauto.With(reg).NewCounterVec(prometheus.CounterOpts{
121+
Name: "cortex_query_samples_total",
122+
Help: "Number of samples to execute a query.",
123+
}, []string{"user"})
124+
119125
h.queryChunkBytes = promauto.With(reg).NewCounterVec(prometheus.CounterOpts{
120126
Name: "cortex_query_fetched_chunks_bytes_total",
121127
Help: "Size of all chunks fetched to execute a query in bytes.",
@@ -137,6 +143,7 @@ func NewHandler(cfg HandlerConfig, roundTripper http.RoundTripper, log log.Logge
137143
h.activeUsers = util.NewActiveUsersCleanupWithDefaultValues(func(user string) {
138144
h.querySeconds.DeleteLabelValues(user)
139145
h.querySeries.DeleteLabelValues(user)
146+
h.querySamples.DeleteLabelValues(user)
140147
h.queryChunkBytes.DeleteLabelValues(user)
141148
h.queryDataBytes.DeleteLabelValues(user)
142149
if err := util.DeleteMatchingLabels(h.rejectedQueries, map[string]string{"user": user}); err != nil {
@@ -305,6 +312,7 @@ func (f *Handler) reportQueryStats(r *http.Request, userID string, queryString u
305312
// Track stats.
306313
f.querySeconds.WithLabelValues(userID).Add(wallTime.Seconds())
307314
f.querySeries.WithLabelValues(userID).Add(float64(numSeries))
315+
f.querySamples.WithLabelValues(userID).Add(float64(numSamples))
308316
f.queryChunkBytes.WithLabelValues(userID).Add(float64(numChunkBytes))
309317
f.queryDataBytes.WithLabelValues(userID).Add(float64(numDataBytes))
310318
f.activeUsers.UpdateUserTimestamp(userID, time.Now())

pkg/frontend/transport/handler_test.go

+13-12
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ func TestHandler_ServeHTTP(t *testing.T) {
188188
{
189189
name: "test handler with stats enabled",
190190
cfg: HandlerConfig{QueryStatsEnabled: true},
191-
expectedMetrics: 3,
191+
expectedMetrics: 4,
192192
roundTripperFunc: roundTripper,
193193
expectedStatusCode: http.StatusOK,
194194
},
@@ -202,7 +202,7 @@ func TestHandler_ServeHTTP(t *testing.T) {
202202
{
203203
name: "test handler with reasonResponseTooLarge",
204204
cfg: HandlerConfig{QueryStatsEnabled: true},
205-
expectedMetrics: 3,
205+
expectedMetrics: 4,
206206
roundTripperFunc: roundTripperFunc(func(req *http.Request) (*http.Response, error) {
207207
return &http.Response{
208208
StatusCode: http.StatusRequestEntityTooLarge,
@@ -218,7 +218,7 @@ func TestHandler_ServeHTTP(t *testing.T) {
218218
{
219219
name: "test handler with reasonTooManyRequests",
220220
cfg: HandlerConfig{QueryStatsEnabled: true},
221-
expectedMetrics: 3,
221+
expectedMetrics: 4,
222222
roundTripperFunc: roundTripperFunc(func(req *http.Request) (*http.Response, error) {
223223
return &http.Response{
224224
StatusCode: http.StatusTooManyRequests,
@@ -234,7 +234,7 @@ func TestHandler_ServeHTTP(t *testing.T) {
234234
{
235235
name: "test handler with reasonTooManySamples",
236236
cfg: HandlerConfig{QueryStatsEnabled: true},
237-
expectedMetrics: 3,
237+
expectedMetrics: 4,
238238
roundTripperFunc: roundTripperFunc(func(req *http.Request) (*http.Response, error) {
239239
return &http.Response{
240240
StatusCode: http.StatusUnprocessableEntity,
@@ -250,7 +250,7 @@ func TestHandler_ServeHTTP(t *testing.T) {
250250
{
251251
name: "test handler with reasonTooLongRange",
252252
cfg: HandlerConfig{QueryStatsEnabled: true},
253-
expectedMetrics: 3,
253+
expectedMetrics: 4,
254254
roundTripperFunc: roundTripperFunc(func(req *http.Request) (*http.Response, error) {
255255
return &http.Response{
256256
StatusCode: http.StatusUnprocessableEntity,
@@ -266,7 +266,7 @@ func TestHandler_ServeHTTP(t *testing.T) {
266266
{
267267
name: "test handler with reasonSeriesFetched",
268268
cfg: HandlerConfig{QueryStatsEnabled: true},
269-
expectedMetrics: 3,
269+
expectedMetrics: 4,
270270
roundTripperFunc: roundTripperFunc(func(req *http.Request) (*http.Response, error) {
271271
return &http.Response{
272272
StatusCode: http.StatusUnprocessableEntity,
@@ -282,7 +282,7 @@ func TestHandler_ServeHTTP(t *testing.T) {
282282
{
283283
name: "test handler with reasonChunksFetched",
284284
cfg: HandlerConfig{QueryStatsEnabled: true},
285-
expectedMetrics: 3,
285+
expectedMetrics: 4,
286286
roundTripperFunc: roundTripperFunc(func(req *http.Request) (*http.Response, error) {
287287
return &http.Response{
288288
StatusCode: http.StatusUnprocessableEntity,
@@ -298,7 +298,7 @@ func TestHandler_ServeHTTP(t *testing.T) {
298298
{
299299
name: "test handler with reasonChunkBytesFetched",
300300
cfg: HandlerConfig{QueryStatsEnabled: true},
301-
expectedMetrics: 3,
301+
expectedMetrics: 4,
302302
roundTripperFunc: roundTripperFunc(func(req *http.Request) (*http.Response, error) {
303303
return &http.Response{
304304
StatusCode: http.StatusUnprocessableEntity,
@@ -314,7 +314,7 @@ func TestHandler_ServeHTTP(t *testing.T) {
314314
{
315315
name: "test handler with reasonDataBytesFetched",
316316
cfg: HandlerConfig{QueryStatsEnabled: true},
317-
expectedMetrics: 3,
317+
expectedMetrics: 4,
318318
roundTripperFunc: roundTripperFunc(func(req *http.Request) (*http.Response, error) {
319319
return &http.Response{
320320
StatusCode: http.StatusUnprocessableEntity,
@@ -330,7 +330,7 @@ func TestHandler_ServeHTTP(t *testing.T) {
330330
{
331331
name: "test handler with reasonSeriesLimitStoreGateway",
332332
cfg: HandlerConfig{QueryStatsEnabled: true},
333-
expectedMetrics: 3,
333+
expectedMetrics: 4,
334334
roundTripperFunc: roundTripperFunc(func(req *http.Request) (*http.Response, error) {
335335
return &http.Response{
336336
StatusCode: http.StatusUnprocessableEntity,
@@ -346,7 +346,7 @@ func TestHandler_ServeHTTP(t *testing.T) {
346346
{
347347
name: "test handler with reasonChunksLimitStoreGateway",
348348
cfg: HandlerConfig{QueryStatsEnabled: true},
349-
expectedMetrics: 3,
349+
expectedMetrics: 4,
350350
roundTripperFunc: roundTripperFunc(func(req *http.Request) (*http.Response, error) {
351351
return &http.Response{
352352
StatusCode: http.StatusUnprocessableEntity,
@@ -362,7 +362,7 @@ func TestHandler_ServeHTTP(t *testing.T) {
362362
{
363363
name: "test handler with reasonBytesLimitStoreGateway",
364364
cfg: HandlerConfig{QueryStatsEnabled: true},
365-
expectedMetrics: 3,
365+
expectedMetrics: 4,
366366
roundTripperFunc: roundTripperFunc(func(req *http.Request) (*http.Response, error) {
367367
return &http.Response{
368368
StatusCode: http.StatusUnprocessableEntity,
@@ -393,6 +393,7 @@ func TestHandler_ServeHTTP(t *testing.T) {
393393
reg,
394394
"cortex_query_seconds_total",
395395
"cortex_query_fetched_series_total",
396+
"cortex_query_samples_total",
396397
"cortex_query_fetched_chunks_bytes_total",
397398
)
398399

0 commit comments

Comments
 (0)