Skip to content

udp: add router for UDP proxy#18791

Merged
mattklein123 merged 93 commits intoenvoyproxy:mainfrom
zhxie:udp-proxy-router
Apr 5, 2022
Merged

udp: add router for UDP proxy#18791
mattklein123 merged 93 commits intoenvoyproxy:mainfrom
zhxie:udp-proxy-router

Conversation

@zhxie
Copy link
Copy Markdown
Contributor

@zhxie zhxie commented Oct 27, 2021

Signed-off-by: Xie Zhihao zhihao.xie@intel.com

Commit Message: udp: add router for UDP proxy
Additional Description: match and route UDP datagrams to different clusters
Risk Level: Medium
Testing: Unit and integration
Docs Changes: UDP proxy example configuration
Release Notes: Added
Platform Specific Features: N/A
Fixes #17652

zhxie added 21 commits August 26, 2021 11:27
Signed-off-by: Xie Zhihao <zhihao.xie@intel.com>
Signed-off-by: Xie Zhihao <zhihao.xie@intel.com>
Signed-off-by: Xie Zhihao <zhihao.xie@intel.com>
Signed-off-by: Xie Zhihao <zhihao.xie@intel.com>
Signed-off-by: Xie Zhihao <zhihao.xie@intel.com>
Signed-off-by: Xie Zhihao <zhihao.xie@intel.com>
Signed-off-by: Xie Zhihao <zhihao.xie@intel.com>
Signed-off-by: Xie Zhihao <zhihao.xie@intel.com>
Signed-off-by: Xie Zhihao <zhihao.xie@intel.com>
Signed-off-by: Xie Zhihao <zhihao.xie@intel.com>
Signed-off-by: Xie Zhihao <zhihao.xie@intel.com>
Signed-off-by: Xie Zhihao <zhihao.xie@intel.com>
Signed-off-by: Xie Zhihao <zhihao.xie@intel.com>
Signed-off-by: Xie Zhihao <zhihao.xie@intel.com>
Signed-off-by: Xie Zhihao <zhihao.xie@intel.com>
Signed-off-by: Xie Zhihao <zhihao.xie@intel.com>
Signed-off-by: Xie Zhihao <zhihao.xie@intel.com>
Signed-off-by: Xie Zhihao <zhihao.xie@intel.com>
@repokitteh-read-only
Copy link
Copy Markdown

As a reminder, PRs marked as draft will not be automatically assigned reviewers,
or be handled by maintainer-oncall triage.

Please mark your PR as ready when you want it to be reviewed!

🐱

Caused by: #18791 was opened by zhxie.

see: more, trace.

@repokitteh-read-only
Copy link
Copy Markdown

CC @envoyproxy/api-shepherds: Your approval is needed for changes made to api/envoy/.
envoyproxy/api-shepherds assignee is @markdroth
CC @envoyproxy/api-watchers: FYI only for changes made to api/envoy/.

🐱

Caused by: #18791 was opened by zhxie.

see: more, trace.

@zhxie
Copy link
Copy Markdown
Contributor Author

zhxie commented Oct 27, 2021

Though this PR is working in progress, docs changed and testings have not been completed, I would like to ask @mattklein123 for a pre-review.

This patch is a update to #17864 which uses the generic matching API #17633 you metioned, but since the prefix/custom generic matching API is not completed, This patch does not support prefix-range-like matching compared with #17864.

zhxie added 2 commits October 27, 2021 13:03
Signed-off-by: Xie Zhihao <zhihao.xie@intel.com>
Signed-off-by: Xie Zhihao <zhihao.xie@intel.com>
@repokitteh-read-only
Copy link
Copy Markdown

CC @envoyproxy/api-shepherds: Your approval is needed for changes made to (api/envoy/|docs/root/api-docs/).
envoyproxy/api-shepherds assignee is @markdroth
CC @envoyproxy/api-watchers: FYI only for changes made to (api/envoy/|docs/root/api-docs/).

🐱

Caused by: #18791 was synchronize by zhxie.

see: more, trace.

Signed-off-by: Xie Zhihao <zhihao.xie@intel.com>
Copy link
Copy Markdown
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks very nice. Flushing out some small comments.

/wait

useful in support systems such as CI, CD, etc. The
:ref:`schema validator check tool <install_tools_schema_validator_check_tool>` has been added
to the tools image.
* udp_proxy: added :ref:`matcher <envoy_v3_api_field_extensions.filters.udp.udp_proxy.v3.UdpProxyConfig.matcher>` to support matching and routing to different clusters.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a note in deprecated below for the deprecated field.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, added.

Network::Address::InstanceConstSharedPtr source_address) const PURE;

