Skip to content

Commit

Permalink
Fix tests and lint
Browse files Browse the repository at this point in the history
  • Loading branch information
chencs committed Aug 13, 2024
1 parent be318c3 commit 67e4d02
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 19 deletions.
18 changes: 9 additions & 9 deletions pkg/frontend/v2/frontend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func setupFrontendWithConcurrencyAndServerOptions(t *testing.T, reg prometheus.R
grpcPort, err := strconv.Atoi(p)
require.NoError(t, err)

cfg := Config{AdditionalQueryQueueDimensionsEnabled: true}
cfg := Config{}
flagext.DefaultValues(&cfg)
cfg.SchedulerAddress = l.Addr().String()
cfg.WorkerConcurrency = concurrency
Expand Down Expand Up @@ -142,7 +142,7 @@ func TestFrontendBasicWorkflow(t *testing.T) {
})

req := &httpgrpc.HTTPRequest{
Url: "/api/v1/query_range?start=946684800&end=946771200&step=60",
Url: "/api/v1/query_range?start=946684800&end=946771200&step=60&query=up{}",
}
resp, _, err := f.RoundTripGRPC(user.InjectOrgID(context.Background(), userID), req)
require.NoError(t, err)
Expand Down Expand Up @@ -178,7 +178,7 @@ func TestFrontend_ShouldTrackPerRequestMetrics(t *testing.T) {
assert.Equal(t, uint64(0), metricsMap["cortex_query_frontend_enqueue_duration_seconds"].GetMetric()[0].GetHistogram().GetSampleCount())

req := &httpgrpc.HTTPRequest{
Url: "/api/v1/query_range?start=946684800&end=946771200&step=60",
Url: "/api/v1/query_range?start=946684800&end=946771200&step=60&query=up{}",
}
resp, _, err := f.RoundTripGRPC(user.InjectOrgID(context.Background(), userID), req)
require.NoError(t, err)
Expand Down Expand Up @@ -223,7 +223,7 @@ func TestFrontendRetryEnqueue(t *testing.T) {
return &schedulerpb.SchedulerToFrontend{Status: schedulerpb.OK}
})
req := &httpgrpc.HTTPRequest{
Url: "/api/v1/query_range?start=946684800&end=946771200&step=60",
Url: "/api/v1/query_range?start=946684800&end=946771200&step=60&query=up{}",
}
_, _, err := f.RoundTripGRPC(user.InjectOrgID(context.Background(), userID), req)
require.NoError(t, err)
Expand All @@ -235,7 +235,7 @@ func TestFrontendTooManyRequests(t *testing.T) {
})

