Skip to content

Commit

Permalink
Store: fix prometheus store label values for matches on external labels
Browse files Browse the repository at this point in the history
External Labels should also be tested for matches against the matchers.

Signed-off-by: Michael Hoffmann <mhoffm@posteo.de>
  • Loading branch information
MichaHoffmann committed Oct 18, 2023
1 parent e4b579f commit cfca276
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ We use *breaking :warning:* to mark changes that are not backward compatible (re
### Fixed

- [#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 cfca276

Please sign in to comment.