Skip to content

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.

# 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.

@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
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
r := p.send(clientIP, reqID, tenantPrefix, tenant, wrReq)
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
@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