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

pkg/query: Fix panic when diffing two profiles #4681

Merged
merged 8 commits into from
May 29, 2024
Merged

pkg/query: Fix panic when diffing two profiles #4681

merged 8 commits into from
May 29, 2024

Conversation

yomete
Copy link
Contributor

@yomete yomete commented May 28, 2024

Resolves #4680

@yomete yomete requested a review from a team as a code owner May 28, 2024 17:30
@yomete yomete changed the title pkg/query: Handle possible nil value for start and end values pkg/query: Handle possible nil value for start and end values May 28, 2024
Copy link

alwaysmeticulous bot commented May 28, 2024

🤖 Meticulous spotted visual differences in 1 of 423 screens tested: view and approve differences detected.

Last updated for commit 4d1cce4. This comment will update as new commits are pushed.

@yomete yomete changed the title pkg/query: Handle possible nil value for start and end values pkg/query: Fix panic when diffing two profiles May 28, 2024
}

profileMetadata = &pb.ProfileMetadata{
MappingFiles: append(mappingFiles_a, mappingFiles_b...),
Copy link
Member

Choose a reason for hiding this comment

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

We can’t just append them, we need to merge them. But good news is that they’re both sorted so something like a k-way merge is possible.

}

l, err := q.querier.GetProfileMetadataLabels(ctx, req.Match, start, end)
labels, err := q.GetProfileMetadataLabels(ctx, []string{}, startTime, endTime)
Copy link
Member

Choose a reason for hiding this comment

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

We should remove the match variable here. We don’t use it and don’t anticipate using it anytime soon.

if err != nil {
return nil, nil, err
}

return mappingFiles, labels, nil
}

func KWayMerge(arr1, arr2 []string) []string {
Copy link
Member

Choose a reason for hiding this comment

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

this is not 100% right, we need not a pure k-way merge, but it also needs to de-duplicate

I'd say we should just name the function merge and in the code comment say that it does a deduplicating k-way merge, so the two slices that are passed must already be sorted

@@ -1491,7 +1491,7 @@ func (q *Querier) GetProfileMetadataMappings(

values := locations.ListValues().(*array.Dictionary)

compactedDict, err := compactDictionary.CompactDictionary(memory.DefaultAllocator, values)
compactedDict, err := compactDictionary.CompactDictionary(q.pool, values)
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 also made the change to use the Querier's memory allocator here instead of memory.DefaultAllocator.

Copy link
Member

@brancz brancz left a comment

Choose a reason for hiding this comment

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

lgtm

return nil, err
// This is a deduplicating k-way merge.
// The two slices that are passed in are assumed to be sorted.
func MergeTwoSortedSlices(arr1, arr2 []string) []string {
Copy link
Member

Choose a reason for hiding this comment

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

nit: no need to export this function

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah I'd exported because the function is being tested in the columnquery.test.go file. is there a better way to do this?

Copy link
Member

Choose a reason for hiding this comment

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

it's still the same package, within the same package unexported functions can be used

Copy link
Contributor Author

Choose a reason for hiding this comment

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

gotcha!

@yomete yomete merged commit 17c7d66 into main May 29, 2024
38 checks passed
@yomete yomete deleted the fix-binary branch May 29, 2024 12:55
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.

Panic in getMappingFiles
2 participants