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 context cancellation checks on merging GetLabel slices #5837

Conversation

erlan-z
Copy link
Contributor

@erlan-z erlan-z commented Mar 28, 2024

What this PR does:
Add context error check while merging slices for GetLabel operations

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]

Signed-off-by: Erlan Zholdubai uulu <erlanz@amazon.com>
@erlan-z erlan-z force-pushed the context-cancellation-checks-for-get-label branch from 23a7a65 to b4bc204 Compare April 2, 2024 22:30
@@ -37,17 +38,18 @@ func StringsClone(s string) string {

// MergeSlicesParallel merge sorted slices in parallel
// using the MergeSortedSlices function
func MergeSlicesParallel(parallelism int, a ...[]string) []string {
func MergeSlicesParallel(ctx context.Context, parallelism int, a ...[]string) ([]string, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you add a test case that returns an error due to context check?

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 was not sure how to add proper test for context cancellation case.

  1. I could mock and add some wait time on iteration, and cancel context within this time. But adding wait time on tests? I'm not sure.
  2. Cancel context before calling the function? but in this one we are not actually testing the real case.

There should be better way than the above two. I will add second one, but let me know if we have any other option to properly test it.

Copy link
Collaborator

@yeya24 yeya24 Apr 5, 2024

Choose a reason for hiding this comment

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

Cancel context before calling the function? but in this one we are not actually testing the real case.

I was thinking about in the middle of the call. If it is not easy to mock that, It is fine to skip.

Copy link
Collaborator

@yeya24 yeya24 left a comment

Choose a reason for hiding this comment

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

https://github.com/cortexproject/cortex/blob/master/pkg/querier/querier.go#L494
Do we want to add context check when we merge all responses?

CHANGELOG.md Outdated Show resolved Hide resolved
@erlan-z
Copy link
Contributor Author

erlan-z commented Apr 8, 2024

https://github.com/cortexproject/cortex/blob/master/pkg/querier/querier.go#L494 Do we want to add context check when we merge all responses?

Yes, we can add context check there as well, but the code that's used for merge is from thanos. I will create a PR in thanos for that but I think we can merge this PR separately

@erlan-z erlan-z force-pushed the context-cancellation-checks-for-get-label branch 3 times, most recently from 3724519 to 4210f3d Compare April 9, 2024 17:21
…angelog

Signed-off-by: Erlan Zholdubai uulu <erlanz@amazon.com>
@erlan-z erlan-z force-pushed the context-cancellation-checks-for-get-label branch from 4210f3d to d4a6a14 Compare April 9, 2024 18:57
@yeya24
Copy link
Collaborator

yeya24 commented Apr 9, 2024

@alanprot Can you also take a look at this PR? Thanks

@yeya24 yeya24 requested a review from alanprot April 9, 2024 20:28
@alanprot
Copy link
Member

I think looks good!

@alanprot alanprot enabled auto-merge (squash) April 10, 2024 16:21
@alanprot alanprot merged commit e1cef90 into cortexproject:master Apr 10, 2024
16 checks passed
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.

None yet

3 participants