Skip to content

Commit

Permalink
using set to handle duplicate values
Browse files Browse the repository at this point in the history
Signed-off-by: Namanl2001 <namanlakhwani@gmail.com>
  • Loading branch information
Namanl2001 committed Apr 3, 2021
1 parent 6c2ec33 commit a4073e4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cmd/thanos/sidecar.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ func runSidecar(
return nil
})
if err != nil {
return errors.Wrap(err, "buildinfo query")
return errors.Wrap(err, "failed to get prometheus version")
}
return nil
}, func(error) {
Expand Down
8 changes: 7 additions & 1 deletion pkg/store/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -520,11 +520,17 @@ func (p *PrometheusStore) LabelValues(ctx context.Context, r *storepb.LabelValue
if err != nil {
return nil, err
}

// using set to handle duplicate values.
labelValuesSet := make(map[string]struct{})
for _, s := range sers {
if val, exists := s[r.Label]; exists {
vals = append(vals, val)
labelValuesSet[val] = struct{}{}
}
}
for key := range labelValuesSet {
vals = append(vals, key)
}
}
sort.Strings(vals)
return &storepb.LabelValuesResponse{Values: vals}, nil
Expand Down

0 comments on commit a4073e4

Please sign in to comment.