Skip to content

Commit

Permalink
Fixes metric query issue with no grouping. (#2902)
Browse files Browse the repository at this point in the history
This would remove all labels for metrics queries that does not have grouping, instead of adding all labels.
It was introduced by #2875

I added a regression test.

Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>
  • Loading branch information
cyriltovena authored Nov 9, 2020
1 parent 095b4a1 commit dfd2e20
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/logql/log/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,10 @@ func (b *LabelsBuilder) GroupedLabels() LabelsResult {
}
return b.toBaseGroup()
}
// no grouping
if len(b.groups) == 0 {
return b.LabelsResult()
}

if b.without {
return b.withoutResult()
Expand Down
12 changes: 12 additions & 0 deletions pkg/logql/log/labels_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,18 @@ func TestLabelsBuilder_GroupedLabelsResult(t *testing.T) {
sort.Sort(expected)
assertLabelResult(t, expected, b.GroupedLabels())

b = NewBaseLabelsBuilderWithGrouping(nil, false, false).ForLabels(lbs, lbs.Hash())
b.Set("foo", "bar")
b.Set("job", "something")
expected = labels.Labels{
labels.Label{Name: "namespace", Value: "loki"},
labels.Label{Name: "job", Value: "something"},
labels.Label{Name: "cluster", Value: "us-central1"},
labels.Label{Name: "foo", Value: "bar"},
}
sort.Sort(expected)
assertLabelResult(t, expected, b.GroupedLabels())

}

func assertLabelResult(t *testing.T, lbs labels.Labels, res LabelsResult) {
Expand Down

0 comments on commit dfd2e20

Please sign in to comment.