tcp_proxy: add support for weighted clusters#4430
tcp_proxy: add support for weighted clusters#4430ggreenway merged 8 commits intoenvoyproxy:masterfrom
Conversation
Signed-off-by: Venil Noronha <veniln@vmware.com>
ggreenway
left a comment
There was a problem hiding this comment.
I skimmed this and it looks good. I'll take a closer look when it's no longer [WIP]
| // 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]; |
There was a problem hiding this comment.
Addressed in 9c55555.
P.S. I'm amazed at the number of fives in the hash. :)
Signed-off-by: Venil Noronha <veniln@vmware.com>
|
I marked it WIP as I was thinking of moving |
Signed-off-by: Venil Noronha <veniln@vmware.com>
506dd06 to
9dadee9
Compare
Signed-off-by: Venil Noronha <veniln@vmware.com>
5a1196a to
ed031a2
Compare
| // 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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Reverted in 0834714.
| message WeightedCluster { | ||
| message ClusterWeight { | ||
| // Name of the upstream cluster. | ||
| // Name of the upstream cluster. The cluster must exist in the |
There was a problem hiding this comment.
I don't think this change is correct. The tcp_proxy handles the case of a missing cluster.
There was a problem hiding this comment.
Reverted in 0834714.
This reverts commit ed031a2. Signed-off-by: Venil Noronha <veniln@vmware.com>
d6c0c5c to
9dadee9
Compare
source/common/tcp_proxy/tcp_proxy.cc
Outdated
| // 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; |
source/common/tcp_proxy/tcp_proxy.cc
Outdated
| // 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_) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
And that is a dupe of code in hcm
Signed-off-by: Venil Noronha <veniln@vmware.com>
Signed-off-by: Venil Noronha <veniln@vmware.com>
ggreenway
left a comment
There was a problem hiding this comment.
Thanks for refactoring that.
source/common/tcp_proxy/tcp_proxy.cc
Outdated
| 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)); |
There was a problem hiding this comment.
nit: std::make_unique, instead of new
source/common/tcp_proxy/tcp_proxy.h
Outdated
| const std::string cluster_name_; | ||
| const uint64_t cluster_weight_; | ||
| }; | ||
| typedef std::shared_ptr<WeightedClusterEntry> WeightedClusterEntrySharedPtr; |
There was a problem hiding this comment.
I think this can be a unique_ptr instead of shared_ptr. I don't think these are ever shared.
Signed-off-by: Venil Noronha <veniln@vmware.com>
|
@ggreenway @rshriram thanks for reviewing! |
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