Closed
Description
Describe the bug
Query federation returns series for the incorrect tenant when using the __tenant_id__
label matcher.
To Reproduce
Steps to reproduce the behavior:
- Start Cortex (SHA or version) v1.17.0
- Setup two tenants:
tenant-a
andtenant-b
- Send metric with value to tenant-a:
metric_name{foo="bar"} 1
- Send metric with value to tenant-b:
metric_name{foo="baz"} 2
- Query with
X-Scope-OrgID: tenant-a|tenant-b
formetric_name{__tenant_id__="tenant-b"}
- Response is
metric_name{__tenant_id__="tenant-b", foo="bar"} 1
Expected behavior
Expected metric_name{__tenant_id__="tenant-b", foo="baz"} 2
Environment:
- Infrastructure: Kubernetes
- Deployment tool: helm
Additional Context
I was able to reproduce this by updating the existing tests to also check the labels from the series that were queried instead of only checking the number of series returned:
diff --git a/pkg/querier/tenantfederation/merge_queryable_test.go b/pkg/querier/tenantfederation/merge_queryable_test.go
index e8aa04ea2..b3aa318d4 100644
--- a/pkg/querier/tenantfederation/merge_queryable_test.go
+++ b/pkg/querier/tenantfederation/merge_queryable_test.go
@@ -451,6 +451,18 @@ func TestMergeQueryable_Select(t *testing.T) {
name: "should return only series for team-b when there is an equals matcher for the team-b tenant",
matchers: []*labels.Matcher{{Name: defaultTenantLabel, Value: "team-b", Type: labels.MatchEqual}},
expectedSeriesCount: 2,
+ expectedLabels: []labels.Labels{
+ {
+ {Name: "__tenant_id__", Value: "team-b"},
+ {Name: "instance", Value: "host1"},
+ {Name: "tenant-team-b", Value: "static"},
+ },
+ {
+ {Name: "__tenant_id__", Value: "team-b"},
+ {Name: "instance", Value: "host2.team-b"},
+ {Name: "original___tenant_id__", Value: "original-value"},
+ },
+ },
},
{
name: "should return one series for each tenant when there is an equals matcher for the host1 instance",
When the test runs, the following failure output occurs:
--- FAIL: TestMergeQueryable_Select/three_tenants/should_return_only_series_for_team-b_when_there_is_an_equals_matcher_for_the_team-b_tenant (0.00s)
Expected :labels.Labels{labels.Label{Name:"__tenant_id__", Value:"team-b"}, labels.Label{Name:"instance", Value:"host1"}, labels.Label{Name:"tenant-team-b", Value:"static"}}
Actual :labels.Labels{labels.Label{Name:"__tenant_id__", Value:"team-b"}, labels.Label{Name:"instance", Value:"host1"}, labels.Label{Name:"tenant-team-a", Value:"static"}}
Metadata
Metadata
Assignees
Labels
No labels