Skip to content

Add local cache to regexResolver#7363

Merged
SungJin1212 merged 6 commits into
cortexproject:masterfrom
SungJin1212:Add-local-cache-to-regexResolver
Mar 23, 2026
Merged

Add local cache to regexResolver#7363
SungJin1212 merged 6 commits into
cortexproject:masterfrom
SungJin1212:Add-local-cache-to-regexResolver

Conversation

@SungJin1212
Copy link
Copy Markdown
Member

@SungJin1212 SungJin1212 commented Mar 19, 2026

This PR introduces a local cache (map) to store already resolved and validated tenant lists.

Benchmark Result

This is result of the BenchmarkRegexResolver_TenantIDs.

goos: darwin
goarch: arm64
pkg: github.com/cortexproject/cortex/pkg/querier/tenantfederation
cpu: Apple M4 Max
BenchmarkRegexResolver_TenantIDs
BenchmarkRegexResolver_TenantIDs/ColdCache_with_regex_tenant
BenchmarkRegexResolver_TenantIDs/ColdCache_with_regex_tenant-14         	   44725	     26863 ns/op
BenchmarkRegexResolver_TenantIDs/WarmCache_with_regex_tenant
BenchmarkRegexResolver_TenantIDs/WarmCache_with_regex_tenant-14         	79362019	        14.60 ns/op
BenchmarkRegexResolver_TenantIDs/ColdCache_with_resolved_tenant
BenchmarkRegexResolver_TenantIDs/ColdCache_with_resolved_tenant-14      	  430551	      2783 ns/op
BenchmarkRegexResolver_TenantIDs/WarmCache_with_resolved_tenant
BenchmarkRegexResolver_TenantIDs/WarmCache_with_resolved_tenant-14      	80651258	        14.60 ns/op
PASS

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

Checklist

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

@SungJin1212 SungJin1212 force-pushed the Add-local-cache-to-regexResolver branch 4 times, most recently from 7602f56 to 19d55ef Compare March 20, 2026 12:37
Copy link
Copy Markdown
Member

@friedrichg friedrichg left a comment

Choose a reason for hiding this comment

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

Minor nit only on documenting the experimental feature. merge at will

# CLI flag: -tenant-federation.user-sync-interval
[user_sync_interval: <duration> | default = 5m]

# [Experimental] Cache size of regex match results used by regex resolver.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If it is experimental it should be mentioned in v1-guarantees


"github.com/go-kit/log"
"github.com/go-kit/log/level"
lru "github.com/hashicorp/golang-lru/v2"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lru is the right choice. I feel.

@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Mar 20, 2026
Signed-off-by: SungJin1212 <tjdwls1201@gmail.com>
Signed-off-by: SungJin1212 <tjdwls1201@gmail.com>
Signed-off-by: SungJin1212 <tjdwls1201@gmail.com>
Signed-off-by: SungJin1212 <tjdwls1201@gmail.com>
Signed-off-by: SungJin1212 <tjdwls1201@gmail.com>
@SungJin1212 SungJin1212 force-pushed the Add-local-cache-to-regexResolver branch from 6d36905 to 363d6a5 Compare March 21, 2026 03:51
Signed-off-by: SungJin1212 <tjdwls1201@gmail.com>
@SungJin1212 SungJin1212 merged commit 72da6f6 into cortexproject:master Mar 23, 2026
33 of 35 checks passed
friedrichg pushed a commit that referenced this pull request Apr 17, 2026
* Add local cache to regexResolver

Signed-off-by: SungJin1212 <tjdwls1201@gmail.com>

* Add cache hit/miss metrics

Signed-off-by: SungJin1212 <tjdwls1201@gmail.com>

* Refactor test

Signed-off-by: SungJin1212 <tjdwls1201@gmail.com>

* fix lint

Signed-off-by: SungJin1212 <tjdwls1201@gmail.com>

* update v1-guarantees

Signed-off-by: SungJin1212 <tjdwls1201@gmail.com>

* annotation

Signed-off-by: SungJin1212 <tjdwls1201@gmail.com>

---------

Signed-off-by: SungJin1212 <tjdwls1201@gmail.com>
Signed-off-by: Friedrich Gonzalez <1517449+friedrichg@users.noreply.github.com>
friedrichg pushed a commit that referenced this pull request Apr 17, 2026
* Add local cache to regexResolver

Signed-off-by: SungJin1212 <tjdwls1201@gmail.com>

* Add cache hit/miss metrics

Signed-off-by: SungJin1212 <tjdwls1201@gmail.com>

* Refactor test

Signed-off-by: SungJin1212 <tjdwls1201@gmail.com>

* fix lint

Signed-off-by: SungJin1212 <tjdwls1201@gmail.com>

* update v1-guarantees

Signed-off-by: SungJin1212 <tjdwls1201@gmail.com>

* annotation

Signed-off-by: SungJin1212 <tjdwls1201@gmail.com>

---------

Signed-off-by: SungJin1212 <tjdwls1201@gmail.com>
Signed-off-by: Friedrich Gonzalez <1517449+friedrichg@users.noreply.github.com>
friedrichg pushed a commit that referenced this pull request Apr 17, 2026
* Add local cache to regexResolver

Signed-off-by: SungJin1212 <tjdwls1201@gmail.com>

* Add cache hit/miss metrics

Signed-off-by: SungJin1212 <tjdwls1201@gmail.com>

* Refactor test

Signed-off-by: SungJin1212 <tjdwls1201@gmail.com>

* fix lint

Signed-off-by: SungJin1212 <tjdwls1201@gmail.com>

* update v1-guarantees

Signed-off-by: SungJin1212 <tjdwls1201@gmail.com>

* annotation

Signed-off-by: SungJin1212 <tjdwls1201@gmail.com>

---------

Signed-off-by: SungJin1212 <tjdwls1201@gmail.com>
Signed-off-by: Friedrich Gonzalez <1517449+friedrichg@users.noreply.github.com>
friedrichg added a commit that referenced this pull request Apr 17, 2026
* Add local cache to regexResolver (#7363)

* Add local cache to regexResolver

Signed-off-by: SungJin1212 <tjdwls1201@gmail.com>

* Add cache hit/miss metrics

Signed-off-by: SungJin1212 <tjdwls1201@gmail.com>

* Refactor test

Signed-off-by: SungJin1212 <tjdwls1201@gmail.com>

* fix lint

Signed-off-by: SungJin1212 <tjdwls1201@gmail.com>

* update v1-guarantees

Signed-off-by: SungJin1212 <tjdwls1201@gmail.com>

* annotation

Signed-off-by: SungJin1212 <tjdwls1201@gmail.com>

---------

Signed-off-by: SungJin1212 <tjdwls1201@gmail.com>
Signed-off-by: Friedrich Gonzalez <1517449+friedrichg@users.noreply.github.com>

* Re-order changelog

Signed-off-by: Friedrich Gonzalez <1517449+friedrichg@users.noreply.github.com>

---------

Signed-off-by: SungJin1212 <tjdwls1201@gmail.com>
Signed-off-by: Friedrich Gonzalez <1517449+friedrichg@users.noreply.github.com>
Co-authored-by: SungJin1212 <tjdwls1201@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer size/L type/performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Large tenants are slowing down the query response to cortex when regex_match_enabled= true in tenant_federation

2 participants