-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Add terminal attribute to request hash. #4292
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
Changes from 3 commits
52c6cf6
5adeff2
dff9c22
987179c
450448b
c93bd57
261ae3a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -585,6 +585,18 @@ message RouteAction { | |
| // Connection properties hash policy. | ||
| ConnectionProperties connection_properties = 3; | ||
| } | ||
| // Reserve for new policy_specifier. | ||
| /* RESERVED */ reserved 4 to 20; | ||
|
|
||
| // If true, and there is already a hash computed, ignore rest of the | ||
| // list of hash polices. | ||
| // For example, if the following hash methods are configured: | ||
| // [(specifier, terminal),...] | ||
| // [(Header A, true), | ||
| // (Cookie B, false), | ||
| // (Cookie C, false)] | ||
| // The generateHash process ends after computing "header A", as it's a terminal policy. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add to the commit message and comments here the motivation for the terminal attribute; is there some real-world use case where this is important? Knowing what you are working on, I'm sure there is, but it would be helpful to share. |
||
| bool terminal = 21; | ||
| } | ||
|
|
||
| // Specifies a list of hash policies to use for ring hash load balancing. Each | ||
|
|
@@ -596,7 +608,9 @@ message RouteAction { | |
| // hash policies fail to generate a hash, no hash will be produced for | ||
| // the route. In this case, the behavior is the same as if no hash policies | ||
| // were specified (i.e. the ring hash load balancer will choose a random | ||
| // backend). | ||
| // backend). If a hash policy has the "terminal" attribute set to true, and | ||
| // there is already a hash generated, the hash is returned immediately, | ||
| // ignoring the rest of the hash policy list. | ||
| repeated HashPolicy hash_policy = 15; | ||
|
|
||
| // Indicates that a HTTP/1.1 client connection to this particular route is allowed to | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1699,6 +1699,63 @@ TEST_F(RouterMatcherHashPolicyTest, HashMultiple) { | |
| EXPECT_NE(hash_h, hash_both); | ||
| } | ||
|
|
||
| TEST_F(RouterMatcherHashPolicyTest, HashTerminal) { | ||
| // Hash pilicy list: cookie, header [terminal=true], user_ip. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: policy
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oops. |
||
| auto route = route_config_.mutable_virtual_hosts(0)->mutable_routes(0)->mutable_route(); | ||
| route->add_hash_policy()->mutable_cookie()->set_name("cookie_hash"); | ||
| auto* header_hash = route->add_hash_policy(); | ||
| header_hash->mutable_header()->set_header_name("foo_header"); | ||
| header_hash->set_terminal(true); | ||
| route->add_hash_policy()->mutable_connection_properties()->set_source_ip(true); | ||
| Network::Address::Ipv4Instance address1("4.3.2.1"); | ||
| Network::Address::Ipv4Instance address2("1.2.3.4"); | ||
|
|
||
| uint64_t hash_1, hash_2; | ||
| // Test terminal works when there is hash computed, the rest of the policy | ||
| // list is ignored. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add a note about how these are using different addresses? It was hard to make out the one-character difference at first glance.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, and done.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. test 123 ( I don't know how github UI works) |
||
| { | ||
| Http::TestHeaderMapImpl headers = genHeaders("www.lyft.com", "/foo", "GET"); | ||
| headers.addCopy("Cookie", "cookie_hash=foo;"); | ||
| headers.addCopy("foo_header", "bar"); | ||
| Router::RouteConstSharedPtr route = config().route(headers, 0); | ||
| hash_1 = route->routeEntry() | ||
| ->hashPolicy() | ||
| ->generateHash(&address1, headers, add_cookie_nop_) | ||
| .value(); | ||
| } | ||
| { | ||
| Http::TestHeaderMapImpl headers = genHeaders("www.lyft.com", "/foo", "GET"); | ||
| headers.addCopy("Cookie", "cookie_hash=foo;"); | ||
| headers.addCopy("foo_header", "bar"); | ||
| Router::RouteConstSharedPtr route = config().route(headers, 0); | ||
| hash_2 = route->routeEntry() | ||
| ->hashPolicy() | ||
| ->generateHash(&address2, headers, add_cookie_nop_) | ||
| .value(); | ||
| } | ||
| EXPECT_EQ(hash_1, hash_2); | ||
|
|
||
| // If no hash computed after evaluating a hash policy, the rest of the policy | ||
| // list is evaluated. | ||
| { | ||
| Http::TestHeaderMapImpl headers = genHeaders("www.lyft.com", "/foo", "GET"); | ||
| Router::RouteConstSharedPtr route = config().route(headers, 0); | ||
| hash_1 = route->routeEntry() | ||
| ->hashPolicy() | ||
| ->generateHash(&address1, headers, add_cookie_nop_) | ||
| .value(); | ||
| } | ||
| { | ||
| Http::TestHeaderMapImpl headers = genHeaders("www.lyft.com", "/foo", "GET"); | ||
| Router::RouteConstSharedPtr route = config().route(headers, 0); | ||
| hash_2 = route->routeEntry() | ||
| ->hashPolicy() | ||
| ->generateHash(&address2, headers, add_cookie_nop_) | ||
| .value(); | ||
| } | ||
| EXPECT_NE(hash_1, hash_2); | ||
| } | ||
|
|
||
| TEST_F(RouterMatcherHashPolicyTest, InvalidHashPolicies) { | ||
| NiceMock<Server::Configuration::MockFactoryContext> factory_context; | ||
| { | ||
|
|
||
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.
Out of curiosity, why are we reserving these field numbers?
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.
I think we will add more hash method into the oneof list above and I naively think it'd be nice if we have a ascending order for all the policy_specifier to be added.
Revert it as it's not the general recognition.