Skip to content

Commit

Permalink
Limiting query start time with config (#572)
Browse files Browse the repository at this point in the history
* Limiting query start time with config

* Fixed maxLookBackPeriod check, added it to existing configs, some other fixes

* gofmted file

* Changed maxLookBackPeriod to 4 weeks in helm chart

* Setting maxLookBackPeriod in helm chart to 0 and bumping up the helm chart version

* changed maxLookBackPeriod in yaml in cmd to 0 and some nit
  • Loading branch information
sandeepsukhani authored and gouthamve committed May 15, 2019
1 parent d50acbe commit 7b584b5
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
3 changes: 3 additions & 0 deletions cmd/loki/loki-local-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@ storage_config:

limits_config:
enforce_metric_name: false

querier:
max_look_back_period: 0
11 changes: 11 additions & 0 deletions pkg/querier/querier.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package querier
import (
"context"
"flag"
"time"

"github.com/cortexproject/cortex/pkg/chunk"
cortex_client "github.com/cortexproject/cortex/pkg/ingester/client"
Expand All @@ -18,10 +19,13 @@ import (

// Config for a querier.
type Config struct {
// Limits query start time to be greater than now() - MaxLookBackPeriod, if set.
MaxLookBackPeriod time.Duration `yaml:"max_look_back_period"`
}

// RegisterFlags register flags.
func (cfg *Config) RegisterFlags(f *flag.FlagSet) {
f.DurationVar(&cfg.MaxLookBackPeriod, "querier.max_look_back_period", 0, "Limit how long back data can be queried")
}

// Querier handlers queries.
Expand Down Expand Up @@ -92,6 +96,13 @@ func (q *Querier) forAllIngesters(f func(logproto.QuerierClient) (interface{}, e

// Query does the heavy lifting for an actual query.
func (q *Querier) Query(ctx context.Context, req *logproto.QueryRequest) (*logproto.QueryResponse, error) {
if q.cfg.MaxLookBackPeriod != 0 {
oldestStartTime := time.Now().Add(-q.cfg.MaxLookBackPeriod)
if oldestStartTime.After(req.Start) {
req.Start = oldestStartTime
}
}

ingesterIterators, err := q.queryIngesters(ctx, req)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion production/helm/loki/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: loki
version: 0.8.0
version: 0.8.1
appVersion: 0.0.1
kubeVersion: "^1.10.0-0"
description: "Loki: like Prometheus, but for logs."
Expand Down
2 changes: 2 additions & 0 deletions production/helm/loki/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ config:
directory: /data/loki/index
filesystem:
directory: /data/loki/chunks
querier:
max_look_back_period: 0

deploymentStrategy: RollingUpdate

Expand Down

0 comments on commit 7b584b5

Please sign in to comment.