-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
ARROW-10526: [FlightRPC][C++] Client cookie middleware #8725
Conversation
lyndonbauto
commented
Nov 20, 2020
- Added client cookie middleware which caches and monitors expiry
- Added testing for client cookie middleware
ParseTimestampStrptime returns time units since the epoch, not time units since now.
[2] Fixed a few bugs with parsing and logic of cookie handling
There appears to be a failure in the python build, I think it's caused by something unrelated to this pull request though, I noticed the same here: https://github.com/apache/arrow/runs/1456411775?check_suite_focus=true |
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.
My main comment here is about the tests - I'd like to see if we can refactor things so that the tests can directly test some of the cookie logic, and so that they don't duplicate said logic in the tests themselves.
Another approach might be to have glass-box tests by having an internal header with the middleware definition, so that tests can directly check the contents of the cookie cache (but so that client code still just gets an opaque middleware instance).
// This test has functions that allow adding and removing cookies from a list of cookies. | ||
// It also automatically adds cookies to an internal list of tracked cookies when they | ||
// are passed to the middleware. | ||
class TestCookieMiddleware : public ::testing::Test { |
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.
This is a general comment, but there's a lot of logic here, and some of it duplicates the logic in the middleware class itself. Can we factor out the cookie parsing into an internal header and add direct tests of that logic, and perhaps reuse some of it here (e.g. splitting and parsing cookies) instead of duplicating it? That would also let us directly test the cookie parsing, instead of indirectly through these tests.
} | ||
} | ||
|
||
DiscardExpiredCookies(); |
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 there any need to discard here if we have to discard before we send cookies anyways?
cookie.has_expiry_ = true; | ||
int64_t seconds = 0; | ||
FixDate(&cookie_attr_value_str); | ||
const char* COOKIE_EXPIRES_FORMAT = "%d %m %Y %H:%M:%S"; |
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.
Can this be moved to an actual constant following the naming convention (kCookieExpiresFormat or similar)?
[2] Added tests for all parsing functions [3] Changes existing tests to use cookie functions directly instead of indirectly [4] Removed duplicated logic
… weren't exported.
@lidavidm That's a really good point, there is a lot of code that wasn't facing direct testing. I followed suggestion of moving the parsing logic to an internal header (the client_header_internal files seemed appropriate since this code is all related to headers). I added a bunch of tests for all the different internal parsing functions that were added. |
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.
Thanks for the changes! I left a few nits, but this is good to go once fixed.
@@ -22,6 +22,8 @@ | |||
|
|||
#include "arrow/flight/client_middleware.h" | |||
#include "arrow/result.h" | |||
#include "arrow/util/optional.h" |
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.
nit: I don't think value_parsing is used in the header, and we're missing #include <mutex>
, and #include <functional>
for binary_function
, #include <string>
, and #include <chrono>
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.
Oh and #include <map>
but perhaps unordered_map is better since you don't care about ordering?
} | ||
|
||
// Function to take a list of cookies and split them into a vector of individual | ||
// cookies. This is done because the cookie cache is a map so ordering is not |
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.
Can we use unordered_map
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.
Yes, good call. Will change this.
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.
Thanks for the changes!
- Added client cookie middleware which caches and monitors expiry - Added testing for client cookie middleware Closes apache#8725 from lyndonb-bq/lyndon/cpp-cookie-support Lead-authored-by: Lyndon Bauto <lyndonb@bitquilltech.com> Co-authored-by: James Duong <jduong@dremio.com> Co-authored-by: Lyndon Bauto <58273576+lyndonb-bq@users.noreply.github.com> Signed-off-by: David Li <li.davidm96@gmail.com>