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
[Proxy] Support for setting proxy for addresses #34617
Conversation
31130de
to
b788d69
Compare
Ready for review. Does not have a second variable (one for ranges of included addresses) |
Automated fix for refs/heads/tasks/outgoing-proxy
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 looks like the right general approach.
Please let me know if you have any questions. Thanks!
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.
Thank you for the review. I addressed the comments.
…include-addresses
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.
Thank you for the review. I implemented environment variable and channel argument for including addresses.
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 looks good overall! Comments are all minor.
Please let me know if you have any questions. Thanks!
@@ -32,12 +36,55 @@ | |||
#include "test/core/util/scoped_env_var.h" | |||
#include "test/core/util/test_config.h" | |||
|
|||
// Need to be in the same namespace as absl::optional... | |||
namespace absl { |
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 not okay to put code into the absl
namespace, since we don't own that namespace.
Instead, I suggest you change the matcher to explictly print whatever you want. For example, you can replace line 85 with the following:
if (*address_string != address) {
*result_listener << "Actual address: " << *address_string;
return false;
}
return true;
Alternatively, you can explicitly print things in the individual tests via something like this:
EXPECT_THAT(address, AddressEq("1.2.3.4"))
<< grpc_sockaddr_to_string(address, true).value_or("unknown");
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 removed these function, but I would like to suggest considering building a library of functions as it would be a significant boost to productivity. E.g. we could consider moving AddressEq
matcher to a shared header.
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'd be fine with having a common library of matchers. We already have a similar one here:
MATCHER_P(EqualsAddress, address_str, "") { |
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.
Ack. Will do some code search in our code base at a later point and see if we can consolidate/reuse matchers.
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.
Thank you for the review. Please take another look.
@@ -32,12 +36,55 @@ | |||
#include "test/core/util/scoped_env_var.h" | |||
#include "test/core/util/test_config.h" | |||
|
|||
// Need to be in the same namespace as absl::optional... | |||
namespace absl { |
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 removed these function, but I would like to suggest considering building a library of functions as it would be a significant boost to productivity. E.g. we could consider moving AddressEq
matcher to a shared header.
mask_bits); | ||
} | ||
return false; | ||
} | ||
|
||
bool AddressIncluded( | ||
const absl::StatusOr<grpc_resolved_address>& target_address, |
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.
Does not work, absl::nullopt_t can not be converted to grpc_resolved_address:
external/com_google_absl/absl/status/statusor.h:779:10: error: no viable conversion from returned value of type 'const absl::nullopt_t' to function return type 'grpc_resolved_address'
I think there's no harm in leaving StatusOr.
Automated fix for refs/heads/tasks/outgoing-proxy
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.
Only minor comments remaining, feel free to merge after addressing. Thanks!
absl::string_view host_name, absl::string_view addresses_and_subnets) { | ||
for (absl::string_view entry : | ||
absl::StrSplit(addresses_and_subnets, ',', absl::SkipEmpty())) { | ||
if (ExactMatchOrSubdomain(host_name, entry) || |
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 should call absl::StripAsciiWhitespace()
just once here, rather than doing it separately in each of ExactMatchOrSubdomain()
and ServerInCIDRRange()
.
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.
Done
mask_bits); | ||
} | ||
return false; | ||
} | ||
|
||
bool AddressIncluded( | ||
const absl::StatusOr<grpc_resolved_address>& target_address, |
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 using StatusOr<>
seems like a very strange API for this function, since the function doesn't need the status; it just needs to know if there's an address that it should check for a CIDR range.
Same thing for ServerInCIDRRange()
-- I think that function should go back to taking const grpc_resolved_address&
, and the caller should not call it in the first place if there was no address to check.
Even if .value_or()
doesn't work in this case, it's not hard for the caller to deal with this:
absl::StatusOr<grpc_resolved_address> address = StringToSockaddr(server_host, 0);
absl::optional<grpc_resolved_address> addr;
if (address.has_value()) addr = *address;
@@ -32,12 +36,55 @@ | |||
#include "test/core/util/scoped_env_var.h" | |||
#include "test/core/util/test_config.h" | |||
|
|||
// Need to be in the same namespace as absl::optional... | |||
namespace absl { |
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'd be fine with having a common library of matchers. We already have a similar one here:
MATCHER_P(EqualsAddress, address_str, "") { |
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.
Thank you. Updated.
absl::string_view host_name, absl::string_view addresses_and_subnets) { | ||
for (absl::string_view entry : | ||
absl::StrSplit(addresses_and_subnets, ',', absl::SkipEmpty())) { | ||
if (ExactMatchOrSubdomain(host_name, entry) || |
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.
Done
mask_bits); | ||
} | ||
return false; | ||
} | ||
|
||
bool AddressIncluded( | ||
const absl::StatusOr<grpc_resolved_address>& target_address, |
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.
Done
@@ -32,12 +36,55 @@ | |||
#include "test/core/util/scoped_env_var.h" | |||
#include "test/core/util/test_config.h" | |||
|
|||
// Need to be in the same namespace as absl::optional... | |||
namespace absl { |
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.
Ack. Will do some code search in our code base at a later point and see if we can consolidate/reuse matchers.
Fixes #33518.