Skip to content

Commit 2454692

Browse files
author
kade.lee
committed
add cortex_query_samples_total metric
1 parent df270ee commit 2454692

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

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

0 commit comments

Comments
 (0)