Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
Signed-off-by: Justin Jung <[email protected]>
  • Loading branch information
justinjung04 committed Nov 9, 2023
1 parent 0f8f2be commit e718607
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 9 deletions.
2 changes: 1 addition & 1 deletion docs/configuration/single-process-config-blocks-local.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,4 @@ ruler:
ruler_storage:
backend: local
local:
directory: /tmp/cortex/rules
directory: /tmp/cortex/rules
8 changes: 6 additions & 2 deletions pkg/frontend/v1/frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,12 @@ func (f *Frontend) stopping(_ error) error {
}

func (f *Frontend) cleanupInactiveUserMetrics(user string) {
f.queueLength.DeleteLabelValues(user)
f.discardedRequests.DeleteLabelValues(user)
f.queueLength.DeletePartialMatch(prometheus.Labels{
"user": user,
})
f.discardedRequests.DeletePartialMatch(prometheus.Labels{
"user": user,
})
}

// RoundTripGRPC round trips a proto (instead of a HTTP request).
Expand Down
2 changes: 1 addition & 1 deletion pkg/frontend/v1/frontend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ func TestFrontendMetricsCleanup(t *testing.T) {
require.NoError(t, testutil.GatherAndCompare(reg, strings.NewReader(`
# HELP cortex_query_frontend_queue_length Number of queries in the queue.
# TYPE cortex_query_frontend_queue_length gauge
cortex_query_frontend_queue_length{user="1"} 0
cortex_query_frontend_queue_length{priority="0",user="1"} 0
`), "cortex_query_frontend_queue_length"))

fr.cleanupInactiveUserMetrics("1")
Expand Down
8 changes: 6 additions & 2 deletions pkg/scheduler/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -520,8 +520,12 @@ func (s *Scheduler) stopping(_ error) error {
}

func (s *Scheduler) cleanupMetricsForInactiveUser(user string) {
s.queueLength.DeleteLabelValues(user)
s.discardedRequests.DeleteLabelValues(user)
s.queueLength.DeletePartialMatch(prometheus.Labels{
"user": user,
})
s.discardedRequests.DeletePartialMatch(prometheus.Labels{
"user": user,
})
}

func (s *Scheduler) getConnectedFrontendClientsMetric() float64 {
Expand Down
6 changes: 3 additions & 3 deletions pkg/scheduler/scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,16 +430,16 @@ func TestSchedulerMetrics(t *testing.T) {
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{user="another"} 1
cortex_query_scheduler_queue_length{user="test"} 1
cortex_query_scheduler_queue_length{priority="0",user="another"} 1
cortex_query_scheduler_queue_length{priority="0",user="test"} 1
`), "cortex_query_scheduler_queue_length"))

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{user="another"} 1
cortex_query_scheduler_queue_length{priority="0",user="another"} 1
`), "cortex_query_scheduler_queue_length"))
}

Expand Down

0 comments on commit e718607

Please sign in to comment.