Skip to content

Commit

Permalink
Include tenant ID label in label values. (#5908)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeschkies authored Apr 14, 2022
1 parent a41926e commit c7cbeab
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
7 changes: 6 additions & 1 deletion pkg/querier/multi_tenant_querier.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func (q *MultiTenantQuerier) Label(ctx context.Context, req *logproto.LabelReque
return nil, err
}

if req.Name == defaultTenantLabel {
if req.Values && req.Name == defaultTenantLabel {
return &logproto.LabelResponse{Values: tenantIDs}, nil
}

Expand All @@ -120,6 +120,11 @@ func (q *MultiTenantQuerier) Label(ctx context.Context, req *logproto.LabelReque
responses[i] = resp
}

// Append tenant ID label name if label names are requested.
if !req.Values {
responses = append(responses, &logproto.LabelResponse{Values: []string{defaultTenantLabel}})
}

return logproto.MergeLabelResponses(responses)
}

Expand Down
14 changes: 13 additions & 1 deletion pkg/querier/multi_tenant_querier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ func TestMultiTenantQuerier_Label(t *testing.T) {
mockLabelRequest := func(name string) *logproto.LabelRequest {
return &logproto.LabelRequest{
Name: name,
Values: true,
Values: name != "",
Start: &start,
End: &end,
}
Expand Down Expand Up @@ -317,6 +317,18 @@ func TestMultiTenantQuerier_Label(t *testing.T) {
orgID: "1",
expectedLabels: []string{"1"},
},
{
desc: "label names for multiple tenants",
name: "",
orgID: "1|2",
expectedLabels: []string{defaultTenantLabel, "test"},
},
{
desc: "label names for a single tenant",
name: "",
orgID: "1",
expectedLabels: []string{"test"},
},
} {
t.Run(tc.desc, func(t *testing.T) {
querier := newQuerierMock()
Expand Down

0 comments on commit c7cbeab

Please sign in to comment.