Skip to content
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

Closed
wants to merge 110 commits into from

Conversation

lyndonbauto
Copy link
Contributor

  • Added client cookie middleware which caches and monitors expiry
  • Added testing for client cookie middleware

@github-actions
Copy link

@lyndonbauto lyndonbauto changed the title ARROW-10526: [FlightRPC][C++][Python] Client cookie middleware ARROW-10526: [FlightRPC][C++] Client cookie middleware Nov 26, 2020
@lyndonbauto lyndonbauto requested a review from lidavidm November 26, 2020 06:42
@lyndonbauto
Copy link
Contributor Author

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

Copy link
Member

@lidavidm lidavidm left a 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 {
Copy link
Member

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();
Copy link
Member

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";
Copy link
Member

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
@lyndonbauto
Copy link
Contributor Author

@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.

@lyndonbauto lyndonbauto requested a review from lidavidm November 27, 2020 22:02
Copy link
Member

@lidavidm lidavidm left a 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"
Copy link
Member

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>

Copy link
Member

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
Copy link
Member

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?

Copy link
Contributor Author

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.

@lyndonbauto lyndonbauto requested a review from lidavidm November 30, 2020 19:09
Copy link
Member

@lidavidm lidavidm left a 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!

@lidavidm lidavidm closed this in b248788 Nov 30, 2020
GeorgeAp pushed a commit to sirensolutions/arrow that referenced this pull request Jun 7, 2021
- 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants