Skip to content

Commit 6f99af6

Browse files
authored
fix(detected labels): response when store label values are empty (#13970)
1 parent b5ac6a0 commit 6f99af6

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

pkg/querier/querier.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -995,7 +995,7 @@ func countLabelsAndCardinality(storeLabelsMap map[string][]string, ingesterLabel
995995

996996
if ingesterLabels != nil {
997997
for label, val := range ingesterLabels.Labels {
998-
if _, isStatic := staticLabels[label]; isStatic || !containsAllIDTypes(val.Values) {
998+
if _, isStatic := staticLabels[label]; (isStatic && val.Values != nil) || !containsAllIDTypes(val.Values) {
999999
_, ok := dlMap[label]
10001000
if !ok {
10011001
dlMap[label] = newParsedLabels()
@@ -1010,7 +1010,7 @@ func countLabelsAndCardinality(storeLabelsMap map[string][]string, ingesterLabel
10101010
}
10111011

10121012
for label, values := range storeLabelsMap {
1013-
if _, isStatic := staticLabels[label]; isStatic || !containsAllIDTypes(values) {
1013+
if _, isStatic := staticLabels[label]; (isStatic && values != nil) || !containsAllIDTypes(values) {
10141014
_, ok := dlMap[label]
10151015
if !ok {
10161016
dlMap[label] = newParsedLabels()

pkg/querier/querier_mock_test.go

+3
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,9 @@ func (s *storeMock) PutOne(_ context.Context, _, _ model.Time, _ chunk.Chunk) er
350350

351351
func (s *storeMock) LabelValuesForMetricName(ctx context.Context, userID string, from, through model.Time, metricName string, labelName string, _ ...*labels.Matcher) ([]string, error) {
352352
args := s.Called(ctx, userID, from, through, metricName, labelName)
353+
if args.Get(0) == nil {
354+
return nil, args.Error(1)
355+
}
353356
return args.Get(0).([]string), args.Error(1)
354357
}
355358

pkg/querier/querier_test.go

+34
Original file line numberDiff line numberDiff line change
@@ -1518,6 +1518,40 @@ func TestQuerier_DetectedLabels(t *testing.T) {
15181518
}
15191519
})
15201520

1521+
t.Run("label is not present when the values are nil", func(t *testing.T) {
1522+
ingesterClient := newQuerierClientMock()
1523+
storeClient := newStoreMock()
1524+
1525+
ingesterClient.On("GetDetectedLabels", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).
1526+
Return(&logproto.LabelToValuesResponse{}, nil)
1527+
storeClient.On("LabelNamesForMetricName", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).
1528+
Return([]string{"storeLabel1", "pod"}, nil).
1529+
On("LabelValuesForMetricName", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, "storeLabel1", mock.Anything).
1530+
Return([]string{"val1", "val2"}, nil).
1531+
On("LabelValuesForMetricName", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, "pod", mock.Anything).
1532+
Return(nil, nil)
1533+
1534+
querier, err := newQuerier(
1535+
conf,
1536+
mockIngesterClientConfig(),
1537+
newIngesterClientMockFactory(ingesterClient),
1538+
mockReadRingWithOneActiveIngester(),
1539+
&mockDeleteGettter{},
1540+
storeClient, limits)
1541+
require.NoError(t, err)
1542+
1543+
resp, err := querier.DetectedLabels(ctx, &request)
1544+
require.NoError(t, err)
1545+
1546+
detectedLabels := resp.DetectedLabels
1547+
assert.Len(t, detectedLabels, 1)
1548+
expectedCardinality := map[string]uint64{"storeLabel1": 2}
1549+
for _, d := range detectedLabels {
1550+
card := expectedCardinality[d.Label]
1551+
assert.Equal(t, d.Cardinality, card, "Expected cardinality mismatch for: ", d.Label)
1552+
}
1553+
})
1554+
15211555
t.Run("returns a response when store data is empty", func(t *testing.T) {
15221556
ingesterResponse := logproto.LabelToValuesResponse{Labels: map[string]*logproto.UniqueLabelValues{
15231557
"cluster": {Values: []string{"ingester"}},

0 commit comments

Comments
 (0)