req := &httpgrpc.HTTPRequest{
Url: "/api/v1/query_range?start=946684800&end=946771200&step=60",
Url: "/api/v1/query_range?start=946684800&end=946771200&step=60&query=up{}",
}
resp, _, err := f.RoundTripGRPC(user.InjectOrgID(context.Background(), "test"), req)
require.NoError(t, err)
Expand All @@ -262,7 +262,7 @@ func TestFrontendCancellation(t *testing.T) {
defer cancel()

req := &httpgrpc.HTTPRequest{
Url: "/api/v1/query_range?start=946684800&end=946771200&step=60",
Url: "/api/v1/query_range?start=946684800&end=946771200&step=60&query=up{}",
}
resp, _, err := f.RoundTripGRPC(user.InjectOrgID(ctx, "test"), req)
require.EqualError(t, err, context.DeadlineExceeded.Error())
Expand Down Expand Up @@ -295,7 +295,7 @@ func TestFrontendWorkerCancellation(t *testing.T) {

// send multiple requests > maxconcurrency of scheduler. So that it keeps all the frontend worker busy in serving requests.
req := &httpgrpc.HTTPRequest{
Url: "/api/v1/query_range?start=946684800&end=946771200&step=60",
Url: "/api/v1/query_range?start=946684800&end=946771200&step=60&query=up{}",
}
reqCount := testFrontendWorkerConcurrency + 5
var wg sync.WaitGroup
Expand Down Expand Up @@ -366,7 +366,7 @@ func TestFrontendFailedCancellation(t *testing.T) {

// send request
req := &httpgrpc.HTTPRequest{
Url: "/api/v1/query_range?start=946684800&end=946771200&step=60",
Url: "/api/v1/query_range?start=946684800&end=946771200&step=60&query=up{}",
}
resp, _, err := f.RoundTripGRPC(user.InjectOrgID(ctx, "test"), req)
require.EqualError(t, err, context.Canceled.Error())
Expand Down Expand Up @@ -686,7 +686,7 @@ func TestWithClosingGrpcServer(t *testing.T) {

// Connection will be established on the first roundtrip.
req := &httpgrpc.HTTPRequest{
Url: "/api/v1/query_range?start=946684800&end=946771200&step=60",
Url: "/api/v1/query_range?start=946684800&end=946771200&step=60&query=up{}",
}
resp, _, err := f.RoundTripGRPC(user.InjectOrgID(context.Background(), userID), req)
require.NoError(t, err)
Expand Down
5 changes: 2 additions & 3 deletions pkg/scheduler/queue/queue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,12 @@ func TestMultiDimensionalQueueFairnessSlowConsumerEffects(t *testing.T) {
normalQueueDimension := "normal-request"
slowConsumerLatency := 20 * time.Millisecond
slowConsumerQueueDimension := "slow-request"
normalQueueDimensionFunc := func(usingMultipleDimensions bool) []string { return []string{"normal-channel"} }
normalQueueDimensionFunc := func(_ bool) []string { return []string{"normal-channel"} }
slowQueueDimensionFunc := func(usingMultipleDimensions bool) []string {
if usingMultipleDimensions {
return []string{"slow-channel"}
} else {
return []string{"normal-channel"}
}
return []string{"normal-channel"}
}

useMultipleDimensions := []bool{false, true}
Expand Down
17 changes: 11 additions & 6 deletions pkg/scheduler/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,7 @@ func (cfg *Config) RegisterFlags(f *flag.FlagSet, logger log.Logger) {
}

func (cfg *Config) Validate() error {
err := cfg.ServiceDiscovery.Validate()
if err != nil {
return err
}
return nil
return cfg.ServiceDiscovery.Validate()
}

// NewScheduler creates a new Scheduler.
Expand Down Expand Up @@ -162,7 +158,16 @@ func NewScheduler(cfg Config, limits Limits, log log.Logger, registerer promethe
[]string{"query_component"},
)

s.requestQueue, err = queue.NewRequestQueue(s.log, cfg.MaxOutstandingPerTenant, cfg.UseMultiAlgorithmQueryQueue, cfg.QuerierForgetDelay, s.queueLength, s.discardedRequests, enqueueDuration, querierInflightRequestsMetric)
s.requestQueue, err = queue.NewRequestQueue(
s.log,
cfg.MaxOutstandingPerTenant,
cfg.UseMultiAlgorithmQueryQueue,
cfg.QuerierForgetDelay,
s.queueLength,
s.discardedRequests,
enqueueDuration,
querierInflightRequestsMetric,
)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ func SerializeProtoResponse(w http.ResponseWriter, resp proto.Message, compressi
}

// ParseRequestFormWithoutConsumingBody parsed and returns the request parameters (query string and/or request body)
// from the input http.Request. If the request has a Body, the request's Body is replaces so that it can be consumed again.
// from the input http.Request. If the request has a Body, the request's Body is replaced so that it can be consumed again.
// It does not check the req.Body size, so it is the caller's responsibility to ensure that the body is not too large.
func ParseRequestFormWithoutConsumingBody(r *http.Request) (url.Values, error) {
if r.Body == nil {
Expand Down

0 comments on commit 67e4d02

Please sign in to comment.