Skip to content
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

feat: adding prefix_prefer_source option #62

Merged
merged 4 commits into from
Jan 25, 2024

Conversation

matthewjstanford
Copy link
Contributor

Adding the ability to use the source requests tenant context as the prefix in the new tenant id.

Resolves #60

processor.go Outdated
if p.cfg.Tenant.Prefix != "" {
tenant = p.cfg.Tenant.Prefix + tenant
if tenantPrefix != "" {
tenant = tenantPrefix + tenant
Copy link
Owner

@blind-oracle blind-oracle Jan 18, 2024

Choose a reason for hiding this comment

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

Why do we need to pass the prefix that deep? I think it's enough just to pass it to dispatch() and there prefix the tenants that are passed to p.send() with it. And if p.cfg.Tenant.Prefix is not set it won't conflict with it. If it's set then they can co-exist I guess.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hm, yeah I hadn't considered that. I could just override p.cfg.Tenant.Prefix when PrefixPreferSource is set. That'd save a lot of these changes.

I'll make those changes and will validate in my setup here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've made these changes, and tested them in my setup and all looks good. And yeah, this dramatically simplifies the change. Thanks for pushing on this one!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, I believe I have addressed your concerns in 2e8c2fa. Please confirm.

README.md Outdated Show resolved Hide resolved
@@ -149,6 +149,12 @@ tenant:
# https://grafana.com/docs/mimir/latest/configure/about-tenant-ids/
# env: CT_TENANT_PREFIX
prefix: foobar-

# If true will use the tenant ID of the inbound request as the prefix of the new tenant id.
Copy link
Owner

Choose a reason for hiding this comment

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

I think we need a bit more detailed description, maybe with a example etc. I didn't get it at first :) Maybe clarify that it takes X-Org-Id header from incoming request, concatenates etc

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added an example inline. Do you think that's sufficient? If not I can add a more detailed example further down in the README.

processor.go Outdated Show resolved Hide resolved
@blind-oracle
Copy link
Owner

I'm not 100% convinced it's the functionality we need, but if that helps somebody and doesn't complicate code much - why not. Conflicts need to be resolved after merging prev PR

Addressing PR comments.
Simplifying PrefixPreferSource logic
Adding example to readme
processor.go Outdated Show resolved Hide resolved
@@ -232,20 +232,6 @@ func Test_request_headers(t *testing.T) {
assert.Equal(t, "my-tenant", string(req.Header.Peek("X-Scope-OrgID")))
}

func Test_request_headers_with_prefix(t *testing.T) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This test is no longer worthwhile, since there is no logic in the fillRequestHeaders() method.

processor.go Outdated
res[idx] = r
}(i, tenant, wrReq)
}(i, tenantPrefix, tenant, wrReq)
Copy link
Owner

Choose a reason for hiding this comment

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

maybe just concat tenant+tenantPrefix here and not pass down to goroutine and send() as a parameter? if prefix is empty it won't make a difference

@blind-oracle blind-oracle merged commit 4867ff5 into blind-oracle:main Jan 25, 2024
1 of 2 checks passed
@blind-oracle
Copy link
Owner

I guess it's now good, thanks!

@matthewjstanford matthewjstanford deleted the prefix_prefer_source branch January 25, 2024 17:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

For tenant prefix, prefer the prometheus tenant id
2 participants