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 dba04fc
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
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 dba04fc

Please sign in to comment.