-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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 all 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 |
|---|---|---|
|
|
@@ -1699,6 +1699,65 @@ TEST_F(RouterMatcherHashPolicyTest, HashMultiple) { | |
| EXPECT_NE(hash_h, hash_both); | ||
| } | ||
|
|
||
| TEST_F(RouterMatcherHashPolicyTest, HashTerminal) { | ||
| // Hash policy list: cookie, header [terminal=true], user_ip. | ||
| 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. | ||
| { | ||
| // Input: {}, {}, address1. Hash on address1. | ||
| 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(); | ||
| } | ||
| { | ||
| // Input: {}, {}, address2. Hash on address2. | ||
| 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.
Is this only about performance, or is there a functional aspect? I.e. avoiding taking unnecessary detail into account when computing the hash? We can talk IRL tomorrow if it would be easier to describe the use case then.
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.
It's about functionality: it provides a fallback for a primary hash method when it didn't work. The performance part is a little gain comes with this attribute.
Updated the PR description to sate it a little bit more clear. Thanks for pointing it out!