Add cookie based routing for selected paths#188
Conversation
|
I have not reviewed the code yet but the description of this PR should be improved and added to the docs. Also we should consider how this relates to the work from @vishalya in terms of pluggable strategies. Imho we should have a default ordered list of strategies that are used out of the box, but it should be possible to activate and deactivate any strategy and also potentially change the order/priority. |
|
Does the rule engine take a lower precedence for a cookie path? |
|
Please rebase after #265 gets merged. + docs on precedence over rule/queryid based routing would be great |
62d579a to
4d0854c
Compare
Yes. Similar to a queryId, the presence of a cookie along with a path in Hopefully the relationships between the different routing strategies are more clear now that this is rebased and includes the refactoring I did of of |
1d61bb9 to
3e9102a
Compare
mosabua
left a comment
There was a problem hiding this comment.
Started review .. will continue later
|
First review round completed. Looks like its in pretty good shape .. please rebase, update naming and such and let me know when its ready again. |
| session cookie if none exists. If a cookie exists, route the request to | ||
| the backend associated with that cookie. | ||
|
|
||
| `removeCookiePaths`: If the request URI starts with a path in this list, |
There was a problem hiding this comment.
Why would you need user to configure this? Other than logout?
45eb2d0 to
d9e342c
Compare
d9e342c to
5a659c3
Compare
|
I saw a NPE error but the test passed. Is this expected? |
|
I don't understand why we have to store the cookie into database. |
The cookie only contains a session id, it does not identify the backend. Are you suggesting using a custom cookie instead of the Jetty session cookie? |
Yea. I'm not familiar with HTTP cookie. Could a cookie be |
It could, the content of a cookie can be anything under 4kB. They also may have attributes such as IMO the decision between using Jetty's ootb session management, as I'm doing here, and a custom cookie like |
8ccc6f8 to
3e67db8
Compare
| Callback callback) | ||
| { | ||
| try { | ||
| String requestPath = request.getRequestURI(); |
There was a problem hiding this comment.
this code block was extracted to recordBackendForQueryId
|
@mosabua I will update the docs once I get confirmation from @oneonestar, @Chaho12 and @vishalya that the new approach is directionally correct |
|
Sounds good |
|
Excellent! Signed cookie and stateless server are exactly what I thought of. |
oneonestar
left a comment
There was a problem hiding this comment.
We could store the routing info in JWT and then store it in cookie.
Advantages:
- Delegate the signature / verification to JWT lib
- Able to update the HMAC algorithm in the future (eg. HmacSHA256 -> ECDSASHA256)
- Some fields are standardised, can avoid ambiguous (iat = issue at, exp = expiration time)
6795791 to
84f93c1
Compare
| to determine which backend handled the previous request based solely on | ||
| the request URI and body. | ||
|
|
||
| #### Cookie Based Routing Configuration |
b32b0dd to
2b31fad
Compare
oneonestar
left a comment
There was a problem hiding this comment.
Looks good. Just a few minor comments.
2b31fad to
5b1e222
Compare
5b1e222 to
34c9b34
Compare
mosabua
left a comment
There was a problem hiding this comment.
I think this is in a good enough shape now and we should merge. Any objections @oneonestar @vishalya @Chaho12 ?
|
Merging this. Any further concerns can be addressed in follow up PRs. |
This adds an additional routing strategy for the Gateway. Currently the Gateway checks all incoming requests for a query ID. If one is found, the cluster running that query is looked up and the query is routed to that cluster. All other requests are sent to a semi random backend cluster in the routing group chosen by the
RoutingGroupSelectorbased on the information present in the request. These routing strategies are not sufficient to solve issues such as #165. For #165, the Gateway needs the capability to route a request to the same backend that a previous request was sent to.This adds the ability to add a session cookie, and to map that session cookie to a specific backend. This is lower precedence than the queryID based routing. Cookie based routing is performed only for paths in a configurable list. OAuth with multiple backends in a routing group (#165) can be solved by configuring
cookiePaths: ['/oauth2/callback']. Finally, a cookie will be deleted if a request is made to a patch in thelogOutCookiePathslist.