Skip to content

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]

continue
}
metric := string(cortexpb.FromLabelAdaptersToLabels(sample.Labels).Bytes(buf))
metric := cortexpb.FromLabelAdaptersToLabels(sample.Labels).String()
Copy link
Contributor

@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
Contributor

@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 🏔 <[email protected]>
Copy link
Contributor

@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.

2 participants