Skip to content

Commit

Permalink
Update queryfrontend for Cortex changes.
Browse files Browse the repository at this point in the history
Signed-off-by: SuperQ <superq@gmail.com>
  • Loading branch information
SuperQ committed Jul 12, 2022
1 parent ed627f2 commit db4df8a
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 5 deletions.
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ require (
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da
github.com/golang/snappy v0.0.4
github.com/googleapis/gax-go v2.0.2+incompatible
github.com/grafana/dskit v0.0.0-20211021180445-3bd016e9d7f1
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect
github.com/grpc-ecosystem/go-grpc-middleware/providers/kit/v2 v2.0.0-20201002093600-73cf2ae9d891
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.0.0-rc.2.0.20201207153454-9f6bf00c00a7
Expand Down
1 change: 0 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,6 @@ github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB7
github.com/gorilla/websocket v0.0.0-20170926233335-4201258b820c/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/grafana/dskit v0.0.0-20211021180445-3bd016e9d7f1 h1:Qf+/W3Tup0nO21tgJmO14WJK0yyrm4L2UJipZP+Zoow=
github.com/grafana/dskit v0.0.0-20211021180445-3bd016e9d7f1/go.mod h1:uPG2nyK4CtgNDmWv7qyzYcdI+S90kHHRWvHnBtEMBXM=
github.com/grafana/regexp v0.0.0-20220304095617-2e8d9baf4ac2 h1:uirlL/j72L93RhV4+mkWhjv0cov2I0MIgPOG9rMDr1k=
github.com/grafana/regexp v0.0.0-20220304095617-2e8d9baf4ac2/go.mod h1:M5qHK+eWfAv8VR/265dIuEpL3fNfeC21tXXp9itM24A=
Expand Down
7 changes: 4 additions & 3 deletions pkg/queryfrontend/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ import (

cortexcache "github.com/cortexproject/cortex/pkg/chunk/cache"
"github.com/cortexproject/cortex/pkg/frontend/transport"
"github.com/cortexproject/cortex/pkg/querier"
"github.com/cortexproject/cortex/pkg/querier/queryrange"
"github.com/cortexproject/cortex/pkg/util/flagext"
cortexvalidation "github.com/cortexproject/cortex/pkg/util/validation"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/grafana/dskit/flagext"
"github.com/pkg/errors"
"gopkg.in/yaml.v2"

Expand Down Expand Up @@ -244,7 +245,7 @@ func (cfg *Config) Validate() error {
if cfg.QueryRangeConfig.SplitQueriesByInterval <= 0 {
return errors.New("split queries interval should be greater than 0 when caching is enabled")
}
if err := cfg.QueryRangeConfig.ResultsCacheConfig.Validate(); err != nil {
if err := cfg.QueryRangeConfig.ResultsCacheConfig.Validate(querier.Config{}); err != nil {
return errors.Wrap(err, "invalid ResultsCache config for query_range tripperware")
}
}
Expand All @@ -253,7 +254,7 @@ func (cfg *Config) Validate() error {
if cfg.LabelsConfig.SplitQueriesByInterval <= 0 {
return errors.New("split queries interval should be greater than 0 when caching is enabled")
}
if err := cfg.LabelsConfig.ResultsCacheConfig.Validate(); err != nil {
if err := cfg.LabelsConfig.ResultsCacheConfig.Validate(querier.Config{}); err != nil {
return errors.Wrap(err, "invalid ResultsCache config for labels tripperware")
}
}
Expand Down
27 changes: 27 additions & 0 deletions pkg/queryfrontend/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type ThanosQueryRangeRequest struct {
StoreMatchers [][]*labels.Matcher
CachingOptions queryrange.CachingOptions
Headers []*RequestHeader
Stats string
}

// IsDedupEnabled returns true if deduplication is enabled.
Expand All @@ -68,6 +69,14 @@ func (r *ThanosQueryRangeRequest) GetCachingOptions() queryrange.CachingOptions
return r.CachingOptions
}

func (r *ThanosQueryRangeRequest) GetStats() string { return r.Stats }

func (r *ThanosQueryRangeRequest) WithStats(stats string) queryrange.Request {
q := *r
q.Stats = stats
return &q
}

// WithStartEnd clone the current request with different start and end timestamp.
func (r *ThanosQueryRangeRequest) WithStartEnd(start, end int64) queryrange.Request {
q := *r
Expand Down Expand Up @@ -123,6 +132,7 @@ type ThanosLabelsRequest struct {
PartialResponse bool
CachingOptions queryrange.CachingOptions
Headers []*RequestHeader
Stats string
}

// GetStoreMatchers returns store matches.
Expand All @@ -143,6 +153,14 @@ func (r *ThanosLabelsRequest) GetQuery() string { return "" }

func (r *ThanosLabelsRequest) GetCachingOptions() queryrange.CachingOptions { return r.CachingOptions }

func (r *ThanosLabelsRequest) GetStats() string { return r.Stats }

func (r *ThanosLabelsRequest) WithStats(stats string) queryrange.Request {
q := *r
q.Stats = stats
return &q
}

// WithStartEnd clone the current request with different start and end timestamp.
func (r *ThanosLabelsRequest) WithStartEnd(start, end int64) queryrange.Request {
q := *r
Expand Down Expand Up @@ -196,6 +214,7 @@ type ThanosSeriesRequest struct {
StoreMatchers [][]*labels.Matcher
CachingOptions queryrange.CachingOptions
Headers []*RequestHeader
Stats string
}

// IsDedupEnabled returns true if deduplication is enabled.
Expand All @@ -219,6 +238,14 @@ func (r *ThanosSeriesRequest) GetQuery() string { return "" }

func (r *ThanosSeriesRequest) GetCachingOptions() queryrange.CachingOptions { return r.CachingOptions }

func (r *ThanosSeriesRequest) GetStats() string { return r.Stats }

func (r *ThanosSeriesRequest) WithStats(stats string) queryrange.Request {
q := *r
q.Stats = stats
return &q
}

// WithStartEnd clone the current request with different start and end timestamp.
func (r *ThanosSeriesRequest) WithStartEnd(start, end int64) queryrange.Request {
q := *r
Expand Down
10 changes: 10 additions & 0 deletions pkg/queryfrontend/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ func (ThanosResponseExtractor) ResponseWithoutHeaders(resp queryrange.Response)
return resp
}

func (ThanosResponseExtractor) ResponseWithoutStats(resp queryrange.Response) queryrange.Response {
switch tr := resp.(type) {
case *ThanosLabelsResponse:
return &ThanosLabelsResponse{Status: queryrange.StatusSuccess, Data: tr.Data}
case *ThanosSeriesResponse:
return &ThanosSeriesResponse{Status: queryrange.StatusSuccess, Data: tr.Data}
}
return resp
}

// headersToQueryRangeHeaders convert slice of ResponseHeader to Cortex queryrange.PrometheusResponseHeader in an
// unsafe manner. It reuses the same memory.
func headersToQueryRangeHeaders(headers []*ResponseHeader) []*queryrange.PrometheusResponseHeader {
Expand Down

0 comments on commit db4df8a

Please sign in to comment.