Skip to content

Commit

Permalink
Store: fix prometheus store label values for matches on external labe…
Browse files Browse the repository at this point in the history
…ls (thanos-io#6816)

External Labels should also be tested for matches against the matchers.

Signed-off-by: Michael Hoffmann <mhoffm@posteo.de>
  • Loading branch information
MichaHoffmann authored and saswatamcode committed Oct 18, 2023
1 parent 186b57a commit 914426d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ We use *breaking :warning:* to mark changes that are not backward compatible (re

### Fixed

- [#6817](https://github.com/thanos-io/thanos/pull/6817) Store Gateway: fix `matchersToPostingGroups` label values variable got shadowed bug.
- [#6802](https://github.com/thanos-io/thanos/pull/6802) Receive: head series limiter should not run if no head series limit is set.
- [#6816](https://github.com/thanos-io/thanos/pull/6816) Store: fix prometheus store label values matches for external labels
- [#6817](https://github.com/thanos-io/thanos/pull/6817) Store Gateway: fix `matchersToPostingGroups` label values variable got shadowed bug.

### Added

Expand Down
7 changes: 7 additions & 0 deletions pkg/store/acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,13 @@ func testStoreAPIsAcceptance(t *testing.T, startStore func(t *testing.T, extLset
matchers: []storepb.LabelMatcher{{Type: storepb.LabelMatcher_EQ, Name: "bar", Value: "different"}},
},
// Matchers on external labels.
{
start: timestamp.FromTime(minTime),
end: timestamp.FromTime(maxTime),
label: "region",
expectedValues: []string(nil),
matchers: []storepb.LabelMatcher{{Type: storepb.LabelMatcher_EQ, Name: "region", Value: "eu-east"}},
},
{
start: timestamp.FromTime(minTime),
end: timestamp.FromTime(maxTime),
Expand Down
10 changes: 5 additions & 5 deletions pkg/store/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -699,11 +699,6 @@ func (p *PrometheusStore) LabelValues(ctx context.Context, r *storepb.LabelValue

extLset := p.externalLabelsFn()

// First check for matching external label which has priority.
if l := extLset.Get(r.Label); l != "" {
return &storepb.LabelValuesResponse{Values: []string{l}}, nil
}

match, matchers, err := matchesExternalLabels(r.Matchers, extLset)
if err != nil {
return nil, status.Error(codes.InvalidArgument, err.Error())
Expand All @@ -712,6 +707,11 @@ func (p *PrometheusStore) LabelValues(ctx context.Context, r *storepb.LabelValue
return &storepb.LabelValuesResponse{Values: nil}, nil
}

// First check for matching external label which has priority.
if l := extLset.Get(r.Label); l != "" {
return &storepb.LabelValuesResponse{Values: []string{l}}, nil
}

var (
sers []map[string]string
vals []string
Expand Down

0 comments on commit 914426d

Please sign in to comment.