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

Refactor/remove global splitby #5243

Merged
merged 11 commits into from
Jan 27, 2022

Conversation

owen-d
Copy link
Member

@owen-d owen-d commented Jan 26, 2022

Here's my attempt at the infamous splitby refactor 👻

@owen-d owen-d requested a review from a team as a code owner January 26, 2022 22:20
Copy link
Contributor

@ssncferreira ssncferreira left a comment

Choose a reason for hiding this comment

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

LGTM
Thanks for the help with this 🙂
Just a couple of comments

pkg/loki/loki.go Show resolved Hide resolved
f.Var(&cfg.ForwardHeaders, "frontend.forward-headers-list", "List of headers forwarded by the query Frontend to downstream querier.")
cfg.ResultsCacheConfig.RegisterFlags(f)
}

// Validate validates the config.
func (cfg *Config) Validate() error {
if cfg.SplitQueriesByInterval != 0 {
return errors.New("The yaml flag `split_queries_by_interval` must now be set in the `limits_config` section instead of the `query_range` config section.")
Copy link
Contributor

Choose a reason for hiding this comment

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

This Validate() method is invoked at the start of the query range module? 🤔
Instead of returning an error, wouldn't it be more appropriate to log a warning and also specify the current default split_queries_by_interval value?

Copy link
Member Author

Choose a reason for hiding this comment

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

That's a fair point. I opted to error because it will force the user to acknowledge/understand this, whereas a warning has a fair chance of being ignored/unseen. The downside to this approach is that we're now erroring on a previously valid configuration without a major version bump. @slim-bean @cyriltovena @sandeepsukhani Any thoughts?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I support this, I know it's not ideal to have a breaking config change in a minor release but the cost to the users IMO is low and the cost to us trying to support multiple flags and deprecated flags over time is high.

However please add a note to the upgrade guide!

Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn't sounds cool to do this. We have good default so why don't we let it start and log that it wasn't registered as expected with an error ?

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree with @cyriltovena here, I think it would be more user-friendly to start loki and log the message stating that the value being used for this flag is now 30 minutes.
It might go unseen, but at least loki still works and it doesn't represent a breaking change for current users.

@owen-d
Copy link
Member Author

owen-d commented Jan 27, 2022

Alright, cleaned it up a bit further, ensuring we call Validate on the query range config and cleaned up the internal struct validation. I removed a bit of duplicate code in favor of letting Validate() defer to the embedded queryrangebase.Config.Validate for simplification.

loki -config.file cmd/loki/loki-local-config.yaml
level=error ts=2022-01-27T14:48:15.808646125Z caller=main.go:52 msg="validating config" err="invalid queryrange config: the yaml flag `split_queries_by_interval` must now be set in the `limits_config` section instead of the `query_range` config section"

splitInterval = x
}

currentInterval := r.GetStart() / splitInterval
// include both the currentInterval and the split duration in key to ensure
// a cache key can't be reused when an interval changes
return fmt.Sprintf("%s:%s:%d:%d:%d", userID, r.GetQuery(), r.GetStep(), currentInterval, split)
Copy link
Contributor

Choose a reason for hiding this comment

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

We could just set it to zero if the split is zero. That's a bit simpler. If we activate splitting, then the split part of the key will kick off.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah good call

Copy link
Contributor

@cyriltovena cyriltovena left a comment

Choose a reason for hiding this comment

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

LGTM

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