diff --git a/pkg/querier/multi_tenant_querier.go b/pkg/querier/multi_tenant_querier.go index 5b063e8382f7c..52284532b583c 100644 --- a/pkg/querier/multi_tenant_querier.go +++ b/pkg/querier/multi_tenant_querier.go @@ -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 } @@ -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) } diff --git a/pkg/querier/multi_tenant_querier_test.go b/pkg/querier/multi_tenant_querier_test.go index 66dc6991e6b61..2babe439dda78 100644 --- a/pkg/querier/multi_tenant_querier_test.go +++ b/pkg/querier/multi_tenant_querier_test.go @@ -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, } @@ -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()