Skip to content

Commit

Permalink
Merge pull request #6331 from rabenhorst/fix-engine-factory
Browse files Browse the repository at this point in the history
Pass QueryEngineFactory by reference
  • Loading branch information
fpetkovski authored May 3, 2023
2 parents 9855151 + 9264b2d commit 1d08ebf
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 23 deletions.
4 changes: 2 additions & 2 deletions cmd/thanos/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ func runQuery(
api := apiv1.NewQueryAPI(
logger,
endpoints.GetEndpointStatus,
*engineFactory,
engineFactory,
apiv1.PromqlEngineType(defaultEngine),
lookbackDeltaCreator,
queryableCreator,
Expand Down Expand Up @@ -800,7 +800,7 @@ func runQuery(
)

defaultEngineType := querypb.EngineType(querypb.EngineType_value[defaultEngine])
grpcAPI := apiv1.NewGRPCAPI(time.Now, queryReplicaLabels, queryableCreator, *engineFactory, defaultEngineType, lookbackDeltaCreator, instantDefaultMaxSourceResolution)
grpcAPI := apiv1.NewGRPCAPI(time.Now, queryReplicaLabels, queryableCreator, engineFactory, defaultEngineType, lookbackDeltaCreator, instantDefaultMaxSourceResolution)
storeServer := store.NewLimitedStoreServer(store.NewInstrumentedStoreServer(reg, proxy), reg, storeRateLimits)
s := grpcserver.New(logger, reg, tracer, grpcLogOpts, tagOpts, comp, grpcProbe,
grpcserver.WithServer(apiv1.RegisterQueryServer(grpcAPI)),
Expand Down
4 changes: 2 additions & 2 deletions pkg/api/query/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type GRPCAPI struct {
now func() time.Time
replicaLabels []string
queryableCreate query.QueryableCreator
engineFactory QueryEngineFactory
engineFactory *QueryEngineFactory
defaultEngine querypb.EngineType
lookbackDeltaCreate func(int64) time.Duration
defaultMaxResolutionSeconds time.Duration
Expand All @@ -33,7 +33,7 @@ func NewGRPCAPI(
now func() time.Time,
replicaLabels []string,
creator query.QueryableCreator,
engineFactory QueryEngineFactory,
engineFactory *QueryEngineFactory,
defaultEngine querypb.EngineType,
lookbackDeltaCreate func(int64) time.Duration,
defaultMaxResolutionSeconds time.Duration,
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/query/grpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func TestGRPCQueryAPIErrorHandling(t *testing.T) {
}

for _, test := range tests {
engineFactory := QueryEngineFactory{
engineFactory := &QueryEngineFactory{
prometheusEngine: test.engine,
}
api := NewGRPCAPI(time.Now, nil, queryableCreator, engineFactory, querypb.EngineType_prometheus, lookbackDeltaFunc, 0)
Expand Down
4 changes: 2 additions & 2 deletions pkg/api/query/v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ type QueryAPI struct {
gate gate.Gate
queryableCreate query.QueryableCreator
// queryEngine returns appropriate promql.Engine for a query with a given step.
engineFactory QueryEngineFactory
engineFactory *QueryEngineFactory
defaultEngine PromqlEngineType
lookbackDeltaCreate func(int64) time.Duration
ruleGroups rules.UnaryClient
Expand Down Expand Up @@ -171,7 +171,7 @@ type seriesQueryPerformanceMetricsAggregator interface {
func NewQueryAPI(
logger log.Logger,
endpointStatus func() []query.EndpointStatus,
engineFactory QueryEngineFactory,
engineFactory *QueryEngineFactory,
defaultEngine PromqlEngineType,
lookbackDeltaCreate func(int64) time.Duration,
c query.QueryableCreator,
Expand Down
28 changes: 12 additions & 16 deletions pkg/api/query/v1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,12 @@ func TestQueryEndpoints(t *testing.T) {

now := time.Now()
timeout := 100 * time.Second
ef := QueryEngineFactory{
engineOpts: promql.EngineOpts{
Logger: nil,
Reg: nil,
MaxSamples: 10000,
Timeout: timeout,
},
}
ef := NewQueryEngineFactory(promql.EngineOpts{
Logger: nil,
Reg: nil,
MaxSamples: 10000,
Timeout: timeout,
}, nil)
api := &QueryAPI{
baseAPI: &baseAPI.BaseAPI{
Now: func() time.Time { return now },
Expand Down Expand Up @@ -727,14 +725,12 @@ func TestMetadataEndpoints(t *testing.T) {

now := time.Now()
timeout := 100 * time.Second
ef := QueryEngineFactory{
engineOpts: promql.EngineOpts{
Logger: nil,
Reg: nil,
MaxSamples: 10000,
Timeout: timeout,
},
}
ef := NewQueryEngineFactory(promql.EngineOpts{
Logger: nil,
Reg: nil,
MaxSamples: 10000,
Timeout: timeout,
}, nil)
api := &QueryAPI{
baseAPI: &baseAPI.BaseAPI{
Now: func() time.Time { return now },
Expand Down

0 comments on commit 1d08ebf

Please sign in to comment.