-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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(balancer) add path, uri_capture, and query as hash sources #8701
Conversation
07b54f8
to
314c86f
Compare
1221be5
to
d96568d
Compare
4e86042
to
8c5a917
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why would one use a path
as the hash input? that doesn't make sense to me. Wouldn't it be better to enable using a path-parameter?
Say I have 20 paths defined, all starting like this; /myapp/[userid]/...
. Now the cardinality of the hash is high because there are 20 individual paths, each getting their own hash.
If we'd use just the captured [userid]
element, we'd ensure that all traffic related to a single user would end up on a single backend. This would make more sense imo.
That said, I don't know the origin of this request.
Agree 100%
Ah, you're one step ahead of me in my explanation 😉. This request comes from an enterprise customer who has explicitly named |
@Tieske I've added router URI capture support :) The work for supporting |
What usecase would they be useful for? |
It's the same use-case as |
2c8c1d8
to
34ba8bf
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
still not convinced about the path
option, I'm afraid it's bloat. Then again it's minimal and isolated in a specific corner of the code. So not that big a deal.
34ba8bf
to
a802b1f
Compare
rebased onto latest master + fixed merge conflicts |
a802b1f
to
d519d81
Compare
Kong moderators: please hold off on merge for one more rebase+test cycle. I didn't think we'd be upgrading to OpenResty 1.21.4 in this release cycle, so I'm going to remove the version gate on this perf optimization and rebase+re-push. One moment... EDIT: Code change is done--good to go after CI finishes. |
d519d81
to
5b7b46e
Compare
5b7b46e
to
3a094d0
Compare
@aboudreault anything else I should address before merge, or is this good to go? |
what's left to do will be in EE so you can merge |
This adds
path
,uri_capture
, andquery_arg
as hash sources for upstreams.There are some code simplicity vs performance vs absolute correctness tradeoffs to consider here:
path
sources its value from$uri
, which is normalized according to NGINX rules and notkong.tools.uri.normalize($request_uri)
. The balancer hash is not directly exposed via any public API and is much less sensitive to compatibility issues than other areas of the codebase (i.e.kong.router
), so I think it's okay to not be 100% consistent here.query_arg
usesngx.req.get_uri_args
, which is semi-expensive as it creates a new table (similar tohash_on_header
now). A feature of an upcoming OpenResty release allows optimizing away the table creation (link), which I've accounted for. The benefit of doing this over usingngx.var.arg_{{name}}
is that NGINX handles decoding for us, and that it works for multi-value query string args.