Skip to content

Commit

Permalink
Select correct tenant during query federation
Browse files Browse the repository at this point in the history
We are creating a job which has the tenant name for each tenant to
query, but we use the incorrect index in the `ids` slice that contains
the list of tenants. This causes the querier to select results for the
first tenant in the list of tenants to match with instead of the actual
tenant the querier was intended for.

I updated the existing tests to check the labels of the results as well
instead of only relying on the number of series found.

Fixes #5941

Signed-off-by: Charlie Le <[email protected]>
  • Loading branch information
CharlieTLe committed May 10, 2024
1 parent db10d87 commit e2be9f0
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/querier/tenantfederation/merge_queryable.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ func (m *mergeQuerier) Select(ctx context.Context, sortSeries bool, hints *stora
return fmt.Errorf("unexpected type %T", jobIntf)
}
// Based on parent ctx here as we are using lazy querier.
newCtx := user.InjectOrgID(parentCtx, ids[job.pos])
newCtx := user.InjectOrgID(parentCtx, job.id)
seriesSets[job.pos] = &addLabelsSeriesSet{
upstream: job.querier.Select(newCtx, sortSeries, hints, filteredMatchers...),
labels: labels.Labels{
Expand Down
44 changes: 44 additions & 0 deletions pkg/querier/tenantfederation/merge_queryable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,11 +446,42 @@ func TestMergeQueryable_Select(t *testing.T) {
name: "should return only series for team-a and team-c tenants when there is a not-equals matcher for the team-b tenant",
matchers: []*labels.Matcher{{Name: defaultTenantLabel, Value: "team-b", Type: labels.MatchNotEqual}},
expectedSeriesCount: 4,
expectedLabels: []labels.Labels{
{
{Name: "__tenant_id__", Value: "team-a"},
{Name: "instance", Value: "host1"},
{Name: "tenant-team-a", Value: "static"},
},
{
{Name: "__tenant_id__", Value: "team-a"},
{Name: "instance", Value: "host2.team-a"},
},
{
{Name: "__tenant_id__", Value: "team-c"},
{Name: "instance", Value: "host1"},
{Name: "tenant-team-c", Value: "static"},
},
{
{Name: "__tenant_id__", Value: "team-c"},
{Name: "instance", Value: "host2.team-c"},
},
},
},
{
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: "should return one series for each tenant when there is an equals matcher for the host1 instance",
Expand Down Expand Up @@ -516,6 +547,19 @@ func TestMergeQueryable_Select(t *testing.T) {
name: "should return only series for team-b when there is an equals matcher for 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: "original___tenant_id__", Value: "original-value"},
{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 all series when there is an equals matcher for the original value of __tenant_id__ using the revised tenant label",
Expand Down

0 comments on commit e2be9f0

Please sign in to comment.