Skip to content

Commit

Permalink
query: Disable downsampling by default.
Browse files Browse the repository at this point in the history
(Details #376)

Signed-off-by: Bartek Plotka <bwplotka@gmail.com>
  • Loading branch information
bwplotka committed Jul 5, 2018
1 parent eaf7756 commit 972a52e
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 46 deletions.
7 changes: 6 additions & 1 deletion cmd/thanos/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ func registerQuery(m map[string]setupFunc, app *kingpin.Application, name string
stores := cmd.Flag("store", "Addresses of statically configured store API servers (repeatable).").
PlaceHolder("<store>").Strings()

enableAutodownsampling := cmd.Flag("query.auto-downsampling", "Enable automatic adjustment (step / 5) to what source of data should be used in store gateways if no max_source_resolution param is specified. ").
Default("false").Bool()

m[name] = func(g *run.Group, logger log.Logger, reg *prometheus.Registry, tracer opentracing.Tracer, _ bool) error {
peer, err := newPeerFn(logger, reg, true, *httpAdvertiseAddr, true)
if err != nil {
Expand Down Expand Up @@ -87,6 +90,7 @@ func registerQuery(m map[string]setupFunc, app *kingpin.Application, name string
peer,
selectorLset,
*stores,
*enableAutodownsampling,
)
}
}
Expand Down Expand Up @@ -141,6 +145,7 @@ func runQuery(
peer *cluster.Peer,
selectorLset labels.Labels,
storeAddrs []string,
enableAutodownsampling bool,
) error {
var staticSpecs []query.StoreSpec
for _, addr := range storeAddrs {
Expand Down Expand Up @@ -208,7 +213,7 @@ func runQuery(
router := route.New()
ui.New(logger, nil).Register(router)

api := v1.NewAPI(logger, reg, engine, queryableCreator)
api := v1.NewAPI(logger, reg, engine, queryableCreator, enableAutodownsampling)
api.Register(router.WithPrefix("/api/v1"), tracer, logger)

mux := http.NewServeMux()
Expand Down
28 changes: 17 additions & 11 deletions pkg/query/api/v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ type API struct {
queryableCreate query.QueryableCreator
queryEngine *promql.Engine

instantQueryDuration prometheus.Histogram
rangeQueryDuration prometheus.Histogram

now func() time.Time
instantQueryDuration prometheus.Histogram
rangeQueryDuration prometheus.Histogram
enableAutodownsampling bool
now func() time.Time
}

// NewAPI returns an initialized API type.
Expand All @@ -113,6 +113,7 @@ func NewAPI(
reg *prometheus.Registry,
qe *promql.Engine,
c query.QueryableCreator,
enableAutodownsampling bool,
) *API {
instantQueryDuration := prometheus.NewHistogram(prometheus.HistogramOpts{
Name: "thanos_query_api_instant_query_duration_seconds",
Expand All @@ -134,12 +135,13 @@ func NewAPI(
rangeQueryDuration,
)
return &API{
logger: logger,
queryEngine: qe,
queryableCreate: c,
instantQueryDuration: instantQueryDuration,
rangeQueryDuration: rangeQueryDuration,
now: time.Now,
logger: logger,
queryEngine: qe,
queryableCreate: c,
instantQueryDuration: instantQueryDuration,
rangeQueryDuration: rangeQueryDuration,
enableAutodownsampling: enableAutodownsampling,
now: time.Now,
}
}

Expand Down Expand Up @@ -277,7 +279,11 @@ func (api *API) queryRange(r *http.Request) (interface{}, []error, *apiError) {
return nil, nil, &apiError{errorBadData, err}
}

maxSourceResolution := step / 5 // By default fit at least 5 samples between steps.
maxSourceResolution := 0 * time.Second
if api.enableAutodownsampling {
// If no max_source_resolution is specified fit at least 5 samples between steps.
maxSourceResolution = step / 5
}
if val := r.FormValue("max_source_resolution"); val != "" {
maxSourceResolution, err = parseDuration(val)
if err != nil {
Expand Down
Loading

0 comments on commit 972a52e

Please sign in to comment.