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

tcp_proxy: add support for weighted clusters #4430

Merged
merged 8 commits into from Sep 24, 2018

Conversation

@venilnoronha
Copy link
Member

@venilnoronha venilnoronha commented Sep 14, 2018

Description:
This PR adds support for optional weighted clusters in TCP Proxy.

Signed-off-by: Venil Noronha veniln@vmware.com

Risk Level: Med
Testing: Added 2 new tests
Docs Changes: N/A
Release Notes: Introduced weighted clusters in version_history.rst

/cc @rshriram

Signed-off-by: Venil Noronha <veniln@vmware.com>
Copy link
Contributor

@ggreenway ggreenway left a comment

I skimmed this and it looks good. I'll take a closer look when it's no longer [WIP]

@ggreenway ggreenway self-assigned this Sep 15, 2018
// When a request matches the route, the choice of an upstream cluster is
// determined by its weight. The sum of weights across all entries in the
// clusters array determines the total weight.
google.protobuf.UInt32Value weight = 2 [(validate.rules).uint32.gte = 1];

This comment has been minimized.

@ggreenway

ggreenway Sep 15, 2018
Contributor

uint32, not g.p.UInt32Value

This comment has been minimized.

@venilnoronha

venilnoronha Sep 15, 2018
Author Member

Addressed in 9c55555.

P.S. I'm amazed at the number of fives in the hash. :)

Signed-off-by: Venil Noronha <veniln@vmware.com>
@venilnoronha
Copy link
Member Author

@venilnoronha venilnoronha commented Sep 15, 2018

I marked it WIP as I was thinking of moving WeightedCluster (which is common to thrift_proxy) to a common location. Do you think we should do that?

Signed-off-by: Venil Noronha <veniln@vmware.com>
@venilnoronha venilnoronha force-pushed the venilnoronha:tcp-weighted-clusters branch to 9dadee9 Sep 15, 2018
Signed-off-by: Venil Noronha <veniln@vmware.com>
@venilnoronha venilnoronha force-pushed the venilnoronha:tcp-weighted-clusters branch to ed031a2 Sep 19, 2018
@venilnoronha venilnoronha changed the title [WIP] tcp_proxy: add support for weighted clusters tcp_proxy: add support for weighted clusters Sep 19, 2018
// criteria. Only endpoints in the upstream cluster with metadata
// matching that set in metadata_match will be considered. The filter
// name should be specified as *envoy.lb*.
envoy.api.v2.core.Metadata metadata_match = 3;

This comment has been minimized.

@ggreenway

ggreenway Sep 19, 2018
Contributor

What's the rationale for adding these two new fields in this PR? They're not implemented, so unless there's a good reason, let's wait to add them until they're implemented.

This comment has been minimized.

@venilnoronha

venilnoronha Sep 19, 2018
Author Member

Reverted in 0834714.

