Skip to content

Commit db3272c

Browse files
committed
dynamic_modules: support RING_HASH and MAGLEV cluster load balancing
Signed-off-by: Basundhara Chakrabarty <basundhara17061996@gmail.com>
1 parent c2671fe commit db3272c

4 files changed

Lines changed: 27 additions & 23 deletions

File tree

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Dynamic module clusters (``envoy.clusters.dynamic_modules``) can now use
22
Envoy's built-in load balancers. In addition to ``CLUSTER_PROVIDED``,
3-
``lb_policy`` may be set to ``LEAST_REQUEST``, ``ROUND_ROBIN``, or ``RANDOM``;
4-
the module then supplies only host discovery and Envoy performs host selection.
5-
Thread-aware policies (ring hash, maglev) are not supported.
3+
``lb_policy`` may be set to ``LEAST_REQUEST``, ``ROUND_ROBIN``, ``RANDOM``,
4+
``RING_HASH``, or ``MAGLEV``; the module then supplies only host discovery and
5+
Envoy performs host selection.

source/extensions/clusters/dynamic_modules/cluster.cc

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -878,22 +878,22 @@ DynamicModuleClusterFactory::createClusterWithConfig(
878878
const envoy::extensions::clusters::dynamic_modules::v3::ClusterConfig& proto_config,
879879
Upstream::ClusterFactoryContext& context) {
880880

881-
// Validate that the LB policy is one supported by dynamic_modules clusters.
882-
// CLUSTER_PROVIDED (module LB) is always supported.
883-
// LEAST_REQUEST, ROUND_ROBIN, RANDOM (native factory LB) are supported.
884-
// Thread-aware policies (ring hash, maglev) are not supported.
881+
// CLUSTER_PROVIDED uses the module's load balancer; the native policies use Envoy's factory
882+
// load balancer, with the module supplying only host discovery.
885883
const auto policy = cluster.lb_policy();
886884
const bool is_module_lb = (policy == envoy::config::cluster::v3::Cluster::CLUSTER_PROVIDED);
887885
const bool is_native_lb = (policy == envoy::config::cluster::v3::Cluster::LEAST_REQUEST ||
888886
policy == envoy::config::cluster::v3::Cluster::ROUND_ROBIN ||
889-
policy == envoy::config::cluster::v3::Cluster::RANDOM);
887+
policy == envoy::config::cluster::v3::Cluster::RANDOM ||
888+
policy == envoy::config::cluster::v3::Cluster::RING_HASH ||
889+
policy == envoy::config::cluster::v3::Cluster::MAGLEV);
890890

891891
if (!is_module_lb && !is_native_lb) {
892-
return absl::InvalidArgumentError(
893-
fmt::format("cluster: LB policy {} is not valid for cluster type "
894-
"'envoy.clusters.dynamic_modules'. Supported policies are "
895-
"CLUSTER_PROVIDED, LEAST_REQUEST, ROUND_ROBIN, and RANDOM.",
896-
envoy::config::cluster::v3::Cluster::LbPolicy_Name(policy)));
892+
return absl::InvalidArgumentError(fmt::format(
893+
"cluster: LB policy {} is not valid for cluster type "
894+
"'envoy.clusters.dynamic_modules'. Supported policies are CLUSTER_PROVIDED, "
895+
"LEAST_REQUEST, ROUND_ROBIN, RANDOM, RING_HASH, and MAGLEV.",
896+
envoy::config::cluster::v3::Cluster::LbPolicy_Name(policy)));
897897
}
898898

899899
Server::Configuration::ServerFactoryContext& server_context = context.serverFactoryContext();

test/extensions/clusters/dynamic_modules/BUILD

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ envoy_cc_test(
2828
"//source/extensions/dynamic_modules:abi_impl",
2929
"//source/extensions/load_balancing_policies/cluster_provided:config",
3030
"//source/extensions/load_balancing_policies/least_request:config",
31+
"//source/extensions/load_balancing_policies/maglev:config",
3132
"//source/extensions/load_balancing_policies/random:config",
33+
"//source/extensions/load_balancing_policies/ring_hash:config",
3234
"//source/extensions/load_balancing_policies/round_robin:config",
3335
"//source/extensions/transport_sockets/raw_buffer:config",
3436
"//test/common/upstream:utility_lib",

test/extensions/clusters/dynamic_modules/cluster_test.cc

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,8 @@ lb_policy: RANDOM
289289
EXPECT_EQ(nullptr, result->second);
290290
}
291291

292-
// Test that thread-aware lb_policy like RING_HASH is rejected.
293-
TEST_F(DynamicModuleClusterTest, RingHashLbPolicyRejected) {
292+
// Test that RING_HASH lb_policy is accepted and returns nullptr thread-aware LB.
293+
TEST_F(DynamicModuleClusterTest, RingHashLbPolicy) {
294294
const std::string yaml = R"EOF(
295295
name: test_cluster
296296
connect_timeout: 0.25s
@@ -305,13 +305,14 @@ lb_policy: RING_HASH
305305
)EOF";
306306

307307
auto result = createCluster(yaml);
308-
ASSERT_FALSE(result.ok());
309-
EXPECT_THAT(result.status().message(),
310-
testing::HasSubstr("not valid for cluster type 'envoy.clusters.dynamic_modules'"));
308+
ASSERT_TRUE(result.ok()) << result.status().message();
309+
EXPECT_NE(nullptr, result->first);
310+
// Native LB policies should return nullptr thread-aware LB.
311+
EXPECT_EQ(nullptr, result->second);
311312
}
312313

313-
// Test that thread-aware lb_policy like MAGLEV is rejected.
314-
TEST_F(DynamicModuleClusterTest, MaglevLbPolicyRejected) {
314+
// Test that MAGLEV lb_policy is accepted and returns nullptr thread-aware LB.
315+
TEST_F(DynamicModuleClusterTest, MaglevLbPolicy) {
315316
const std::string yaml = R"EOF(
316317
name: test_cluster
317318
connect_timeout: 0.25s
@@ -326,9 +327,10 @@ lb_policy: MAGLEV
326327
)EOF";
327328

328329
auto result = createCluster(yaml);
329-
ASSERT_FALSE(result.ok());
330-
EXPECT_THAT(result.status().message(),
331-
testing::HasSubstr("not valid for cluster type 'envoy.clusters.dynamic_modules'"));
330+
ASSERT_TRUE(result.ok()) << result.status().message();
331+
EXPECT_NE(nullptr, result->first);
332+
// Native LB policies should return nullptr thread-aware LB.
333+
EXPECT_EQ(nullptr, result->second);
332334
}
333335

334336
// Test that a missing module fails gracefully.

0 commit comments

Comments
 (0)