/**
* Returns all cluster names in the router. The UDP proxy filter requires every cluster names for
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Returns all cluster names in the router. The UDP proxy filter requires every cluster names for
* Returns all cluster names in the router. The UDP proxy filter requires every cluster name for

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, changed.

RouterImpl::RouterImpl(const envoy::extensions::filters::udp::udp_proxy::v3::UdpProxyConfig& config,
Server::Configuration::ServerFactoryContext& factory_context) {
if (config.has_cluster()) {
cluster_ = config.cluster();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be a bit cleaner to just synthesize matcher config for this case. Then you can use unified code for the rest of it? (Basically it makes the deprecated path cheaper to maintain and understand as the only special case is here.)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am sorry but I cannot catch your idea here. Do you mention we can move cluster_ out of Router?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I catch your thought finally, I will submit the commit soon.

return cluster_.value();
}

if (source_address->ip()) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically isn't it possible to send UDP/datagrams over a pipe? Or do we block this in config? Either way it seems like this should be handled elsewhere as a config load issue vs. on every route request?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is redundant. I will remove it, thanks.

return;
}

ENVOY_LOG(debug, "udp proxy: detaching from cluster {}", cluster);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this log is now misleading. I would see if the cluster is used before logging and erasing? If you store an iterator the perf delta will be negligible.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, fixed.

Comment on lines +29 to +30
route(Network::Address::InstanceConstSharedPtr destination_address,
Network::Address::InstanceConstSharedPtr source_address) const PURE;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I would pass by const ref to avoid shared_ptr inc/dec

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I will make them const.
By the way, InstanceConstSharedPtr is a shared_ptr<const Instance>. I think it is not necessary to change to a const ref since the const Instance cannot be changed.

zhxie added 5 commits March 31, 2022 11:14
Signed-off-by: Xie Zhihao <zhihao.xie@intel.com>
Signed-off-by: Xie Zhihao <zhihao.xie@intel.com>
Signed-off-by: Xie Zhihao <zhihao.xie@intel.com>
Signed-off-by: Xie Zhihao <zhihao.xie@intel.com>
Signed-off-by: Xie Zhihao <zhihao.xie@intel.com>
Signed-off-by: Xie Zhihao <zhihao.xie@intel.com>
Copy link
Copy Markdown
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks LGTM other than small comment and fixing CI.

/wait

virtual const std::string
route(Network::Address::InstanceConstSharedPtr destination_address,
Network::Address::InstanceConstSharedPtr source_address) const PURE;
route(const Network::Address::InstanceConstSharedPtr destination_address,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I meant const Network::Address::Instance&

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const std::string& route = config_->route(data.addresses_.local_, data.addresses_.peer_);

In the caller method, we will get a InstanceConstSharedPtr. If we change the Router::route's signature to const Network::Address::Instance&, we have to change the code in the caller to

const std::string& route = config_->route(*data.addresses_.local_, *data.addresses_.peer_); 

Do you think it is acceptable?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, I have updated all methods in the caller chain.

Signed-off-by: Xie Zhihao <zhihao.xie@intel.com>
zhxie added 2 commits April 1, 2022 10:37
Signed-off-by: Xie Zhihao <zhihao.xie@intel.com>
Signed-off-by: Xie Zhihao <zhihao.xie@intel.com>
@zhxie
Copy link
Copy Markdown
Contributor Author

zhxie commented Apr 1, 2022

It is strange that the patch does not touch any codes in source/common/http but the CI complains low coverage on it.

/retest

@repokitteh-read-only
Copy link
Copy Markdown

Retrying Azure Pipelines:
Retried failed jobs in: envoy-presubmit

🐱

Caused by: a #18791 (comment) was created by @zhxie.

see: more, trace.

@zhxie
Copy link
Copy Markdown
Contributor Author

zhxie commented Apr 2, 2022

Flaky macOS test.

/retest

@repokitteh-read-only
Copy link
Copy Markdown

Retrying Azure Pipelines:
Retried failed jobs in: envoy-presubmit

🐱

Caused by: a #18791 (comment) was created by @zhxie.

see: more, trace.

Copy link
Copy Markdown
Member

@mattklein123 mattklein123 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. Great work!

@repokitteh-read-only repokitteh-read-only bot removed the api label Apr 5, 2022
@mattklein123 mattklein123 merged commit 90a1d4b into envoyproxy:main Apr 5, 2022
phlax added a commit to phlax/envoy that referenced this pull request Apr 5, 2022
This reverts commit 90a1d4b.

Signed-off-by: Ryan Northey <ryan@synca.io>
ravenblackx pushed a commit to ravenblackx/envoy that referenced this pull request Jun 8, 2022
Signed-off-by: Xie Zhihao <zhihao.xie@intel.com>
@zhxie zhxie deleted the udp-proxy-router branch September 7, 2022 08:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Route UDP packets to different upstreams based on origin IP

6 participants