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

Fix the incorrect ordering for topk and bottomk in shardable queries #5170

Merged
merged 2 commits into from
Feb 24, 2023

Conversation

harry671003
Copy link
Contributor

What this PR does:

Examples:

# Query Merge mechanism Prometheus Link Remarks
1 1 + sort(sum by (code) (http_requests_total) ) Merge and then sort by values link Prometheus sorts by value.
2 sort(topk by (code) (10, http_requests_total)) Merge and then sort by values link Prometheus sorts by value.
3 topk by (code) (10, http_requests_total) Merge responses but don't sort link Prometheus doesn't sort.
4 topk(5, http_requests_total) by (code) + sort(http_requests_total) Merge and then sort by values link Prometheus doesn't sort.
5 sort(http_requests_total) + topk(5, http_requests_total) by (code) Merge and then sort by values link Prometheus sorts by value.

There is discrepancy for case 4 where Prometheus doesn't sort the responses but Thanos will sort by value.

I believe the above approach will give reasonable compatibility with Prometheus without increasing the complexity in the merging logic in the frontend.

Checklist

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

Signed-off-by: 🌲 Harry 🌊 John 🏔 <johrry@amazon.com>
@@ -324,20 +324,30 @@ func vectorMerge(req tripperware.Request, resps []*PrometheusInstantQueryRespons
if s == nil {
continue
}
metric := string(cortexpb.FromLabelAdaptersToLabels(sample.Labels).Bytes(buf))
metric := cortexpb.FromLabelAdaptersToLabels(sample.Labels).String()
Copy link
Collaborator

@yeya24 yeya24 Feb 23, 2023

Choose a reason for hiding this comment

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

Can we still keep the Bytes? It should have better performance than String.
https://github.com/cortexproject/cortex/pull/5095/files

Copy link
Collaborator

@yeya24 yeya24 Feb 23, 2023

Choose a reason for hiding this comment

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

Signed-off-by: 🌲 Harry 🌊 John 🏔 <johrry@amazon.com>
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.

Thanks!

@yeya24 yeya24 merged commit dd8a039 into cortexproject:master Feb 24, 2023
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

2 participants