@@ -146,13 +147,28 @@ message TcpProxy {
// The router selects an upstream cluster based on these weights.
message WeightedCluster {
message ClusterWeight {
// Name of the upstream cluster.
// Name of the upstream cluster. The cluster must exist in the

This comment has been minimized.

@ggreenway

ggreenway Sep 19, 2018
Contributor

I don't think this change is correct. The tcp_proxy handles the case of a missing cluster.

This comment has been minimized.

@venilnoronha

venilnoronha Sep 19, 2018
Author Member

Reverted in 0834714.

This reverts commit ed031a2.

Signed-off-by: Venil Noronha <veniln@vmware.com>
@venilnoronha venilnoronha force-pushed the venilnoronha:tcp-weighted-clusters branch 3 times, most recently to 9dadee9 Sep 19, 2018
// Weighted clusters will be enabled only if both the default cluster and
// deprecated v1 routes are absent.
if (routes_.empty() && config.has_weighted_clusters()) {
total_cluster_weight_ = 0UL;

This comment has been minimized.

@ggreenway

ggreenway Sep 20, 2018
Contributor

0; (UL suffix isn't needed).

This comment has been minimized.

@venilnoronha

venilnoronha Sep 20, 2018
Author Member

Addressed in 99352da.

// Find the right cluster to route to based on the interval in which
// the selected value falls. The intervals are determined as
// [0, cluster1_weight), [cluster1_weight, cluster1_weight+cluster2_weight),..
for (const WeightedClusterEntry& cluster : weighted_clusters_) {

This comment has been minimized.

@ggreenway

ggreenway Sep 20, 2018
Contributor

This code is duplicate of the same thing in thrift_proxy. Is there any way to share the code for this algorithm? Maybe a templatized function just for the algorithm, so you don't need to make the entries be a common type?

This comment has been minimized.

@rshriram

rshriram Sep 21, 2018
Member

And that is a dupe of code in hcm

This comment has been minimized.

@venilnoronha

venilnoronha Sep 21, 2018
Author Member

Addressed in 9dce4f5.

Signed-off-by: Venil Noronha <veniln@vmware.com>
Signed-off-by: Venil Noronha <veniln@vmware.com>
@venilnoronha venilnoronha requested a review from zuercher as a code owner Sep 21, 2018
Copy link
Contributor

@ggreenway ggreenway left a comment

Thanks for refactoring that.

@@ -83,8 +84,9 @@ Config::Config(const envoy::config::filter::network::tcp_proxy::v2::TcpProxy& co
total_cluster_weight_ = 0;
for (const envoy::config::filter::network::tcp_proxy::v2::TcpProxy::WeightedCluster::
ClusterWeight& cluster_desc : config.weighted_clusters().clusters()) {
weighted_clusters_.emplace_back(WeightedClusterEntry(cluster_desc));
total_cluster_weight_ += weighted_clusters_.back().cluster_weight_;
std::unique_ptr<WeightedClusterEntry> cluster_entry(new WeightedClusterEntry(cluster_desc));

This comment has been minimized.

@ggreenway

ggreenway Sep 21, 2018
Contributor

nit: std::make_unique, instead of new

This comment has been minimized.

@venilnoronha

venilnoronha Sep 21, 2018
Author Member

Fixed in af356c1.

const std::string cluster_name_;
const uint64_t cluster_weight_;
};
typedef std::shared_ptr<WeightedClusterEntry> WeightedClusterEntrySharedPtr;

This comment has been minimized.

@ggreenway

ggreenway Sep 21, 2018
Contributor

I think this can be a unique_ptr instead of shared_ptr. I don't think these are ever shared.

This comment has been minimized.

@venilnoronha

venilnoronha Sep 21, 2018
Author Member

Fixed in af356c1.

Signed-off-by: Venil Noronha <veniln@vmware.com>
Copy link
Contributor

@ggreenway ggreenway left a comment

LGTM. Thanks!

@venilnoronha
Copy link
Member Author

@venilnoronha venilnoronha commented Sep 21, 2018

@ggreenway @rshriram thanks for reviewing!

@ggreenway ggreenway merged commit 10625c5 into envoyproxy:master Sep 24, 2018
12 checks passed
12 checks passed
DCO DCO
Details
ci/circleci: api Your tests passed on CircleCI!
Details
ci/circleci: asan Your tests passed on CircleCI!
Details
ci/circleci: build_image Your tests passed on CircleCI!
Details
ci/circleci: coverage Your tests passed on CircleCI!
Details
ci/circleci: docs Your tests passed on CircleCI!
Details
ci/circleci: filter_example_mirror Your tests passed on CircleCI!
Details
ci/circleci: format Your tests passed on CircleCI!
Details
ci/circleci: ipv6_tests Your tests passed on CircleCI!
Details
ci/circleci: mac Your tests passed on CircleCI!
Details
ci/circleci: release Your tests passed on CircleCI!
Details
ci/circleci: tsan Your tests passed on CircleCI!
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.