Skip to content

Added -querier.max-query-lookback and fixed -querier.max-query-into-future #3452

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

Merged
merged 6 commits into from
Nov 4, 2020

Conversation

pracucci
Copy link
Contributor

@pracucci pracucci commented Nov 3, 2020

What this PR does:
Currently, the only option to limit the time range of queries is -store.max-look-back-period, but it suffers the following issues:

  1. Applies to chunks storage only
  2. Applies to instance/range queries only (not a strict requirement today, but we'll soon work on querying series/labels from storage in the blocks storage)
  3. Can't be overridden on a per-tenant basis

In this PR I'm adding -querier.max-query-lookback which is expected is superseed -store.max-look-back-period solving the issues above. While working on tests, I've also noticed that -querier.max-query-into-future is currently broken (doesn't really enforce it), so I've fixed it in this PR.

Out of the scope of this PR:

  • Enforcing the limit in the query-frontend too (will be done in a separate PR)

Which issue(s) this PR fixes:
N/A

Checklist

  • Tests updated
  • Documentation added
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]

@@ -204,18 +205,20 @@ func NewQueryable(distributor QueryableWithFilter, stores []QueryableWithFilter,
return storage.QueryableFunc(func(ctx context.Context, mint, maxt int64) (storage.Querier, error) {
now := time.Now()

if cfg.MaxQueryIntoFuture > 0 {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved to validateQueryTimeRange(), which is also called in the Select(). If this limit is not enforced in the Select() too, we're not really enforcing it. Unit tests were weak: I spotted this issue improving unit tests.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is this because Select uses hints?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Exactly.

Copy link
Contributor

@gouthamve gouthamve left a comment

Choose a reason for hiding this comment

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

LGTM with nits :)

@@ -74,7 +74,7 @@ func (cfg *StoreConfig) RegisterFlags(f *flag.FlagSet) {
cfg.WriteDedupeCacheConfig.RegisterFlagsWithPrefix("store.index-cache-write.", "Cache config for index entry writing. ", f)

f.Var(&cfg.CacheLookupsOlderThan, "store.cache-lookups-older-than", "Cache index entries older than this period. 0 to disable.")
f.Var(&cfg.MaxLookBackPeriod, "store.max-look-back-period", "Limit how long back data can be queried")
f.Var(&cfg.MaxLookBackPeriod, "store.max-look-back-period", "Deprecated: use -querier.max-query-lookback instead. Limit how long back data can be queried. This setting applies to chunks storage only.") // To be removed in Cortex 1.8.
}

// Validate validates the store config.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we warn users if this is set in validate?

flagext.DeprecatedFlagsUsed.Inc()
level.Warn(logger).Log("msg", "running with DEPRECATED ..... use ... instead")

@@ -204,18 +205,20 @@ func NewQueryable(distributor QueryableWithFilter, stores []QueryableWithFilter,
return storage.QueryableFunc(func(ctx context.Context, mint, maxt int64) (storage.Querier, error) {
now := time.Now()

if cfg.MaxQueryIntoFuture > 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this because Select uses hints?

Signed-off-by: Marco Pracucci <marco@pracucci.com>
Signed-off-by: Marco Pracucci <marco@pracucci.com>
Signed-off-by: Marco Pracucci <marco@pracucci.com>
@pracucci pracucci force-pushed the add-querier-max-lookback branch from 020c19a to 3e304f3 Compare November 3, 2020 13:48
Signed-off-by: Marco Pracucci <marco@pracucci.com>
Signed-off-by: Marco Pracucci <marco@pracucci.com>
Copy link
Contributor

@pstibrany pstibrany left a comment

Choose a reason for hiding this comment

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

LGTM, with some nits.

Comment on lines +518 to +520
if endTime.Before(startTime) {
return 0, 0, errEmptyTimeRange
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This check is repeated in both if conditions. Should we do it only once, after all manipulations?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it's more future proof doing it in both places. Doesn't look an overcomplication.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's more future proof doing it in both places

I don't quite understand what you mean by "future proof" here. (It's not overcomplication, but looks like unnecessary duplication. Plus it would cover case when input start time is already after end time).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As of today, we can remove the if and move it to the end because the two validations are done one on start time and the other one on end time. If in the future we add more validation (either on start or end), we may end up in bugs which we don't realise because of an invalid time range (start > end) introduced by a previous validation.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see, although I think this check is pretty universal, and hopefully unit tests will warn us about newly introduced bugs. Thanks for explaining your thinking.

Signed-off-by: Marco Pracucci <marco@pracucci.com>
@pracucci
Copy link
Contributor Author

pracucci commented Nov 3, 2020

Thanks @pstibrany for your thoughtful review. I've addressed your comments.

Copy link
Contributor

@ranton256 ranton256 left a comment

Choose a reason for hiding this comment

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

LGTM

@pracucci pracucci merged commit 87f3204 into cortexproject:master Nov 4, 2020
@pracucci pracucci deleted the add-querier-max-lookback branch November 4, 2020 07:47
@Wing924 Wing924 mentioned this pull request Dec 13, 2020
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants