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

Add concurrency to the mergeQueryable #4065

Conversation

simonswine
Copy link
Contributor

@simonswine simonswine commented Apr 9, 2021

This should significantly parallelize tenant federation queries. This also extends and aligns the error and warning wrapping and adds tests for those cases.

What this PR does:

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]

Copy link
Contributor

@MichelHollands MichelHollands left a comment

Choose a reason for hiding this comment

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

LGTM, just 1 question and some smaller doc string changes

Copy link
Contributor

@stevesg stevesg left a comment

Choose a reason for hiding this comment

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

Looks nice - just one suggestion which might simplify the code a bit.

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.

Nice work, thank you on working on this. I suggest we simplify mergeDistinctStringSlice a bit (see my comments).

@jtlisi jtlisi self-assigned this Apr 15, 2021
@jtlisi jtlisi self-requested a review April 15, 2021 17:34
@jtlisi jtlisi removed their assignment Apr 15, 2021
Copy link
Contributor

@jtlisi jtlisi left a comment

Choose a reason for hiding this comment

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

@simonswine can you add an enhancement CHANGELOG entry?

@simonswine simonswine force-pushed the 20210409_adopt_concurrency_merge_queryable branch 3 times, most recently from e203f2b to 0fc0fcd Compare April 22, 2021 07:34
@simonswine simonswine requested a review from pstibrany April 22, 2021 08:21
@simonswine simonswine force-pushed the 20210409_adopt_concurrency_merge_queryable branch from ff839dc to 82e9c65 Compare April 22, 2021 09:22
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.

Thank you for your work on this. Please take a look at comments.

@simonswine simonswine force-pushed the 20210409_adopt_concurrency_merge_queryable branch from 833a7f9 to 13acdf4 Compare April 23, 2021 08:09
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.

Nice work! Thanks for addressing my feedback.

q := mockTenantQuerier{tenant: tenantIDs[0], extraLabels: m.extraLabels}

// set warning if exists
if intf := ctx.Value(contextKeyWarningsByTenant); intf != nil {
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 don't quite see why warnings and errors for tenants must be passed to mockTenantQueryableWithFilter via context, instead of having extra fields in that queryable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Valid point, have refactored the tests a bit in 4a10de0

@simonswine
Copy link
Contributor Author

@pstibrany thanks for your continued review 🤗, we should be there now.

Copy link
Contributor

@jtlisi jtlisi left a comment

Choose a reason for hiding this comment

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

LGTM

I had one question and two nits. Both non-blocking.

@simonswine simonswine force-pushed the 20210409_adopt_concurrency_merge_queryable branch from 8c5a8f9 to ffb1313 Compare April 26, 2021 15:34
simonswine and others added 9 commits April 26, 2021 17:29
This should significantly parallelize tenant federation queries. This
also extends aligns the error and warning wrapping and adds tests for
those cases.

Signed-off-by: Christian Simon <[email protected]>
Co-authored-by: Steve Simpson <[email protected]>
Co-authored-by: Michel Hollands <[email protected]>
Signed-off-by: Christian Simon <[email protected]>
* Avoid background goroutine receiving results
* Propagate errGroup context
* Improve documentation comments

Signed-off-by: Christian Simon <[email protected]>
Signed-off-by: Christian Simon <[email protected]>
In the first instance the limit is hard-coded, but that might be an
option that can configured.

Signed-off-by: Christian Simon <[email protected]>
This is beneficial if the methods are not handling context cancellation
themselves.

Signed-off-by: Christian Simon <[email protected]>
Signed-off-by: Christian Simon <[email protected]>
simonswine and others added 3 commits April 26, 2021 17:29
Reuse queryable struct and avoid using the context for passing
parameters around.

Signed-off-by: Christian Simon <[email protected]>
Co-authored-by: Jacob Lisi <[email protected]>
Signed-off-by: Christian Simon <[email protected]>
@simonswine simonswine force-pushed the 20210409_adopt_concurrency_merge_queryable branch from ffb1313 to 7fd543d Compare April 26, 2021 16:29
@pstibrany pstibrany merged commit fbde82d into cortexproject:master Apr 27, 2021
simonswine added a commit to simonswine/cortex that referenced this pull request May 25, 2021
* Add concurrency to the mergeQueryable

This should significantly parallelize tenant federation queries. This
also extends aligns the error and warning wrapping and adds tests for
those cases.

Signed-off-by: Christian Simon <[email protected]>

* Apply suggestions from code review

Co-authored-by: Steve Simpson <[email protected]>
Co-authored-by: Michel Hollands <[email protected]>
Signed-off-by: Christian Simon <[email protected]>

* Simplify concurrency of mergeDistinctStringSlice

* Avoid background goroutine receiving results
* Propagate errGroup context
* Improve documentation comments

Signed-off-by: Christian Simon <[email protected]>

* Add changelog entry

Signed-off-by: Christian Simon <[email protected]>

* Limit maximum concurrency of mergeQueryable

In the first instance the limit is hard-coded, but that might be an
option that can configured.

Signed-off-by: Christian Simon <[email protected]>

* End job early if context already closed

Signed-off-by: Christian Simon <[email protected]>

* Handle context cancellation in concurrency.ForEach

This is beneficial if the methods are not handling context cancellation
themselves.

Signed-off-by: Christian Simon <[email protected]>

* Avoid using interface pointer

Signed-off-by: Christian Simon <[email protected]>

* Handle errors properly for storage.SeriesSet

Signed-off-by: Christian Simon <[email protected]>

* Improve warning and error message readability

Signed-off-by: Christian Simon <[email protected]>

* Simplify mockTenantQueryableWithFilter

Reuse queryable struct and avoid using the context for passing
parameters around.

Signed-off-by: Christian Simon <[email protected]>

* Improve wording on comment

Co-authored-by: Jacob Lisi <[email protected]>
Signed-off-by: Christian Simon <[email protected]>

Co-authored-by: Steve Simpson <[email protected]>
Co-authored-by: Michel Hollands <[email protected]>
Co-authored-by: Jacob Lisi <[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.

5 participants