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
8 changes: 8 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,12 @@ import (

// Config for a querier.
type Config struct {
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, "")
Copy link
Member

Choose a reason for hiding this comment

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

Why the mixure of - and _? Also, can you add a description for the flag?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

must be a typo, sorry missed it somehow

}

// Querier handlers queries.
Expand Down Expand Up @@ -92,6 +95,11 @@ 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) {
oldestStartTime := time.Now().Add(-q.cfg.MaxLookBackPeriod)
Copy link
Member

Choose a reason for hiding this comment

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

This means queries are broken for the default value (0). Have a check for MaxLookBackPeriod > 0 :)

if oldestStartTime.After(req.Start) {
req.Start = oldestStartTime
}

ingesterIterators, err := q.queryIngesters(ctx, req)
if err != nil {
return nil, err
Expand Down