Skip to content

Commit

Permalink
Fix duplicate label values from ingester streams (grafana#9629)
Browse files Browse the repository at this point in the history
  • Loading branch information
periklis authored Jun 5, 2023
1 parent c6f809a commit 69392de
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
* [9176](https://github.com/grafana/loki/pull/9176) **DylanGuedes**: Fix incorrect association of per-stream rate limit when sharding is enabled.
* [9463](https://github.com/grafana/loki/pull/9463) **Totalus**: Fix OpenStack Swift client object listing to fetch all the objects properly.
* [9495](https://github.com/grafana/loki/pull/9495) **thampiotr**: Promtail: Fix potential goroutine leak in file tailer.
* [9629](https://github.com/grafana/loki/pull/9629) **periklis**: Fix duplicate label values from ingester streams.

##### Changes

Expand Down
8 changes: 4 additions & 4 deletions pkg/ingester/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -480,15 +480,15 @@ func (i *instance) Label(ctx context.Context, req *logproto.LabelRequest, matche
}, nil
}

labels := make([]string, 0)
labels := util.NewUniqueStrings(0)
err := i.forMatchingStreams(ctx, *req.Start, matchers, nil, func(s *stream) error {
for _, label := range s.labels {
if req.Values && label.Name == req.Name {
labels = append(labels, label.Value)
labels.Add(label.Value)
continue
}
if !req.Values {
labels = append(labels, label.Name)
labels.Add(label.Name)
}
}
return nil
Expand All @@ -498,7 +498,7 @@ func (i *instance) Label(ctx context.Context, req *logproto.LabelRequest, matche
}

return &logproto.LabelResponse{
Values: labels,
Values: labels.Strings(),
}, nil
}

Expand Down
1 change: 1 addition & 0 deletions pkg/ingester/instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ func setupTestStreams(t *testing.T) (*instance, time.Time, int) {
testStreams := []logproto.Stream{
{Labels: "{app=\"test\",job=\"varlogs\"}", Entries: entries(5, currentTime)},
{Labels: "{app=\"test2\",job=\"varlogs\"}", Entries: entries(5, currentTime.Add(6*time.Nanosecond))},
{Labels: "{app=\"test\",job=\"varlogs2\"}", Entries: entries(5, currentTime.Add(12*time.Nanosecond))},
}

for _, testStream := range testStreams {
Expand Down

0 comments on commit 69392de

Please sign in to comment.