Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limiting query start time with config #572

Merged
merged 7 commits into from
May 15, 2019
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"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a comment above the field too?

}

// 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