Repository navigation
fix(model): remove all labels in WithoutLabels regardless of argument order - #6106
amalsaidov wants to merge 2 commits into
Conversation
… order Labels.WithoutLabels collects the matching label pairs in the order of the names argument and then hands them to Subtract, which performs a merge join and assumes its argument is sorted. When the caller passes label names in an order other than sorted (for example a group-by list from a query), some of the requested labels were silently left in the result. Sort the collected pairs before subtracting them so every requested label is removed irrespective of argument order, matching the behaviour of the sibling WithLabels and BytesWithLabels helpers. Add a test case covering unsorted removal names. Signed-off-by: Amal Saidov <amalsaidov@users.noreply.github.com>
|
|
Signed commits report2 of 2 commits between
This repository requires all commits to be signed. See GitHub docs on commit signature verification. |
WithLabels collected matching pairs in the order of the names argument, so passing an unsorted name list (for example a group-by list from a query, as in timeseries.Builder and heatmap.Builder) produced an unsorted label set. Sort the matched pairs before returning so the result is a well-formed, order-independent label set, matching the fix applied to WithoutLabels. Add a test covering unsorted keep names. Signed-off-by: Amal Saidov <amalsaidov@users.noreply.github.com>
|
Good catch, thanks. Will get the CLA signed. |
What this does
Labels.WithoutLabelsis meant to return a copy of the label set with thegiven names removed. It collects the matching label pairs in the order of the
namesargument and then callsSubtract, which performs a merge join andassumes its input is sorted. When the caller passes names in any order other
than sorted, the merge join advances past entries that should have been
dropped, so some requested labels are silently left in the result.
The sibling helpers
WithLabelsandBytesWithLabelsscan the label set foreach name and are therefore order independent.
WithoutLabelsshould behave thesame way.
This is reachable from the query path:
timeseries.Builderandheatmap.Buildercalllbs.WithoutLabels(by...)wherebyis the group-bylist taken straight from the request (
TimeSeries.GroupBy,Heatmap.GroupBy),which is not guaranteed to be sorted. In that case exemplar/point labels keep
group-by labels that should have been stripped.
Fix
Sort the collected pairs before subtracting them, so every requested label is
removed regardless of argument order.
Test
Added a case to
TestLabels_WithoutLabelsthat removes two labels passed inunsorted order (
"service", "env"). It fails before the change (theenvlabel is left behind) and passes after.
AI-assisted; directed, reviewed and tested by the author.