Skip to content

Support sharding subqueries in instant query QF #4955

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 8 commits into from
Nov 9, 2022

Conversation

yeya24
Copy link
Contributor

@yeya24 yeya24 commented Nov 6, 2022

What this PR does:

thanos-io/thanos#5811

Thanos doesn't support query sharding for subqueries.
This PR updates the Thanos version to get it supported and also support Matrix response type in instant query so that we can merge the sharded sub query responses.

Which issue(s) this PR fixes:
Fixes #

Checklist

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

@yeya24 yeya24 force-pushed the instant-query-matrix branch from 8476510 to a893089 Compare November 6, 2022 21:06
Signed-off-by: Ben Ye <[email protected]>
@yeya24 yeya24 force-pushed the instant-query-matrix branch from a893089 to 41e1047 Compare November 6, 2022 23:09
@yeya24 yeya24 changed the title support matrix response merge in instant query QF Support sharding subqueries in instant query QF Nov 7, 2022
@yeya24
Copy link
Contributor Author

yeya24 commented Nov 8, 2022

cc @alanprot @alvinlin123

// return a sub slice whose first element's is the smallest timestamp that is strictly
// bigger than the given minTs. Empty slice is returned if minTs is bigger than all the
// timestamps in samples.
func SliceSamples(samples []cortexpb.Sample, minTs int64) []cortexpb.Sample {
Copy link
Contributor

Choose a reason for hiding this comment

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

Would be lovely if we can add unit tests for this function. I understand this is a refactor, but since we export this function now, so it would be lovely to use unit test to establish contracts :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cool idea. I added an unit test

// SliceSamples assumes given samples are sorted by timestamp in ascending order and
// return a sub slice whose first element's is the smallest timestamp that is strictly
// bigger than the given minTs. Empty slice is returned if minTs is bigger than all the
// timestamps in samples.
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I think it's always a good idea to explicit called out what happens if caller violates assumption. Like "If the given samples is not sorted, the behaviour is undefined". Of course it's debatable that this is just stating the obvious; hence the nit :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated

@@ -324,6 +335,59 @@ func vectorMerge(resps []*PrometheusInstantQueryResponse) *Vector {
return result
}

func matrixMerge(resps []*PrometheusInstantQueryResponse) *Matrix {
Copy link
Contributor

Choose a reason for hiding this comment

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

This function looks a lot like

func matrixMerge(resps []*PrometheusResponse) []tripperware.SampleStream {

Anyway we can reduce the duplication?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No good way for now cause they are different types.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could expose an interface for sure... But this needs more refactoring. I prefer copying the function for now.

Copy link
Contributor

@alvinlin123 alvinlin123 Nov 8, 2022

Choose a reason for hiding this comment

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

From my brief look, I think we can break

func matrixMerge(resps []*PrometheusResponse) []tripperware.SampleStream {
into multiple functions one that takes in []tripperware.SampleStream and the other that takes in resps []*PrometheusResponse.

Then here you may be able to use the new function that takes in []tripperware.SampleStream.

Yes some "mapping" code still need to be done, but at least the core logic of merging []tripperware.SampleStream becomes common.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated. Could you please take another look?

Signed-off-by: Ben Ye <[email protected]>
@yeya24 yeya24 force-pushed the instant-query-matrix branch from 6c1f7fa to 6dda199 Compare November 8, 2022 02:20
@yeya24 yeya24 force-pushed the instant-query-matrix branch from 54702fa to 4988400 Compare November 8, 2022 03:03
Signed-off-by: Ben Ye <[email protected]>
Signed-off-by: Ben Ye <[email protected]>
@yeya24 yeya24 force-pushed the instant-query-matrix branch from 68dc314 to e6383d5 Compare November 8, 2022 04:40
Signed-off-by: Ben Ye <[email protected]>
@alanprot alanprot merged commit 0f1dd3f into cortexproject:master Nov 9, 2022
@yeya24 yeya24 deleted the instant-query-matrix branch November 9, 2022 23:14
t00350320 pushed a commit to t00350320/cortex that referenced this pull request Nov 15, 2022
* support matrix response merge in instant query QF

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

* update changelog

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

* remove utils folder

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

* update unit tests for slice samples

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

* fix import

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

* update pb

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

* extract common merge function

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

* update unit test

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

Signed-off-by: Ben Ye <[email protected]>
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.

3 participants