From c06cedfa833f449b30713901ccdbbe5f9ca45458 Mon Sep 17 00:00:00 2001 From: saadiaelf Date: Mon, 27 Jan 2025 10:50:58 -0800 Subject: [PATCH 1/4] add high priority test --- .../clusters/aggregate/cluster_test.cc | 76 +++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/test/extensions/clusters/aggregate/cluster_test.cc b/test/extensions/clusters/aggregate/cluster_test.cc index b9aabb3908868..c18628697f1ef 100644 --- a/test/extensions/clusters/aggregate/cluster_test.cc +++ b/test/extensions/clusters/aggregate/cluster_test.cc @@ -284,6 +284,82 @@ TEST_F(AggregateClusterTest, CircuitBreakerMaxConnectionsTest) { 0U); } +TEST_F(AggregateClusterTest, CircuitBreakerMaxConnectionsHighPriorityTest) { + const std::string yaml_config = R"EOF( + name: aggregate_cluster + connect_timeout: 0.25s + lb_policy: CLUSTER_PROVIDED + circuit_breakers: + thresholds: + - priority: DEFAULT + max_connections: 1 + track_remaining: true + - priority: HIGH + max_connections: 2 + track_remaining: true + cluster_type: + name: envoy.clusters.aggregate + typed_config: + "@type": type.googleapis.com/envoy.extensions.clusters.aggregate.v3.ClusterConfig + clusters: + - primary + - secondary +)EOF"; + + initialize(yaml_config); + + // resource manager for the DEFAULT priority (see the yaml config above) + Upstream::ResourceManager& resource_manager_default = + cluster_->info()->resourceManager(Upstream::ResourcePriority::Default); + + // resource manager for the HIGH priority (see the yaml config above) + Upstream::ResourceManager& resource_manager_high = + cluster_->info()->resourceManager(Upstream::ResourcePriority::High); + + Stats::Gauge& cx_open_default = getCircuitBreakersStatByPriority("default", "cx_open"); + Stats::Gauge& remaining_cx_default = getCircuitBreakersStatByPriority("default", "remaining_cx"); + Stats::Gauge& cx_open_high = getCircuitBreakersStatByPriority("high", "cx_open"); + Stats::Gauge& remaining_cx_high = getCircuitBreakersStatByPriority("high", "remaining_cx"); + + // check initial state for priority DEFAULT + EXPECT_EQ(1U, resource_manager_default.connections().max()); + assertResourceManagerStat(resource_manager_default.connections(), remaining_cx_default, + cx_open_default, true, 0U, 1U, 0U); + + // check initial state for priority HIGH + EXPECT_EQ(2U, resource_manager_high.connections().max()); + assertResourceManagerStat(resource_manager_high.connections(), remaining_cx_high, cx_open_high, + true, 0U, 2U, 0U); + + // test DEFAULT priority + resource_manager_default.connections().inc(); + assertResourceManagerStat(resource_manager_default.connections(), remaining_cx_default, + cx_open_default, false, 1U, 0U, 1U); + + // test HIGH priority (1st connection) + resource_manager_high.connections().inc(); + assertResourceManagerStat(resource_manager_high.connections(), remaining_cx_high, cx_open_high, + true, 1U, 1U, 0U); + + // test HIGH priority (2nd connection) + resource_manager_high.connections().inc(); + assertResourceManagerStat(resource_manager_high.connections(), remaining_cx_high, cx_open_high, + false, 2U, 0U, 1U); + + // remove connection and check state + resource_manager_default.connections().dec(); + assertResourceManagerStat(resource_manager_default.connections(), remaining_cx_default, + cx_open_default, true, 0U, 1U, 0U); + + resource_manager_high.connections().dec(); + assertResourceManagerStat(resource_manager_high.connections(), remaining_cx_high, cx_open_high, + true, 1U, 1U, 0U); + + resource_manager_high.connections().dec(); + assertResourceManagerStat(resource_manager_high.connections(), remaining_cx_high, cx_open_high, + true, 0U, 2U, 0U); +} + TEST_F(AggregateClusterTest, CircuitBreakerMaxPendingRequestsTest) { const std::string yaml_config = R"EOF( name: aggregate_cluster From 487e8b4cd3ec6d166cdeb0fe6ec9ba1516f32cc5 Mon Sep 17 00:00:00 2001 From: saadiaelf Date: Tue, 28 Jan 2025 03:44:41 -0800 Subject: [PATCH 2/4] refactor tests Signed-off-by: saadiaelf --- .../clusters/aggregate/cluster_test.cc | 38 ++++++++++++++++--- 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/test/extensions/clusters/aggregate/cluster_test.cc b/test/extensions/clusters/aggregate/cluster_test.cc index c18628697f1ef..98c154d524175 100644 --- a/test/extensions/clusters/aggregate/cluster_test.cc +++ b/test/extensions/clusters/aggregate/cluster_test.cc @@ -331,33 +331,59 @@ TEST_F(AggregateClusterTest, CircuitBreakerMaxConnectionsHighPriorityTest) { assertResourceManagerStat(resource_manager_high.connections(), remaining_cx_high, cx_open_high, true, 0U, 2U, 0U); - // test DEFAULT priority + // increment connection for priority DEFAULT resource_manager_default.connections().inc(); + // check the state of DEFAULT Circuit breaker assertResourceManagerStat(resource_manager_default.connections(), remaining_cx_default, cx_open_default, false, 1U, 0U, 1U); + // check the state of HIGH Circuit breaker + assertResourceManagerStat(resource_manager_high.connections(), remaining_cx_high, cx_open_high, + true, 0U, 2U, 0U); + + // remove connection and check state for priority DEFAULT + resource_manager_default.connections().dec(); + // check the state of DEFAULT Circuit breaker + assertResourceManagerStat(resource_manager_default.connections(), remaining_cx_default, + cx_open_default, true, 0U, 1U, 0U); + // check the state of HIGH Circuit breaker + assertResourceManagerStat(resource_manager_high.connections(), remaining_cx_high, cx_open_high, + true, 0U, 2U, 0U); - // test HIGH priority (1st connection) + // increment connection for priority HIGH (1nd connection) resource_manager_high.connections().inc(); + // check the state of HIGH Circuit breaker assertResourceManagerStat(resource_manager_high.connections(), remaining_cx_high, cx_open_high, true, 1U, 1U, 0U); + // check the state of DEFAULT Circuit breaker + assertResourceManagerStat(resource_manager_default.connections(), remaining_cx_default, + cx_open_default, true, 0U, 1U, 0U); - // test HIGH priority (2nd connection) + // increment connection for priority HIGH (2nd connection) resource_manager_high.connections().inc(); + // check the state of HIGH Circuit breaker assertResourceManagerStat(resource_manager_high.connections(), remaining_cx_high, cx_open_high, false, 2U, 0U, 1U); - - // remove connection and check state - resource_manager_default.connections().dec(); + // check the state of DEFAULT Circuit breaker assertResourceManagerStat(resource_manager_default.connections(), remaining_cx_default, cx_open_default, true, 0U, 1U, 0U); + // remove connection and check state for priority HIGH resource_manager_high.connections().dec(); + // check the state of HIGH Circuit breaker assertResourceManagerStat(resource_manager_high.connections(), remaining_cx_high, cx_open_high, true, 1U, 1U, 0U); + // check the state of DEFAULT Circuit breaker + assertResourceManagerStat(resource_manager_default.connections(), remaining_cx_default, + cx_open_default, true, 0U, 1U, 0U); + // remove connection and check state for priority HIGH resource_manager_high.connections().dec(); + // check the state of HIGH Circuit breaker assertResourceManagerStat(resource_manager_high.connections(), remaining_cx_high, cx_open_high, true, 0U, 2U, 0U); + // check the state of DEFAULT Circuit breaker + assertResourceManagerStat(resource_manager_default.connections(), remaining_cx_default, + cx_open_default, true, 0U, 1U, 0U); } TEST_F(AggregateClusterTest, CircuitBreakerMaxPendingRequestsTest) { From 690085bfb402d551877f0b021f3ecf7e08c0788d Mon Sep 17 00:00:00 2001 From: saadiaelf Date: Tue, 28 Jan 2025 03:54:15 -0800 Subject: [PATCH 3/4] formaatting Signed-off-by: saadiaelf --- test/extensions/clusters/aggregate/cluster_test.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/extensions/clusters/aggregate/cluster_test.cc b/test/extensions/clusters/aggregate/cluster_test.cc index 98c154d524175..66878638c9236 100644 --- a/test/extensions/clusters/aggregate/cluster_test.cc +++ b/test/extensions/clusters/aggregate/cluster_test.cc @@ -369,7 +369,7 @@ TEST_F(AggregateClusterTest, CircuitBreakerMaxConnectionsHighPriorityTest) { // remove connection and check state for priority HIGH resource_manager_high.connections().dec(); - // check the state of HIGH Circuit breaker + // check the state of HIGH Circuit breaker assertResourceManagerStat(resource_manager_high.connections(), remaining_cx_high, cx_open_high, true, 1U, 1U, 0U); // check the state of DEFAULT Circuit breaker @@ -378,7 +378,7 @@ TEST_F(AggregateClusterTest, CircuitBreakerMaxConnectionsHighPriorityTest) { // remove connection and check state for priority HIGH resource_manager_high.connections().dec(); - // check the state of HIGH Circuit breaker + // check the state of HIGH Circuit breaker assertResourceManagerStat(resource_manager_high.connections(), remaining_cx_high, cx_open_high, true, 0U, 2U, 0U); // check the state of DEFAULT Circuit breaker From 4d0d75d1ee622a603d10aca19d228251960a87cd Mon Sep 17 00:00:00 2001 From: Baz Murphy Date: Tue, 28 Jan 2025 05:32:34 -0800 Subject: [PATCH 4/4] adjustment Signed-off-by: Baz Murphy --- .../clusters/aggregate/cluster_test.cc | 65 +++++++------------ 1 file changed, 22 insertions(+), 43 deletions(-) diff --git a/test/extensions/clusters/aggregate/cluster_test.cc b/test/extensions/clusters/aggregate/cluster_test.cc index 66878638c9236..3740bae0c0ed2 100644 --- a/test/extensions/clusters/aggregate/cluster_test.cc +++ b/test/extensions/clusters/aggregate/cluster_test.cc @@ -284,7 +284,7 @@ TEST_F(AggregateClusterTest, CircuitBreakerMaxConnectionsTest) { 0U); } -TEST_F(AggregateClusterTest, CircuitBreakerMaxConnectionsHighPriorityTest) { +TEST_F(AggregateClusterTest, CircuitBreakerMaxConnectionsPriorityTest) { const std::string yaml_config = R"EOF( name: aggregate_cluster connect_timeout: 0.25s @@ -295,7 +295,7 @@ TEST_F(AggregateClusterTest, CircuitBreakerMaxConnectionsHighPriorityTest) { max_connections: 1 track_remaining: true - priority: HIGH - max_connections: 2 + max_connections: 1 track_remaining: true cluster_type: name: envoy.clusters.aggregate @@ -308,11 +308,8 @@ TEST_F(AggregateClusterTest, CircuitBreakerMaxConnectionsHighPriorityTest) { initialize(yaml_config); - // resource manager for the DEFAULT priority (see the yaml config above) Upstream::ResourceManager& resource_manager_default = cluster_->info()->resourceManager(Upstream::ResourcePriority::Default); - - // resource manager for the HIGH priority (see the yaml config above) Upstream::ResourceManager& resource_manager_high = cluster_->info()->resourceManager(Upstream::ResourcePriority::High); @@ -321,67 +318,49 @@ TEST_F(AggregateClusterTest, CircuitBreakerMaxConnectionsHighPriorityTest) { Stats::Gauge& cx_open_high = getCircuitBreakersStatByPriority("high", "cx_open"); Stats::Gauge& remaining_cx_high = getCircuitBreakersStatByPriority("high", "remaining_cx"); - // check initial state for priority DEFAULT + // check the initial max_connections for DEFAULT priority matches the config EXPECT_EQ(1U, resource_manager_default.connections().max()); assertResourceManagerStat(resource_manager_default.connections(), remaining_cx_default, cx_open_default, true, 0U, 1U, 0U); - // check initial state for priority HIGH - EXPECT_EQ(2U, resource_manager_high.connections().max()); + // check the initial max_connections for HIGH priority matches the config + EXPECT_EQ(1U, resource_manager_high.connections().max()); assertResourceManagerStat(resource_manager_high.connections(), remaining_cx_high, cx_open_high, - true, 0U, 2U, 0U); + true, 0U, 1U, 0U); - // increment connection for priority DEFAULT + // add a connection to DEFAULT priority resource_manager_default.connections().inc(); - // check the state of DEFAULT Circuit breaker + // check the state of DEFAULT priority circuit breaker state and statistics assertResourceManagerStat(resource_manager_default.connections(), remaining_cx_default, cx_open_default, false, 1U, 0U, 1U); - // check the state of HIGH Circuit breaker + // check the HIGH priority circuit breaker state and statistics assertResourceManagerStat(resource_manager_high.connections(), remaining_cx_high, cx_open_high, - true, 0U, 2U, 0U); + true, 0U, 1U, 0U); - // remove connection and check state for priority DEFAULT + // remove the connection from DEFAULT priority resource_manager_default.connections().dec(); - // check the state of DEFAULT Circuit breaker + // check the DEFAULT priority circuit breaker state and statistics assertResourceManagerStat(resource_manager_default.connections(), remaining_cx_default, cx_open_default, true, 0U, 1U, 0U); - // check the state of HIGH Circuit breaker + // check the HIGH priority circuit breaker state and statistics assertResourceManagerStat(resource_manager_high.connections(), remaining_cx_high, cx_open_high, - true, 0U, 2U, 0U); - - // increment connection for priority HIGH (1nd connection) - resource_manager_high.connections().inc(); - // check the state of HIGH Circuit breaker - assertResourceManagerStat(resource_manager_high.connections(), remaining_cx_high, cx_open_high, - true, 1U, 1U, 0U); - // check the state of DEFAULT Circuit breaker - assertResourceManagerStat(resource_manager_default.connections(), remaining_cx_default, - cx_open_default, true, 0U, 1U, 0U); + true, 0U, 1U, 0U); - // increment connection for priority HIGH (2nd connection) + // add a connection to HIGH priority resource_manager_high.connections().inc(); - // check the state of HIGH Circuit breaker + // check the HIGH priority circuit breaker state and statistics assertResourceManagerStat(resource_manager_high.connections(), remaining_cx_high, cx_open_high, - false, 2U, 0U, 1U); - // check the state of DEFAULT Circuit breaker - assertResourceManagerStat(resource_manager_default.connections(), remaining_cx_default, - cx_open_default, true, 0U, 1U, 0U); - - // remove connection and check state for priority HIGH - resource_manager_high.connections().dec(); - // check the state of HIGH Circuit breaker - assertResourceManagerStat(resource_manager_high.connections(), remaining_cx_high, cx_open_high, - true, 1U, 1U, 0U); - // check the state of DEFAULT Circuit breaker + false, 1U, 0U, 1U); + // check the DEFAULT priority circuit breaker state and statistics assertResourceManagerStat(resource_manager_default.connections(), remaining_cx_default, cx_open_default, true, 0U, 1U, 0U); - // remove connection and check state for priority HIGH + // remove the connection from HIGH priority resource_manager_high.connections().dec(); - // check the state of HIGH Circuit breaker + // check the HIGH priority circuit breaker state and statistics assertResourceManagerStat(resource_manager_high.connections(), remaining_cx_high, cx_open_high, - true, 0U, 2U, 0U); - // check the state of DEFAULT Circuit breaker + true, 0U, 1U, 0U); + // check the DEFAULT priority circuit breaker and statistics assertResourceManagerStat(resource_manager_default.connections(), remaining_cx_default, cx_open_default, true, 0U, 1U, 0U); }