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

Cleanup dangling request queue metrics #6433

Merged
merged 2 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 pkg/frontend/v1/frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ func (f *Frontend) cleanupInactiveUserMetrics(user string) {
f.discardedRequests.DeletePartialMatch(prometheus.Labels{
"user": user,
})
f.requestQueue.CleanupInactiveUserMetrics(user)
}

// RoundTripGRPC round trips a proto (instead of a HTTP request).
Expand Down
7 changes: 5 additions & 2 deletions pkg/frontend/v1/frontend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,14 @@ func TestFrontendMetricsCleanup(t *testing.T) {
# HELP cortex_query_frontend_queue_length Number of queries in the queue.
# TYPE cortex_query_frontend_queue_length gauge
cortex_query_frontend_queue_length{priority="0",type="fifo",user="1"} 0
`), "cortex_query_frontend_queue_length"))
# HELP cortex_request_queue_requests_total Total number of query requests going to the request queue.
# TYPE cortex_request_queue_requests_total counter
cortex_request_queue_requests_total{priority="0",user="1"} 1
`), "cortex_query_frontend_queue_length", "cortex_request_queue_requests_total"))

fr.cleanupInactiveUserMetrics("1")

require.NoError(t, testutil.GatherAndCompare(reg, strings.NewReader(""), "cortex_query_frontend_queue_length"))
require.NoError(t, testutil.GatherAndCompare(reg, strings.NewReader(""), "cortex_query_frontend_queue_length", "cortex_request_queue_requests_total"))
}

testFrontend(t, defaultFrontendConfig(), handler, test, matchMaxConcurrency, nil, reg)
Expand Down
4 changes: 4 additions & 0 deletions pkg/scheduler/queue/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,3 +247,7 @@ func (q *RequestQueue) QuerierDisconnecting() {
func (q *RequestQueue) GetConnectedQuerierWorkersMetric() float64 {
return float64(q.connectedQuerierWorkers.Load())
}

func (q *RequestQueue) CleanupInactiveUserMetrics(user string) {
q.totalRequests.DeletePartialMatch(prometheus.Labels{"user": user})
}
1 change: 1 addition & 0 deletions pkg/scheduler/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,7 @@ func (s *Scheduler) cleanupMetricsForInactiveUser(user string) {
s.discardedRequests.DeletePartialMatch(prometheus.Labels{
"user": user,
})
s.requestQueue.CleanupInactiveUserMetrics(user)
}

func (s *Scheduler) getConnectedFrontendClientsMetric() float64 {
Expand Down
11 changes: 9 additions & 2 deletions pkg/scheduler/scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,15 +430,22 @@ func TestSchedulerMetrics(t *testing.T) {
# TYPE cortex_query_scheduler_queue_length gauge
cortex_query_scheduler_queue_length{priority="0",type="fifo",user="another"} 1
cortex_query_scheduler_queue_length{priority="0",type="fifo",user="test"} 1
`), "cortex_query_scheduler_queue_length"))
# HELP cortex_request_queue_requests_total Total number of query requests going to the request queue.
# TYPE cortex_request_queue_requests_total counter
cortex_request_queue_requests_total{priority="0",user="another"} 1
cortex_request_queue_requests_total{priority="0",user="test"} 1
`), "cortex_query_scheduler_queue_length", "cortex_request_queue_requests_total"))

scheduler.cleanupMetricsForInactiveUser("test")

require.NoError(t, promtest.GatherAndCompare(reg, strings.NewReader(`
# HELP cortex_query_scheduler_queue_length Number of queries in the queue.
# TYPE cortex_query_scheduler_queue_length gauge
cortex_query_scheduler_queue_length{priority="0",type="fifo",user="another"} 1
`), "cortex_query_scheduler_queue_length"))
# HELP cortex_request_queue_requests_total Total number of query requests going to the request queue.
# TYPE cortex_request_queue_requests_total counter
cortex_request_queue_requests_total{priority="0",user="another"} 1
`), "cortex_query_scheduler_queue_length", "cortex_request_queue_requests_total"))
}

func initFrontendLoop(t *testing.T, client schedulerpb.SchedulerForFrontendClient, frontendAddr string) schedulerpb.SchedulerForFrontend_FrontendLoopClient {
Expand Down
Loading