Skip to content

Commit

Permalink
store: fix misc label_value issues related to external labels (#6879)
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Hoffmann <[email protected]>
  • Loading branch information
MichaHoffmann authored Dec 5, 2023
1 parent 28407d6 commit e578b1f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
7 changes: 7 additions & 0 deletions pkg/store/acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,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: "__name__", Value: "nonexistent"}},
},
{
start: timestamp.FromTime(minTime),
end: timestamp.FromTime(maxTime),
Expand Down
7 changes: 6 additions & 1 deletion pkg/store/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -704,11 +704,16 @@ func (p *PrometheusStore) LabelValues(ctx context.Context, r *storepb.LabelValue
return nil, status.Error(codes.InvalidArgument, err.Error())
}
if !match {
return &storepb.LabelValuesResponse{Values: nil}, nil
return &storepb.LabelValuesResponse{}, nil
}

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

Expand Down
7 changes: 6 additions & 1 deletion pkg/store/tsdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,10 +341,15 @@ func (s *TSDBStore) LabelValues(ctx context.Context, r *storepb.LabelValuesReque
}

if !match {
return &storepb.LabelValuesResponse{Values: nil}, nil
return &storepb.LabelValuesResponse{}, nil
}

if v := s.getExtLset().Get(r.Label); v != "" {
for _, m := range matchers {
if !m.Matches(v) {
return &storepb.LabelValuesResponse{}, nil
}
}
return &storepb.LabelValuesResponse{Values: []string{v}}, nil
}

Expand Down

0 comments on commit e578b1f

Please sign in to comment.