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

Cache labels and series results #3315

Merged
merged 5 commits into from
Oct 20, 2020
Merged

Conversation

yeya24
Copy link
Contributor

@yeya24 yeya24 commented Oct 14, 2020

Signed-off-by: Ben Ye [email protected]

  • I added CHANGELOG entry for this change.
  • Change is not relevant to the end user.

Changes

Fixes #3230

  1. Bump Cortex to commit cortexproject/cortex@21bad57
  2. Support labels/series specific cache configuration
  3. Labels & Series API responses can be cached now. Tested on different query API implementation: Thanos querier, Prometheus and Conprof :)

Verification

Copy link
Member

@bwplotka bwplotka left a comment

Choose a reason for hiding this comment

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

This looks amazing ❤️

Some high-level comments, but overall LGTM! (:

case *ThanosLabelsRequest:
return fmt.Sprintf("%s:%d", tr.Label, currentInterval)
case *ThanosSeriesRequest:
return fmt.Sprintf("%s:%d", tr.Matchers, currentInterval)
}
return fmt.Sprintf("%s:%d:%d", r.GetQuery(), r.GetStep(), currentInterval)
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't we error here?

Copy link
Contributor Author

@yeya24 yeya24 Oct 14, 2020

Choose a reason for hiding this comment

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

I am not sure but this shouldn't happen. It would error out in the first place when decoding the HTTP request if the request is not valid.

CHANGELOG.md Outdated
@@ -13,6 +13,7 @@ We use *breaking :warning:* to mark changes that are not backward compatible (re

- [#3261](https://github.com/thanos-io/thanos/pull/3261) Thanos Store: Use segment files specified in meta.json file, if present. If not present, Store does the LIST operation as before.
- [#3276](https://github.com/thanos-io/thanos/pull/3276) Query Frontend: Support query splitting and retry for labels and series requests.
- [#3315](https://github.com/thanos-io/thanos/pull/3315) Query Frontend: Support results caching for labels and series requests.
Copy link
Member

Choose a reason for hiding this comment

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

label names ? label values? both?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes both. I will make it more clear.

i := 0
for ; i < len(t.resolutions) && t.resolutions[i] > tr.MaxSourceResolution; i++ {
}
return fmt.Sprintf("%s:%d:%d:%d", tr.Query, tr.Step, currentInterval, i)
case *ThanosLabelsRequest:
Copy link
Member

Choose a reason for hiding this comment

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

What about label names?

Copy link
Contributor Author

@yeya24 yeya24 Oct 14, 2020

Choose a reason for hiding this comment

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

ThanosLabelsRequest already covers both label_values query and label_names query. If it is a label_names query, then tr.Label is just an empty string. For label_values query, that's the queried label name.

I am using the same struct for them since their query response is the same []string

// GetStep returns the step of the request in milliseconds.
func (r *ThanosLabelsRequest) GetStep() int64 { return 0 }
// GetStep returns the step of the request in milliseconds. Returns 1 is a trick to avoid panic in
// https://github.com/cortexproject/cortex/blob/master/pkg/querier/queryrange/results_cache.go#L447.
Copy link
Member

Choose a reason for hiding this comment

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

(: Yea it's getting very tricky without Cortex actually support our case, and it would be nice to help them as well 🤔
This is fine for now, but wonder how long term solution of truly shared code with cortex would looks like

Copy link
Contributor Author

@yeya24 yeya24 Oct 14, 2020

Choose a reason for hiding this comment

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

Yeah, I will take a look later. Would be good to have these query APIs natively supported on Cortex then we can re-use.

@yeya24 yeya24 requested a review from kakkoyun October 19, 2020 13:54
Signed-off-by: Ben Ye <[email protected]>
Signed-off-by: Ben Ye <[email protected]>
Signed-off-by: Ben Ye <[email protected]>
Signed-off-by: Ben Ye <[email protected]>
@yeya24 yeya24 force-pushed the cache-labelseries branch from 97eb6cd to 651b1bd Compare October 19, 2020 16:32
@yeya24
Copy link
Contributor Author

yeya24 commented Oct 19, 2020

Conflict fixed. Please give another round of review if you have time.

Copy link
Member

@kakkoyun kakkoyun left a comment

Choose a reason for hiding this comment

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

LGTM. Great work. I think we can go ahead and merge it. We can open follow up PRs if needed.

@kakkoyun kakkoyun merged commit 2a7590f into thanos-io:master Oct 20, 2020
@yeya24 yeya24 deleted the cache-labelseries branch October 20, 2020 12:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

query-frontend: Split and cache metadata API responses by time interval
3 participants