From ccfadcf5d06e8b3c565dd1937ad68099953fbb17 Mon Sep 17 00:00:00 2001 From: Casie Chen Date: Mon, 10 Jun 2024 16:11:23 -0700 Subject: [PATCH] lint --- pkg/scheduler/queue/queue_test.go | 2 +- .../queue/tenant_querier_assignment.go | 8 ------ pkg/scheduler/queue/tenant_queues_test.go | 11 ++++---- pkg/scheduler/queue/tree_queue.go | 4 +-- pkg/scheduler/queue/tree_queue_test.go | 27 ++++++++++++------- 5 files changed, 26 insertions(+), 26 deletions(-) diff --git a/pkg/scheduler/queue/queue_test.go b/pkg/scheduler/queue/queue_test.go index 737f8e308ae..82591a1f4db 100644 --- a/pkg/scheduler/queue/queue_test.go +++ b/pkg/scheduler/queue/queue_test.go @@ -9,7 +9,6 @@ import ( "context" "errors" "fmt" - promtest "github.com/prometheus/client_golang/prometheus/testutil" "math/rand" "strconv" "strings" @@ -22,6 +21,7 @@ import ( "github.com/grafana/dskit/services" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promauto" + promtest "github.com/prometheus/client_golang/prometheus/testutil" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "golang.org/x/sync/errgroup" diff --git a/pkg/scheduler/queue/tenant_querier_assignment.go b/pkg/scheduler/queue/tenant_querier_assignment.go index 42743e9f8e8..d2293ee7243 100644 --- a/pkg/scheduler/queue/tenant_querier_assignment.go +++ b/pkg/scheduler/queue/tenant_querier_assignment.go @@ -96,14 +96,6 @@ type tenantQuerierAssignments struct { currentQuerier *QuerierID } -func (tqa *tenantQuerierAssignments) getTenant(tenantID TenantID) (*queueTenant, error) { - if tenantID == emptyTenantID { - return nil, ErrInvalidTenantID - } - tenant := tqa.tenantsByID[tenantID] - return tenant, nil -} - // createOrUpdateTenant creates or updates a tenant into the tenant-querier assignment state. // // New tenants are added to the tenant order list and tenant-querier shards are shuffled if needed. diff --git a/pkg/scheduler/queue/tenant_queues_test.go b/pkg/scheduler/queue/tenant_queues_test.go index 858e7463f2a..a7a33ed4786 100644 --- a/pkg/scheduler/queue/tenant_queues_test.go +++ b/pkg/scheduler/queue/tenant_queues_test.go @@ -8,13 +8,14 @@ package queue import ( "context" "fmt" - "github.com/grafana/dskit/httpgrpc" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" "math" "math/rand" "testing" "time" + + "github.com/grafana/dskit/httpgrpc" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func (qb *queueBroker) enqueueObjectsForTests(tenantID TenantID, numObjects int) error { @@ -111,7 +112,7 @@ func TestQueues(t *testing.T) { {buildExpectedObject(tenantTwo.tenantID, 2), tenantTwo}, {buildExpectedObject(tenantOne.tenantID, 5), tenantOne}, } - lastTenantIndex = assertExpectedValuesOnDequeue(t, qb, -1, "querier-2", expectedDequeueVals) + _ = assertExpectedValuesOnDequeue(t, qb, -1, "querier-2", expectedDequeueVals) //[one two three] // confirm fifo by adding a third tenant queue and iterating to it @@ -310,7 +311,7 @@ func TestQueuesOnTerminatingQuerier(t *testing.T) { // After disconnecting querier-2, it's expected to own no queue. qb.tenantQuerierAssignments.removeQuerier("querier-2") - req, tenant, qTwolastTenantIndex, err = qb.dequeueRequestForQuerier(qTwolastTenantIndex, "querier-2") + req, tenant, _, _ = qb.dequeueRequestForQuerier(qTwolastTenantIndex, "querier-2") assert.Nil(t, req) assert.Nil(t, tenant) assert.Equal(t, ErrQuerierShuttingDown, err) diff --git a/pkg/scheduler/queue/tree_queue.go b/pkg/scheduler/queue/tree_queue.go index fa8f067f185..ddeb39e154d 100644 --- a/pkg/scheduler/queue/tree_queue.go +++ b/pkg/scheduler/queue/tree_queue.go @@ -118,9 +118,7 @@ func newNode(name string, depth int, da DequeueAlgorithm) (*Node, error) { if da == nil { return nil, fmt.Errorf("cannot create a node without a defined DequeueAlgorithm") } - switch da.(type) { - case *tenantQuerierAssignments: - tqa := da.(*tenantQuerierAssignments) + if tqa, ok := da.(*tenantQuerierAssignments); ok { tqa.tenantOrderIndex = localQueueIndex - 1 // start from -2 so that we first check local queue if tqa.tenantNodes == nil { tqa.tenantNodes = map[string][]*Node{} diff --git a/pkg/scheduler/queue/tree_queue_test.go b/pkg/scheduler/queue/tree_queue_test.go index cd59330259d..f45ce91a228 100644 --- a/pkg/scheduler/queue/tree_queue_test.go +++ b/pkg/scheduler/queue/tree_queue_test.go @@ -5,10 +5,9 @@ package queue import ( "fmt" "strings" - - //"fmt" - "github.com/stretchr/testify/require" "testing" + + "github.com/stretchr/testify/require" ) func newTenantQuerierAssignments() *tenantQuerierAssignments { @@ -620,12 +619,22 @@ func Test_ChangeTenantQuerierAssignments(t *testing.T) { tree, err := NewTree(state, &roundRobinState{}, &roundRobinState{}) require.NoError(t, err) - err = tree.EnqueueBackByPath(QueuePath{"tenant-1", "query-component-1"}, "query-1") - err = tree.EnqueueBackByPath(QueuePath{"tenant-2", "query-component-1"}, "query-2") - err = tree.EnqueueBackByPath(QueuePath{"tenant-2", "query-component-1"}, "query-3") - err = tree.EnqueueBackByPath(QueuePath{"tenant-2", "query-component-1"}, "query-4") - err = tree.EnqueueBackByPath(QueuePath{"tenant-3", "query-component-1"}, "query-5") - require.NoError(t, err) + type enqueueObj struct { + obj any + path QueuePath + } + enqueueObjs := []enqueueObj{ + {"query-1", QueuePath{"tenant-1", "query-component-1"}}, + {"query-2", QueuePath{"tenant-2", "query-component-1"}}, + {"query-3", QueuePath{"tenant-2", "query-component-1"}}, + {"query-4", QueuePath{"tenant-2", "query-component-1"}}, + {"query-5", QueuePath{"tenant-3", "query-component-1"}}, + } + + for _, eo := range enqueueObjs { + err = tree.EnqueueBackByPath(eo.path, eo.obj) + require.NoError(t, err) + } querier1 := QuerierID("querier-1") querier2 := QuerierID("querier-2")