Skip to content

Introduce a regex tenant resolver #6713

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

SungJin1212
Copy link
Member

@SungJin1212 SungJin1212 commented Apr 22, 2025

This PR introduces a regex tenant resolver to allow regex in the X-Scope-OrgID value when the user uses tenant-federation feature.
It introduces two flags, tenant-federation.regex-matcher-enabled and tenant-federation.user-sync-interval.

  • The tenant-federation.regex-matcher-enabled enables the regex resolver, which allows regex to the X-Scope-OrgID value.
  • The tenant-federation.user-sync-interval specifies how frequently to scan users. The scanned users are used to calculate matched tenantIDs.

The regex matching rule follows the Prometheus regex matcher (=~), See here.

For example, if there are 3 tenants, whose IDs are user-1, user-2, and user-3. We can set X-Scope-OrgID to user-.+ to query whole tenants.
Also, we can use an existing way like setting user-1|user-2|user-3 to X-Scope-OrgID.

Which issue(s) this PR fixes:
Fixes #6588

Checklist

  • Tests updated
  • Documentation added
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]

@SungJin1212 SungJin1212 marked this pull request as draft April 22, 2025 01:29
@SungJin1212 SungJin1212 force-pushed the Support-regex-to-tenant-federation branch 8 times, most recently from 1b8963e to e6a4222 Compare April 22, 2025 06:02
@SungJin1212 SungJin1212 marked this pull request as ready for review April 22, 2025 06:27
@SungJin1212
Copy link
Member Author

@CharlieTLe
Could you take a look when you have time?

@SungJin1212 SungJin1212 force-pushed the Support-regex-to-tenant-federation branch from e6a4222 to 63f97d2 Compare April 24, 2025 06:46
// because if the # of matched tenantIDs is only one, `X-Scope-OrgID` header is
// set to input regex.
byPassForSingleQuerier = false
tenant.WithDefaultResolver(tenantfederation.NewRegexResolver(prometheus.DefaultRegisterer, t.Cfg.TenantFederation.UserSyncInterval, util_log.Logger, t.Distributor.AllUserStats))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if there is a better way to gather all users. Calling t.Distributor.AllUserStats seems a bit expensive just to get user IDs.

And it cannot cover users that don't ingest anymore but maybe their data still present on long term storage.

Copy link
Member Author

@SungJin1212 SungJin1212 Apr 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And it cannot cover users that don't ingest anymore but maybe their data still present on long term storage.

Thanks for catching.
How about utilizing the userScanner?

Copy link
Member Author

@SungJin1212 SungJin1212 Apr 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling t.Distributor.AllUserStats seems a bit expensive just to get user IDs.

Do you have any good ideas?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow for dynamic tenant selection in query federation
2 participants