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

[Proxy] Support for setting proxy for addresses #34617

Merged
merged 18 commits into from Oct 18, 2023

Conversation

eugeneo
Copy link
Contributor

@eugeneo eugeneo commented Oct 6, 2023

Fixes #33518.

@eugeneo
Copy link
Contributor Author

eugeneo commented Oct 11, 2023

Ready for review. Does not have a second variable (one for ranges of included addresses)

@eugeneo eugeneo marked this pull request as ready for review October 12, 2023 16:44
Copy link
Member

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

src/core/ext/filters/client_channel/http_proxy_mapper.cc Outdated Show resolved Hide resolved
src/core/ext/filters/client_channel/http_proxy_mapper.h Outdated Show resolved Hide resolved
src/core/ext/filters/client_channel/http_proxy_mapper.h Outdated Show resolved Hide resolved
include/grpc/impl/channel_arg_names.h Outdated Show resolved Hide resolved
test/core/client_channel/http_proxy_mapper_test.cc Outdated Show resolved Hide resolved
include/grpc/impl/channel_arg_names.h Outdated Show resolved Hide resolved
test/core/client_channel/http_proxy_mapper_test.cc Outdated Show resolved Hide resolved
test/core/client_channel/http_proxy_mapper_test.cc Outdated Show resolved Hide resolved
test/core/client_channel/http_proxy_mapper_test.cc Outdated Show resolved Hide resolved
Copy link
Contributor Author

@eugeneo eugeneo left a 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.

src/core/ext/filters/client_channel/http_proxy_mapper.cc Outdated Show resolved Hide resolved
include/grpc/impl/channel_arg_names.h Outdated Show resolved Hide resolved
src/core/ext/filters/client_channel/http_proxy_mapper.h Outdated Show resolved Hide resolved
test/core/client_channel/http_proxy_mapper_test.cc Outdated Show resolved Hide resolved
test/core/client_channel/http_proxy_mapper_test.cc Outdated Show resolved Hide resolved
test/core/client_channel/http_proxy_mapper_test.cc Outdated Show resolved Hide resolved
test/core/client_channel/http_proxy_mapper_test.cc Outdated Show resolved Hide resolved
include/grpc/impl/channel_arg_names.h Outdated Show resolved Hide resolved
Copy link
Contributor Author

@eugeneo eugeneo left a 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.

src/core/ext/filters/client_channel/http_proxy_mapper.cc Outdated Show resolved Hide resolved
include/grpc/impl/channel_arg_names.h Outdated Show resolved Hide resolved
Copy link
Member

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

src/core/ext/filters/client_channel/http_proxy_mapper.cc Outdated Show resolved Hide resolved
src/core/ext/filters/client_channel/http_proxy_mapper.cc Outdated Show resolved Hide resolved
src/core/ext/filters/client_channel/http_proxy_mapper.cc Outdated Show resolved Hide resolved
src/core/ext/filters/client_channel/http_proxy_mapper.cc Outdated Show resolved Hide resolved
src/core/ext/filters/client_channel/http_proxy_mapper.cc Outdated Show resolved Hide resolved
@@ -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 {
Copy link
Member

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");

Copy link
Contributor Author

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.

Copy link
Member

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, "") {

Copy link
Contributor Author

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.

test/core/client_channel/http_proxy_mapper_test.cc Outdated Show resolved Hide resolved
Copy link
Contributor Author

@eugeneo eugeneo left a 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.

test/core/client_channel/http_proxy_mapper_test.cc Outdated Show resolved Hide resolved
@@ -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 {
Copy link
Contributor Author

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.

src/core/ext/filters/client_channel/http_proxy_mapper.cc Outdated Show resolved Hide resolved
src/core/ext/filters/client_channel/http_proxy_mapper.cc Outdated Show resolved Hide resolved
src/core/ext/filters/client_channel/http_proxy_mapper.cc Outdated Show resolved Hide resolved
mask_bits);
}
return false;
}

bool AddressIncluded(
const absl::StatusOr<grpc_resolved_address>& target_address,
Copy link
Contributor Author

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.

src/core/ext/filters/client_channel/http_proxy_mapper.cc Outdated Show resolved Hide resolved
Copy link
Member

@markdroth markdroth left a 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) ||
Copy link
Member

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().

Copy link
Contributor Author

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

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

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, "") {

Copy link
Contributor Author

@eugeneo eugeneo left a 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) ||
Copy link
Contributor Author

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

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

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.

@eugeneo eugeneo enabled auto-merge (squash) October 18, 2023 23:11
@eugeneo eugeneo merged commit 1a76e7c into grpc:master Oct 18, 2023
53 of 70 checks passed
@eugeneo eugeneo deleted the tasks/outgoing-proxy branch October 19, 2023 16:32
@copybara-service copybara-service bot added the imported Specifies if the PR has been imported to the internal repository label Oct 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bloat/none imported Specifies if the PR has been imported to the internal repository lang/core per-call-memory/neutral per-channel-memory/neutral release notes: yes Indicates if PR needs to be in release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for HTTP CONNECT for L7 load balancing
3 participants