From 9eebbd8aa11eb284641a85bc720c02b172c0ebcf Mon Sep 17 00:00:00 2001 From: Zach Date: Wed, 21 Oct 2020 05:24:36 +0000 Subject: [PATCH 1/6] Scaled up to 10k hosts, however is currently inefficient Signed-off-by: Zach --- test/common/upstream/load_balancer_fuzz.proto | 12 ++--- .../upstream/load_balancer_fuzz_base.cc | 18 +++---- .../random_256_ports | 4 +- .../random_NoHosts | 4 +- .../random_load_balancer_corpus/random_Normal | 6 +-- ...h-ba5efdfd9c412a8507087120783fe6529b1ac0cb | 4 +- .../random_largest-port-value | 4 +- .../random_many_choose_hosts | 4 +- .../random_max_ports | 4 +- .../random_overflowing_ports | 6 +-- ...t-eed4596101efb3e737f736c8d5bcd4f0815a8728 | 4 +- .../random_slow-unit-test | 8 +-- .../random_test_something | 6 +-- ...t-6b0d6b83136a4cf0b9ccd468f11207a792859d43 | 4 +- ...t-9144cfbb40b5101ecc28b205b10e6c36a72aae83 | 4 +- .../random_with-locality | 6 +-- .../random_with-locality-high-number-of-hosts | 49 +++++++++++++++++++ test/fuzz/random.h | 36 +++++++++----- 18 files changed, 121 insertions(+), 62 deletions(-) create mode 100644 test/common/upstream/random_load_balancer_corpus/random_with-locality-high-number-of-hosts diff --git a/test/common/upstream/load_balancer_fuzz.proto b/test/common/upstream/load_balancer_fuzz.proto index c4b1ead2c7d0d..759823f15e382 100644 --- a/test/common/upstream/load_balancer_fuzz.proto +++ b/test/common/upstream/load_balancer_fuzz.proto @@ -15,7 +15,7 @@ message UpdateHealthFlags { uint32 num_degraded_hosts = 3; uint32 num_excluded_hosts = 4; // This is used to determine which hosts get marked as healthy, degraded, and excluded. - bytes random_bytestring = 5 [(validate.rules).bytes = {min_len: 1, max_len: 256}]; + bytes random_bytestring = 5 [(validate.rules).bytes = {min_len: 4, max_len: 40000}]; } message LbAction { @@ -32,13 +32,13 @@ message LbAction { } message SetupPriorityLevel { - uint32 num_hosts_in_priority_level = 1 [(validate.rules).uint32.lte = 500]; - uint32 num_hosts_locality_a = 2 [(validate.rules).uint32.lte = 500]; - uint32 num_hosts_locality_b = 3 [(validate.rules).uint32.lte = 500]; + uint32 num_hosts_in_priority_level = 1 [(validate.rules).uint32.lte = 10000]; + uint32 num_hosts_locality_a = 2 [(validate.rules).uint32.lte = 10000]; + uint32 num_hosts_locality_b = 3 [(validate.rules).uint32.lte = 10000]; // Hard cap at 3 localities for simplicity - uint32 num_hosts_locality_c = 4 [(validate.rules).uint32.lte = 500]; + uint32 num_hosts_locality_c = 4 [(validate.rules).uint32.lte = 10000]; // For choosing which hosts go in which locality - bytes random_bytestring = 5 [(validate.rules).bytes = {min_len: 1, max_len: 256}]; + bytes random_bytestring = 5 [(validate.rules).bytes = {min_len: 4, max_len: 40000}]; } // This message represents what LoadBalancerFuzzBase will interact with, performing setup of host sets and calling into load balancers. diff --git a/test/common/upstream/load_balancer_fuzz_base.cc b/test/common/upstream/load_balancer_fuzz_base.cc index 6741f95f75811..838cbe627a025 100644 --- a/test/common/upstream/load_balancer_fuzz_base.cc +++ b/test/common/upstream/load_balancer_fuzz_base.cc @@ -10,7 +10,7 @@ namespace { // possible within Load Balancing. In it's current state, it is too slow (particularly due to calls // to makeTestHost()) to scale up hosts. Once this is made more efficient, this number will be // increased. -constexpr uint32_t MaxNumHostsPerPriorityLevel = 256; +constexpr uint32_t MaxNumHostsPerPriorityLevel = 10000; } // namespace @@ -32,7 +32,7 @@ void LoadBalancerFuzzBase::initializeASingleHostSet( Fuzz::ProperSubsetSelector subset_selector(setup_priority_level.random_bytestring()); - const std::vector> localities = subset_selector.constructSubsets( + const std::vector> localities = subset_selector.constructSubsets( {setup_priority_level.num_hosts_locality_a(), setup_priority_level.num_hosts_locality_b(), setup_priority_level.num_hosts_locality_c()}, host_set.hosts_.size()); @@ -44,7 +44,7 @@ void LoadBalancerFuzzBase::initializeASingleHostSet( std::array locality_indexes = {locality_a, locality_b, locality_c}; for (uint8_t locality = 0; locality < locality_indexes.size(); locality++) { - for (uint8_t index : localities[locality]) { + for (uint32_t index : localities[locality]) { locality_indexes[locality].push_back(host_set.hosts_[index]); locality_indexes_[index] = locality; } @@ -101,11 +101,11 @@ void LoadBalancerFuzzBase::updateHealthFlagsForAHostSet(const uint64_t host_prio Fuzz::ProperSubsetSelector subset_selector(random_bytestring); - const std::vector> subsets = subset_selector.constructSubsets( + const std::vector> subsets = subset_selector.constructSubsets( {num_healthy_hosts, num_degraded_hosts, num_excluded_hosts}, host_set_size); // Healthy hosts are first subset - for (uint8_t index : subsets.at(HealthStatus::HEALTHY)) { + for (uint32_t index : subsets.at(HealthStatus::HEALTHY)) { host_set.healthy_hosts_.push_back(host_set.hosts_[index]); // No health flags for healthy } @@ -113,7 +113,7 @@ void LoadBalancerFuzzBase::updateHealthFlagsForAHostSet(const uint64_t host_prio absl::StrJoin(subsets.at(HealthStatus::HEALTHY), " ")); // Degraded hosts are second subset - for (uint8_t index : subsets.at(HealthStatus::DEGRADED)) { + for (uint32_t index : subsets.at(HealthStatus::DEGRADED)) { host_set.degraded_hosts_.push_back(host_set.hosts_[index]); // Health flags are not currently directly used by most load balancers, but // they may be added and also are used by other components. @@ -125,7 +125,7 @@ void LoadBalancerFuzzBase::updateHealthFlagsForAHostSet(const uint64_t host_prio absl::StrJoin(subsets.at(HealthStatus::DEGRADED), " ")); // Excluded hosts are third subset - for (uint8_t index : subsets.at(HealthStatus::EXCLUDED)) { + for (uint32_t index : subsets.at(HealthStatus::EXCLUDED)) { host_set.excluded_hosts_.push_back(host_set.hosts_[index]); // Health flags are not currently directly used by most load balancers, but // they may be added and also are used by other components. @@ -156,8 +156,8 @@ void LoadBalancerFuzzBase::updateHealthFlagsForAHostSet(const uint64_t host_prio // Iterate through subsets for (uint8_t health_status = 0; health_status < locality_health_statuses.size(); health_status++) { - for (uint8_t index : subsets.at(health_status)) { // Each subset logically represents a health - // status + for (uint32_t index : subsets.at(health_status)) { // Each subset logically represents a health + // status // If the host is in a locality, we have to update the corresponding health status host vector if (!(locality_indexes_.find(index) == locality_indexes_.end())) { // After computing the host index subsets, we want to propagate these changes to a host set diff --git a/test/common/upstream/random_load_balancer_corpus/random_256_ports b/test/common/upstream/random_load_balancer_corpus/random_256_ports index 1924462a2ee76..b66a4e3c60cd7 100644 --- a/test/common/upstream/random_load_balancer_corpus/random_256_ports +++ b/test/common/upstream/random_load_balancer_corpus/random_256_ports @@ -31,11 +31,11 @@ actions { } setup_priority_levels { num_hosts_in_priority_level: 256 - random_bytestring: "\x01\x02" + random_bytestring: "\x01\x02\x01\x02" } setup_priority_levels { num_hosts_in_priority_level: 256 - random_bytestring: "\x01\x02" + random_bytestring: "\x01\x02\x01\x02" } seed_for_prng: 4 } diff --git a/test/common/upstream/random_load_balancer_corpus/random_NoHosts b/test/common/upstream/random_load_balancer_corpus/random_NoHosts index 551225e908e3a..bbd0eb803656f 100644 --- a/test/common/upstream/random_load_balancer_corpus/random_NoHosts +++ b/test/common/upstream/random_load_balancer_corpus/random_NoHosts @@ -14,11 +14,11 @@ actions { } setup_priority_levels { num_hosts_in_priority_level: 0 - random_bytestring: "\x01\x02" + random_bytestring: "\x01\x02\x01\x02" } setup_priority_levels { num_hosts_in_priority_level: 0 - random_bytestring: "\x01\x02" + random_bytestring: "\x01\x02\x01\x02" } seed_for_prng: 2 } diff --git a/test/common/upstream/random_load_balancer_corpus/random_Normal b/test/common/upstream/random_load_balancer_corpus/random_Normal index 61bb66f8638cd..0d0d605bad386 100644 --- a/test/common/upstream/random_load_balancer_corpus/random_Normal +++ b/test/common/upstream/random_load_balancer_corpus/random_Normal @@ -6,7 +6,7 @@ actions { update_health_flags { host_priority: 0 num_healthy_hosts: 2 - random_bytestring: "\x01\x02" + random_bytestring: "\x01\x02\x01\x02" } } actions { @@ -31,11 +31,11 @@ actions { } setup_priority_levels { num_hosts_in_priority_level: 2 - random_bytestring: "\x01\x02" + random_bytestring: "\x01\x02\x01\x02" } setup_priority_levels { num_hosts_in_priority_level: 0 - random_bytestring: "\x01\x02" + random_bytestring: "\x01\x02\x01\x02" } seed_for_prng: 1 } diff --git a/test/common/upstream/random_load_balancer_corpus/random_crash-ba5efdfd9c412a8507087120783fe6529b1ac0cb b/test/common/upstream/random_load_balancer_corpus/random_crash-ba5efdfd9c412a8507087120783fe6529b1ac0cb index 602a393132bfc..fbd29c7b9425f 100644 --- a/test/common/upstream/random_load_balancer_corpus/random_crash-ba5efdfd9c412a8507087120783fe6529b1ac0cb +++ b/test/common/upstream/random_load_balancer_corpus/random_crash-ba5efdfd9c412a8507087120783fe6529b1ac0cb @@ -28,11 +28,11 @@ actions { } setup_priority_levels { num_hosts_in_priority_level: 2 - random_bytestring: "\x01\x02" + random_bytestring: "\x01\x02\x01\x02" } setup_priority_levels { num_hosts_in_priority_level: 9007199259945536 - random_bytestring: "\x01\x02" + random_bytestring: "\x01\x02\x01\x02" } seed_for_prng: 6 } diff --git a/test/common/upstream/random_load_balancer_corpus/random_largest-port-value b/test/common/upstream/random_load_balancer_corpus/random_largest-port-value index 2f95ce787ef1b..7801b65715b18 100644 --- a/test/common/upstream/random_load_balancer_corpus/random_largest-port-value +++ b/test/common/upstream/random_load_balancer_corpus/random_largest-port-value @@ -24,11 +24,11 @@ actions { } nsetup_priority_levels { num_hosts_in_priority_level: 65455 - random_bytestring: "\x01\x02" + random_bytestring: "\x01\x02\x01\x02" } setup_priority_levels { num_hosts_in_priority_level: 65455 - random_bytestring: "\x01\x02" + random_bytestring: "\x01\x02\x01\x02" } seed_for_prng: 5 } diff --git a/test/common/upstream/random_load_balancer_corpus/random_many_choose_hosts b/test/common/upstream/random_load_balancer_corpus/random_many_choose_hosts index b263d07ec40e6..562f60b80a10e 100644 --- a/test/common/upstream/random_load_balancer_corpus/random_many_choose_hosts +++ b/test/common/upstream/random_load_balancer_corpus/random_many_choose_hosts @@ -51,11 +51,11 @@ actions { } setup_priority_levels { num_hosts_in_priority_level: 2 - random_bytestring: "\x01\x02" + random_bytestring: "\x01\x02\x01\x02" } setup_priority_levels { num_hosts_in_priority_level: 0 - random_bytestring: "\x01\x02" + random_bytestring: "\x01\x02\x01\x02" } seed_for_prng: 1 } diff --git a/test/common/upstream/random_load_balancer_corpus/random_max_ports b/test/common/upstream/random_load_balancer_corpus/random_max_ports index 4a7406d8b765c..b309c42775850 100644 --- a/test/common/upstream/random_load_balancer_corpus/random_max_ports +++ b/test/common/upstream/random_load_balancer_corpus/random_max_ports @@ -31,11 +31,11 @@ actions { } setup_priority_levels { num_hosts_in_priority_level: 32726 - random_bytestring: "\x01\x02" + random_bytestring: "\x01\x02\x01\x02" } setup_priority_levels { num_hosts_in_priority_level: 32726 - random_bytestring: "\x01\x02" + random_bytestring: "\x01\x02\x01\x02" } seed_for_prng: 88 } diff --git a/test/common/upstream/random_load_balancer_corpus/random_overflowing_ports b/test/common/upstream/random_load_balancer_corpus/random_overflowing_ports index 4598c29dbe10e..4c1e2309fa48e 100644 --- a/test/common/upstream/random_load_balancer_corpus/random_overflowing_ports +++ b/test/common/upstream/random_load_balancer_corpus/random_overflowing_ports @@ -6,7 +6,7 @@ actions { update_health_flags { host_priority: 0 num_healthy_hosts: 2 - random_bytestring: "\x01\x02" + random_bytestring: "laierghilaerghfliakreg" } } actions { @@ -31,11 +31,11 @@ actions { } setup_priority_levels { num_hosts_in_priority_level: 60000 - random_bytestring: "\x01\x02" + random_bytestring: "aergaergaegrfkijhilaegr" } setup_priority_levels { num_hosts_in_priority_level: 60000 - random_bytestring: "\x01\x02" + random_bytestring: "3q4tgsrht674eu43" } seed_for_prng: 4 } diff --git a/test/common/upstream/random_load_balancer_corpus/random_slow-unit-eed4596101efb3e737f736c8d5bcd4f0815a8728 b/test/common/upstream/random_load_balancer_corpus/random_slow-unit-eed4596101efb3e737f736c8d5bcd4f0815a8728 index 7bebf1a2cf962..906d7ec670cbe 100644 --- a/test/common/upstream/random_load_balancer_corpus/random_slow-unit-eed4596101efb3e737f736c8d5bcd4f0815a8728 +++ b/test/common/upstream/random_load_balancer_corpus/random_slow-unit-eed4596101efb3e737f736c8d5bcd4f0815a8728 @@ -30,11 +30,11 @@ load_balancer_test_case { } setup_priority_levels { num_hosts_in_priority_level: 536903638 - random_bytestring: "\001\002" + random_bytestring: "\001\002\003\004" } setup_priority_levels { num_hosts_in_priority_level: 32726 - random_bytestring: "\001\002" + random_bytestring: "\001\002\003\004" } seed_for_prng: 88 } diff --git a/test/common/upstream/random_load_balancer_corpus/random_slow-unit-test b/test/common/upstream/random_load_balancer_corpus/random_slow-unit-test index e1f2fcfdd3031..48292e8963583 100644 --- a/test/common/upstream/random_load_balancer_corpus/random_slow-unit-test +++ b/test/common/upstream/random_load_balancer_corpus/random_slow-unit-test @@ -7,7 +7,7 @@ load_balancer_test_case { actions { update_health_flags { num_healthy_hosts: 2 - random_bytestring: "\001\002\003\004" + random_bytestring: "aergswyhtydjkkyugikt" } } actions { @@ -25,7 +25,7 @@ load_balancer_test_case { actions { update_health_flags { num_healthy_hosts: 2 - random_bytestring: "\001\002\003\004" + random_bytestring: "arwefawefeaqgftrsehttyjhui" } } setup_priority_levels { @@ -33,14 +33,14 @@ load_balancer_test_case { num_hosts_locality_one: 50 num_hosts_locality_two: 50 num_hosts_locality_three: 50 - random_bytestring: "\001\002" + random_bytestring: "awertfeyjuhytukgjmu" } setup_priority_levels { num_hosts_in_priority_level: 500 num_hosts_locality_one: 50 num_hosts_locality_two: 50 num_hosts_locality_three: 50 - random_bytestring: "\001\002" + random_bytestring: "awerfuilyetrs" } seed_for_prng: 88 } diff --git a/test/common/upstream/random_load_balancer_corpus/random_test_something b/test/common/upstream/random_load_balancer_corpus/random_test_something index 172e2cb1c0514..e4dbc5a7cd693 100644 --- a/test/common/upstream/random_load_balancer_corpus/random_test_something +++ b/test/common/upstream/random_load_balancer_corpus/random_test_something @@ -6,7 +6,7 @@ actions { update_health_flags { host_priority: 0 num_healthy_hosts: 2 - random_bytestring: "\x01\x02" + random_bytestring: "aegrkiyuttkyumfae" } } actions { @@ -31,11 +31,11 @@ actions { } setup_priority_levels { num_hosts_in_priority_level: 250 - random_bytestring: "\x01\x02" + random_bytestring: "ukjyrkjyrujaegregaeagr" } setup_priority_levels { num_hosts_in_priority_level: 250 - random_bytestring: "\x01\x02" + random_bytestring: "aerhyytjtyukytufagfe" } seed_for_prng: 4 } diff --git a/test/common/upstream/random_load_balancer_corpus/random_timeout-6b0d6b83136a4cf0b9ccd468f11207a792859d43 b/test/common/upstream/random_load_balancer_corpus/random_timeout-6b0d6b83136a4cf0b9ccd468f11207a792859d43 index 96f3d0efd72be..aa119d68145b6 100644 --- a/test/common/upstream/random_load_balancer_corpus/random_timeout-6b0d6b83136a4cf0b9ccd468f11207a792859d43 +++ b/test/common/upstream/random_load_balancer_corpus/random_timeout-6b0d6b83136a4cf0b9ccd468f11207a792859d43 @@ -20,12 +20,12 @@ load_balancer_test_case { actions { update_health_flags { num_excluded_hosts: 268435456 - random_bytestring: "\x01\x02" + random_bytestring: "aergaergyhreaggear" } } setup_priority_levels { num_hosts_in_priority_level: 13534154135 - random_bytestring: "\x01\x02" + random_bytestring: "earghaegraergaergaergaerg" } seed_for_prng: 32 } diff --git a/test/common/upstream/random_load_balancer_corpus/random_timeout-9144cfbb40b5101ecc28b205b10e6c36a72aae83 b/test/common/upstream/random_load_balancer_corpus/random_timeout-9144cfbb40b5101ecc28b205b10e6c36a72aae83 index 2fca35ed475d0..776eccfd8a37d 100644 --- a/test/common/upstream/random_load_balancer_corpus/random_timeout-9144cfbb40b5101ecc28b205b10e6c36a72aae83 +++ b/test/common/upstream/random_load_balancer_corpus/random_timeout-9144cfbb40b5101ecc28b205b10e6c36a72aae83 @@ -14,12 +14,12 @@ load_balancer_test_case { update_health_flags { host_priority: 270582939648 num_degraded_hosts: 4194304 - random_bytestring: "\x01\x02\x03\x04" + random_bytestring: "aergaergaerghaerhgaerghaergaerg" } } setup_priority_levels { num_hosts_in_priority_level: 1024 - random_bytestring: "\x01\x02" + random_bytestring: "yrfukykyrthrtgrgera" } seed_for_prng: 62208 } diff --git a/test/common/upstream/random_load_balancer_corpus/random_with-locality b/test/common/upstream/random_load_balancer_corpus/random_with-locality index 3f2f1281845f0..39023351784a3 100644 --- a/test/common/upstream/random_load_balancer_corpus/random_with-locality +++ b/test/common/upstream/random_load_balancer_corpus/random_with-locality @@ -8,7 +8,7 @@ actions { num_healthy_hosts: 2 num_degraded_hosts: 3 num_excluded_hosts: 4 - random_bytestring: "\x01\x02\x03\x04\x05\x06" + random_bytestring: "eargfaergaergaergaerggaereargaegr" } } actions { @@ -36,14 +36,14 @@ setup_priority_levels { num_hosts_locality_a: 3 num_hosts_locality_b: 4 num_hosts_locality_c: 5 - random_bytestring: "\x01\x02" + random_bytestring: "eragaerghahtgrathaertthgrtahrathggraaergeargaergae" } setup_priority_levels { num_hosts_in_priority_level: 20 num_hosts_locality_a: 3 num_hosts_locality_b: 4 num_hosts_locality_c: 5 - random_bytestring: "\x01\x02" + random_bytestring: "dsfawetfawertfrawawetukyfyguukytfufrrawer" } seed_for_prng: 1 } diff --git a/test/common/upstream/random_load_balancer_corpus/random_with-locality-high-number-of-hosts b/test/common/upstream/random_load_balancer_corpus/random_with-locality-high-number-of-hosts new file mode 100644 index 0000000000000..6af6e39d0d2b5 --- /dev/null +++ b/test/common/upstream/random_load_balancer_corpus/random_with-locality-high-number-of-hosts @@ -0,0 +1,49 @@ +load_balancer_test_case { +common_lb_config { + +} +actions { + update_health_flags { + host_priority: 0 + num_healthy_hosts: 2 + num_degraded_hosts: 3 + num_excluded_hosts: 4 + random_bytestring: "eargfaergaergaergaerggaereargaegr" + } +} +actions { + prefetch { + + } +} +actions { + prefetch { + + } +} +actions { + choose_host { + + } +} +actions { + choose_host { + + } +} +setup_priority_levels { + num_hosts_in_priority_level: 3000 + num_hosts_locality_a: 1000 + num_hosts_locality_b: 500 + num_hosts_locality_c: 1500 + random_bytestring: "eragaerghahtgrathaertthgrtahrathggraaergeargaergae" +} +setup_priority_levels { + num_hosts_in_priority_level: 3000 + num_hosts_locality_a: 300 + num_hosts_locality_b: 1200 + num_hosts_locality_c: 1500 + random_bytestring: "dsfawetfawertfrawawetukyfyguukytfufrrawer" +} +seed_for_prng: 1 +} diff --git a/test/fuzz/random.h b/test/fuzz/random.h index 01b8f5e83df55..f434b33b373f4 100644 --- a/test/fuzz/random.h +++ b/test/fuzz/random.h @@ -33,10 +33,19 @@ class PsuedoRandomGenerator64 : public RandomGenerator { } // namespace Random namespace Fuzz { + class ProperSubsetSelector { public: ProperSubsetSelector(const std::string& random_bytestring) - : random_bytestring_(random_bytestring) {} + : random_bytestring_(random_bytestring) { + // Must be at least 4 bytes wide to serve as randomness for the subset selector + ASSERT(random_bytestring_.length() >= 4); + // Pull off the last few bits to make random_bytestring_ a multiple of 4 - this will make + // iteration through the bytestring a lot easier and cleaner + while (random_bytestring_.length() % 4 != 0) { + random_bytestring_.pop_back(); + } + } /** * This function does proper subset selection on a certain number of elements. It returns a vector @@ -50,16 +59,16 @@ class ProperSubsetSelector { * of elements, the function would return something such as {{5, 3}}. */ - std::vector> + std::vector> constructSubsets(const std::vector& number_of_elements_in_each_subset, uint32_t number_of_elements) { num_elements_left_ = number_of_elements; - std::vector index_vector; + std::vector index_vector; index_vector.reserve(number_of_elements); for (uint32_t i = 0; i < number_of_elements; i++) { index_vector.push_back(i); } - std::vector> subsets; + std::vector> subsets; subsets.reserve(number_of_elements_in_each_subset.size()); for (uint32_t i : number_of_elements_in_each_subset) { subsets.push_back(constructSubset(i, index_vector)); @@ -69,22 +78,22 @@ class ProperSubsetSelector { private: // Builds a single subset by pulling indexes off index_vector_ - std::vector constructSubset(uint32_t number_of_elements_in_subset, - std::vector& index_vector) { - std::vector subset; + std::vector constructSubset(uint32_t number_of_elements_in_subset, + std::vector& index_vector) { + std::vector subset; for (uint32_t i = 0; i < number_of_elements_in_subset && !(num_elements_left_ == 0); i++) { // Index of bytestring will wrap around if it "overflows" past the random bytestring's length. - uint64_t index_of_index_vector = - random_bytestring_[index_of_random_bytestring_ % random_bytestring_.length()] % - num_elements_left_; - const uint64_t index = index_vector.at(index_of_index_vector); + uint32_t* bytes_from_bytestring = reinterpret_cast( + &random_bytestring_ + (index_of_random_bytestring_ % random_bytestring_.length())); + uint32_t index_of_index_vector = *bytes_from_bytestring % num_elements_left_; + uint32_t index = index_vector.at(index_of_index_vector); subset.push_back(index); // Move the index chosen to the end of the vector - will not be chosen again std::swap(index_vector[index_of_index_vector], index_vector[num_elements_left_ - 1]); --num_elements_left_; - ++index_of_random_bytestring_; + index_of_random_bytestring_ += 4; } return subset; @@ -92,7 +101,8 @@ class ProperSubsetSelector { // This bytestring will be iterated through representing randomness in order to choose // subsets - const std::string random_bytestring_; + std::string random_bytestring_; + // This will iterate by 4 every time bytestring is iterated uint32_t index_of_random_bytestring_ = 0; // Used to make subset construction linear time complexity with std::swap - chosen indexes will be From 0726569f766e5696716334057b471267f40fd2cc Mon Sep 17 00:00:00 2001 From: Zach Date: Thu, 22 Oct 2020 16:10:47 +0000 Subject: [PATCH 2/6] Temp for debugging Signed-off-by: Zach --- .../upstream/load_balancer_fuzz_base.cc | 34 ++++++++++++++++++- .../common/upstream/load_balancer_fuzz_base.h | 9 ++++- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/test/common/upstream/load_balancer_fuzz_base.cc b/test/common/upstream/load_balancer_fuzz_base.cc index 838cbe627a025..e0fd4e7c1e198 100644 --- a/test/common/upstream/load_balancer_fuzz_base.cc +++ b/test/common/upstream/load_balancer_fuzz_base.cc @@ -14,6 +14,23 @@ constexpr uint32_t MaxNumHostsPerPriorityLevel = 10000; } // namespace +/*static const std::shared_ptr& mockClusterInfo() { + CONSTRUCT_ON_FIRST_USE(std::shared_ptr); +}*/ + +HostVector initializeHostsForUseInFuzzing() { + //const std::shared_ptr> info_ = std::make_shared>(mockClusterInfo()); + //std::shared_ptr> info_{new NiceMock()}; + HostVector hosts; + for (uint32_t i = 0; i < 10000; ++i) { + hosts.push_back(makeTestHost(LoadBalancerFuzzBase::info_, "tcp://127.0.0.1:" + std::to_string(i))); + } + return hosts; +} + +std::shared_ptr LoadBalancerFuzzBase::info_{new NiceMock()}; +HostVector LoadBalancerFuzzBase::initialized_hosts_ = initializeHostsForUseInFuzzing(); + void LoadBalancerFuzzBase::initializeASingleHostSet( const test::common::upstream::SetupPriorityLevel& setup_priority_level, const uint8_t priority_level, uint16_t& port) { @@ -25,7 +42,7 @@ void LoadBalancerFuzzBase::initializeASingleHostSet( // Cap each host set at 256 hosts for efficiency - Leave port clause in for future changes while (hosts_made < std::min(num_hosts_in_priority_level, MaxNumHostsPerPriorityLevel) && port < 65535) { - host_set.hosts_.push_back(makeTestHost(info_, "tcp://127.0.0.1:" + std::to_string(port))); + host_set.hosts_.push_back(initialized_hosts_[port - 80]); ++port; ++hosts_made; } @@ -225,5 +242,20 @@ void LoadBalancerFuzzBase::replay( } } +void LoadBalancerFuzzBase::clearStaticHostsHealthFlags() { + // Have to clear the hosts health flags here - how do we know what hosts to clear? + // The only outstanding health flags set are those that are set from hosts being placed in degraded + // and excluded. Thus, use the priority set pointer to know which flags to clear. + for (uint32_t priority_level = 0; priority_level < priority_set_.hostSetsPerPriority().size(); ++priority_level) { + MockHostSet& host_set = *priority_set_.getMockHostSet(priority_level); + for (auto& host : host_set.degraded_hosts_) { + host->healthFlagClear(Host::HealthFlag::DEGRADED_ACTIVE_HC); + } + for (auto& host : host_set.excluded_hosts_) { + host->healthFlagClear(Host::HealthFlag::FAILED_ACTIVE_HC); + } + } +} + } // namespace Upstream } // namespace Envoy diff --git a/test/common/upstream/load_balancer_fuzz_base.h b/test/common/upstream/load_balancer_fuzz_base.h index deeb4c82c2165..1da5b5deacaf3 100644 --- a/test/common/upstream/load_balancer_fuzz_base.h +++ b/test/common/upstream/load_balancer_fuzz_base.h @@ -36,6 +36,8 @@ class LoadBalancerFuzzBase { ~LoadBalancerFuzzBase() = default; void replay(const Protobuf::RepeatedPtrField& actions); + void clearStaticHostsHealthFlags(); + // These public objects shared amongst all types of load balancers will be used to construct load // balancers in specific load balancer fuzz classes Stats::IsolatedStoreImpl stats_store_; @@ -43,7 +45,8 @@ class LoadBalancerFuzzBase { NiceMock runtime_; Random::PsuedoRandomGenerator64 random_; NiceMock priority_set_; - std::shared_ptr info_{new NiceMock()}; + //std::shared_ptr info_{new NiceMock()}; + static std::shared_ptr info_; std::unique_ptr lb_; private: @@ -61,6 +64,10 @@ class LoadBalancerFuzzBase { // localities Key - index of host within full host list, value - locality level host at index is // in absl::node_hash_map locality_indexes_; + + // Will statically initialize 10000? hosts in this vector + // Will have to clear flags at the end of each iteration here + static HostVector initialized_hosts_; }; } // namespace Upstream From 204859678e018a63ebeba54280716c098c1258d8 Mon Sep 17 00:00:00 2001 From: Zach Date: Tue, 27 Oct 2020 02:27:00 +0000 Subject: [PATCH 3/6] Scaled up to 60k hosts Signed-off-by: Zach --- test/common/upstream/load_balancer_fuzz.proto | 12 ++--- .../upstream/load_balancer_fuzz_base.cc | 44 ++++++++--------- .../common/upstream/load_balancer_fuzz_base.h | 6 +-- .../random_256_ports | 4 +- .../random_load_balancer_corpus/random_Normal | 6 +-- ...h-55abbf82c64b5a62e299b93d7b254045471199c9 | 41 ++++++++++++++++ ...h-5a64c214e5c2038299c8f2e85f143f1163077c1b | 25 ++++++++++ .../random_with_locality-50000-hosts | 49 +++++++++++++++++++ test/fuzz/random.h | 11 +++-- test/fuzz/random_test.cc | 14 +++--- 10 files changed, 164 insertions(+), 48 deletions(-) create mode 100644 test/common/upstream/random_load_balancer_corpus/random_crash-55abbf82c64b5a62e299b93d7b254045471199c9 create mode 100644 test/common/upstream/random_load_balancer_corpus/random_crash-5a64c214e5c2038299c8f2e85f143f1163077c1b create mode 100644 test/common/upstream/random_load_balancer_corpus/random_with_locality-50000-hosts diff --git a/test/common/upstream/load_balancer_fuzz.proto b/test/common/upstream/load_balancer_fuzz.proto index 759823f15e382..debde43378080 100644 --- a/test/common/upstream/load_balancer_fuzz.proto +++ b/test/common/upstream/load_balancer_fuzz.proto @@ -8,7 +8,7 @@ import "google/protobuf/empty.proto"; message UpdateHealthFlags { // The host priority determines what host set within the priority set which will get updated. - uint64 host_priority = 1; + uint32 host_priority = 1; // These will determine how many hosts will get placed into health hosts, degraded hosts, and // excluded hosts from the full host list. uint32 num_healthy_hosts = 2; @@ -32,13 +32,13 @@ message LbAction { } message SetupPriorityLevel { - uint32 num_hosts_in_priority_level = 1 [(validate.rules).uint32.lte = 10000]; - uint32 num_hosts_locality_a = 2 [(validate.rules).uint32.lte = 10000]; - uint32 num_hosts_locality_b = 3 [(validate.rules).uint32.lte = 10000]; + uint32 num_hosts_in_priority_level = 1 [(validate.rules).uint32.lte = 60000]; + uint32 num_hosts_locality_a = 2 [(validate.rules).uint32.lte = 60000]; + uint32 num_hosts_locality_b = 3 [(validate.rules).uint32.lte = 60000]; // Hard cap at 3 localities for simplicity - uint32 num_hosts_locality_c = 4 [(validate.rules).uint32.lte = 10000]; + uint32 num_hosts_locality_c = 4 [(validate.rules).uint32.lte = 60000]; // For choosing which hosts go in which locality - bytes random_bytestring = 5 [(validate.rules).bytes = {min_len: 4, max_len: 40000}]; + bytes random_bytestring = 5 [(validate.rules).bytes = {min_len: 4, max_len: 50000}]; } // This message represents what LoadBalancerFuzzBase will interact with, performing setup of host sets and calling into load balancers. diff --git a/test/common/upstream/load_balancer_fuzz_base.cc b/test/common/upstream/load_balancer_fuzz_base.cc index e0fd4e7c1e198..c6d37857027d1 100644 --- a/test/common/upstream/load_balancer_fuzz_base.cc +++ b/test/common/upstream/load_balancer_fuzz_base.cc @@ -6,31 +6,20 @@ namespace Envoy { namespace Upstream { namespace { -// TODO(zasweq): This will be relaxed in the future in order to fully represent the state space -// possible within Load Balancing. In it's current state, it is too slow (particularly due to calls -// to makeTestHost()) to scale up hosts. Once this is made more efficient, this number will be -// increased. -constexpr uint32_t MaxNumHostsPerPriorityLevel = 10000; -} // namespace +constexpr uint32_t MaxNumHostsPerPriorityLevel = 60000; -/*static const std::shared_ptr& mockClusterInfo() { - CONSTRUCT_ON_FIRST_USE(std::shared_ptr); -}*/ +} // namespace -HostVector initializeHostsForUseInFuzzing() { - //const std::shared_ptr> info_ = std::make_shared>(mockClusterInfo()); - //std::shared_ptr> info_{new NiceMock()}; +HostVector +LoadBalancerFuzzBase::initializeHostsForUseInFuzzing(std::shared_ptr info_) { HostVector hosts; - for (uint32_t i = 0; i < 10000; ++i) { - hosts.push_back(makeTestHost(LoadBalancerFuzzBase::info_, "tcp://127.0.0.1:" + std::to_string(i))); + for (uint32_t i = 1; i <= 60000; ++i) { + hosts.push_back(makeTestHost(info_, "tcp://127.0.0.1:" + std::to_string(i))); } return hosts; } -std::shared_ptr LoadBalancerFuzzBase::info_{new NiceMock()}; -HostVector LoadBalancerFuzzBase::initialized_hosts_ = initializeHostsForUseInFuzzing(); - void LoadBalancerFuzzBase::initializeASingleHostSet( const test::common::upstream::SetupPriorityLevel& setup_priority_level, const uint8_t priority_level, uint16_t& port) { @@ -41,8 +30,8 @@ void LoadBalancerFuzzBase::initializeASingleHostSet( uint32_t hosts_made = 0; // Cap each host set at 256 hosts for efficiency - Leave port clause in for future changes while (hosts_made < std::min(num_hosts_in_priority_level, MaxNumHostsPerPriorityLevel) && - port < 65535) { - host_set.hosts_.push_back(initialized_hosts_[port - 80]); + port < 60000) { + host_set.hosts_.push_back(initialized_hosts_[port]); ++port; ++hosts_made; } @@ -75,8 +64,16 @@ void LoadBalancerFuzzBase::initializeASingleHostSet( // Initializes random and fixed host sets void LoadBalancerFuzzBase::initializeLbComponents( const test::common::upstream::LoadBalancerTestCase& input) { + static NiceMock info; + static std::shared_ptr info_pointer{std::shared_ptr{}, &info}; + + // Will statically initialize 60000 hosts in this vector, so each fuzz run doesn't construct new + // hosts to use. This will require clearing of state after each run. + static HostVector initialized_hosts = initializeHostsForUseInFuzzing(info_pointer); + initialized_hosts_ = initialized_hosts; + random_.initializeSeed(input.seed_for_prng()); - uint16_t port = 80; + uint16_t port = 1; for (uint8_t priority_of_host_set = 0; priority_of_host_set < input.setup_priority_levels().size(); ++priority_of_host_set) { initializeASingleHostSet(input.setup_priority_levels().at(priority_of_host_set), @@ -244,9 +241,10 @@ void LoadBalancerFuzzBase::replay( void LoadBalancerFuzzBase::clearStaticHostsHealthFlags() { // Have to clear the hosts health flags here - how do we know what hosts to clear? - // The only outstanding health flags set are those that are set from hosts being placed in degraded - // and excluded. Thus, use the priority set pointer to know which flags to clear. - for (uint32_t priority_level = 0; priority_level < priority_set_.hostSetsPerPriority().size(); ++priority_level) { + // The only outstanding health flags set are those that are set from hosts being placed in + // degraded and excluded. Thus, use the priority set pointer to know which flags to clear. + for (uint32_t priority_level = 0; priority_level < priority_set_.hostSetsPerPriority().size(); + ++priority_level) { MockHostSet& host_set = *priority_set_.getMockHostSet(priority_level); for (auto& host : host_set.degraded_hosts_) { host->healthFlagClear(Host::HealthFlag::DEGRADED_ACTIVE_HC); diff --git a/test/common/upstream/load_balancer_fuzz_base.h b/test/common/upstream/load_balancer_fuzz_base.h index 1da5b5deacaf3..b6938e7046237 100644 --- a/test/common/upstream/load_balancer_fuzz_base.h +++ b/test/common/upstream/load_balancer_fuzz_base.h @@ -45,8 +45,6 @@ class LoadBalancerFuzzBase { NiceMock runtime_; Random::PsuedoRandomGenerator64 random_; NiceMock priority_set_; - //std::shared_ptr info_{new NiceMock()}; - static std::shared_ptr info_; std::unique_ptr lb_; private: @@ -65,9 +63,11 @@ class LoadBalancerFuzzBase { // in absl::node_hash_map locality_indexes_; + static HostVector initializeHostsForUseInFuzzing(std::shared_ptr info_); + // Will statically initialize 10000? hosts in this vector // Will have to clear flags at the end of each iteration here - static HostVector initialized_hosts_; + HostVector initialized_hosts_; }; } // namespace Upstream diff --git a/test/common/upstream/random_load_balancer_corpus/random_256_ports b/test/common/upstream/random_load_balancer_corpus/random_256_ports index b66a4e3c60cd7..306a4f8280fb8 100644 --- a/test/common/upstream/random_load_balancer_corpus/random_256_ports +++ b/test/common/upstream/random_load_balancer_corpus/random_256_ports @@ -31,11 +31,11 @@ actions { } setup_priority_levels { num_hosts_in_priority_level: 256 - random_bytestring: "\x01\x02\x01\x02" + random_bytestring: "\x01\x02\x01\x02\x01\x02\x01\x02" } setup_priority_levels { num_hosts_in_priority_level: 256 - random_bytestring: "\x01\x02\x01\x02" + random_bytestring: "\x01\x02\x01\x02\x01\x02\x01\x02" } seed_for_prng: 4 } diff --git a/test/common/upstream/random_load_balancer_corpus/random_Normal b/test/common/upstream/random_load_balancer_corpus/random_Normal index 0d0d605bad386..27947391c6b48 100644 --- a/test/common/upstream/random_load_balancer_corpus/random_Normal +++ b/test/common/upstream/random_load_balancer_corpus/random_Normal @@ -6,7 +6,7 @@ actions { update_health_flags { host_priority: 0 num_healthy_hosts: 2 - random_bytestring: "\x01\x02\x01\x02" + random_bytestring: "aergteawthgrstyhaersgeasrgreasg" } } actions { @@ -31,11 +31,11 @@ actions { } setup_priority_levels { num_hosts_in_priority_level: 2 - random_bytestring: "\x01\x02\x01\x02" + random_bytestring: "aergagerageraegr" } setup_priority_levels { num_hosts_in_priority_level: 0 - random_bytestring: "\x01\x02\x01\x02" + random_bytestring: "agreaergvaergaegr" } seed_for_prng: 1 } diff --git a/test/common/upstream/random_load_balancer_corpus/random_crash-55abbf82c64b5a62e299b93d7b254045471199c9 b/test/common/upstream/random_load_balancer_corpus/random_crash-55abbf82c64b5a62e299b93d7b254045471199c9 new file mode 100644 index 0000000000000..e4dbc5a7cd693 --- /dev/null +++ b/test/common/upstream/random_load_balancer_corpus/random_crash-55abbf82c64b5a62e299b93d7b254045471199c9 @@ -0,0 +1,41 @@ +load_balancer_test_case { +common_lb_config { + +} +actions { + update_health_flags { + host_priority: 0 + num_healthy_hosts: 2 + random_bytestring: "aegrkiyuttkyumfae" + } +} +actions { + prefetch { + + } +} +actions { + prefetch { + + } +} +actions { + choose_host { + + } +} +actions { + choose_host { + + } +} +setup_priority_levels { + num_hosts_in_priority_level: 250 + random_bytestring: "ukjyrkjyrujaegregaeagr" +} +setup_priority_levels { + num_hosts_in_priority_level: 250 + random_bytestring: "aerhyytjtyukytufagfe" +} +seed_for_prng: 4 +} diff --git a/test/common/upstream/random_load_balancer_corpus/random_crash-5a64c214e5c2038299c8f2e85f143f1163077c1b b/test/common/upstream/random_load_balancer_corpus/random_crash-5a64c214e5c2038299c8f2e85f143f1163077c1b new file mode 100644 index 0000000000000..776eccfd8a37d --- /dev/null +++ b/test/common/upstream/random_load_balancer_corpus/random_crash-5a64c214e5c2038299c8f2e85f143f1163077c1b @@ -0,0 +1,25 @@ +load_balancer_test_case { + common_lb_config { + healthy_panic_threshold { + value: 4.88907830238399e-311 + } + consistent_hashing_lb_config { + use_hostname_for_hashing: true + hash_balance_factor { + value: 1024 + } + } + } + actions { + update_health_flags { + host_priority: 270582939648 + num_degraded_hosts: 4194304 + random_bytestring: "aergaergaerghaerhgaerghaergaerg" + } + } + setup_priority_levels { + num_hosts_in_priority_level: 1024 + random_bytestring: "yrfukykyrthrtgrgera" + } + seed_for_prng: 62208 +} diff --git a/test/common/upstream/random_load_balancer_corpus/random_with_locality-50000-hosts b/test/common/upstream/random_load_balancer_corpus/random_with_locality-50000-hosts new file mode 100644 index 0000000000000..2357bf88768f8 --- /dev/null +++ b/test/common/upstream/random_load_balancer_corpus/random_with_locality-50000-hosts @@ -0,0 +1,49 @@ +load_balancer_test_case { +common_lb_config { + +} +actions { + update_health_flags { + host_priority: 0 + num_healthy_hosts: 2 + num_degraded_hosts: 3 + num_excluded_hosts: 4 + random_bytestring: "eargfaergaergaergaerggaereargaegr" + } +} +actions { + prefetch { + + } +} +actions { + prefetch { + + } +} +actions { + choose_host { + + } +} +actions { + choose_host { + + } +} +setup_priority_levels { + num_hosts_in_priority_level: 50000 + num_hosts_locality_a: 1000 + num_hosts_locality_b: 500 + num_hosts_locality_c: 1500 + random_bytestring: "eragaerghahtgrathaertthgrtahrathggraaergeargaergae" +} +setup_priority_levels { + num_hosts_in_priority_level: 50000 + num_hosts_locality_a: 300 + num_hosts_locality_b: 1200 + num_hosts_locality_c: 1500 + random_bytestring: "dsfawetfawertfrawawetukyfyguukytfufrrawer" +} +seed_for_prng: 1 +} diff --git a/test/fuzz/random.h b/test/fuzz/random.h index f434b33b373f4..4245e197c730a 100644 --- a/test/fuzz/random.h +++ b/test/fuzz/random.h @@ -84,9 +84,14 @@ class ProperSubsetSelector { for (uint32_t i = 0; i < number_of_elements_in_subset && !(num_elements_left_ == 0); i++) { // Index of bytestring will wrap around if it "overflows" past the random bytestring's length. - uint32_t* bytes_from_bytestring = reinterpret_cast( - &random_bytestring_ + (index_of_random_bytestring_ % random_bytestring_.length())); - uint32_t index_of_index_vector = *bytes_from_bytestring % num_elements_left_; + // uint32_t* bytes_from_bytestring = reinterpret_cast( + // &random_bytestring_[index_of_random_bytestring_ % random_bytestring_.length()]); + std::string bytes_from_bytestring = + random_bytestring_.substr(index_of_random_bytestring_ % random_bytestring_.length(), 4); + /*uint32_t random_32_bits; + absl::SimpleAtoi(bytes_from_bytestring, &random_32_bits);*/ + uint32_t index_of_index_vector = + *reinterpret_cast(&bytes_from_bytestring) % num_elements_left_; uint32_t index = index_vector.at(index_of_index_vector); subset.push_back(index); // Move the index chosen to the end of the vector - will not be chosen again diff --git a/test/fuzz/random_test.cc b/test/fuzz/random_test.cc index 9e7fd1012260e..9c8f85d37a5ce 100644 --- a/test/fuzz/random_test.cc +++ b/test/fuzz/random_test.cc @@ -9,16 +9,14 @@ namespace Envoy { namespace Fuzz { // Test the subset selection - since selection is based on a passed in random bytestring you can -// work the algorithm yourself Pass in 5 elements, expect first subset to be element 2 and element -// 4, second subset to be elements 1, 2, 3 +// work the algorithm yourself Pass in 5 elements, expect first subset to be element 0 and element +// 4, second subset to be elements 2, 3, 1 TEST(BasicSubsetSelection, RandomTest) { - // \x01 chooses the first element, which gets swapped with last element, 0x3 chooses the third - // index, which gets swapped with last element etc. - std::string random_bytestring = "\x01\x03\x09\x04\x33"; + std::string random_bytestring = "aergaergaerwhgaerlgnj"; ProperSubsetSelector subset_selector(random_bytestring); - const std::vector> subsets = subset_selector.constructSubsets({2, 3}, 5); - const std::vector expected_subset_one = {1, 3}; - const std::vector expected_subset_two = {0, 2, 4}; + const std::vector> subsets = subset_selector.constructSubsets({2, 3}, 5); + const std::vector expected_subset_one = {0, 4}; + const std::vector expected_subset_two = {2, 3, 1}; EXPECT_THAT(subsets[0], ContainerEq(expected_subset_one)); EXPECT_THAT(subsets[1], ContainerEq(expected_subset_two)); } From 10499798abab5c092b8cdde179e947cc1d3a6c09 Mon Sep 17 00:00:00 2001 From: Zach Date: Wed, 28 Oct 2020 22:22:53 +0000 Subject: [PATCH 4/6] Responded to Harvey's comments Signed-off-by: Zach --- test/common/upstream/load_balancer_fuzz.proto | 8 ++++-- .../upstream/load_balancer_fuzz_base.cc | 25 +++++++++++------ .../common/upstream/load_balancer_fuzz_base.h | 8 +++--- .../random_256_ports | 6 ++--- .../random_NoHosts | 10 +++++-- .../random_load_balancer_corpus/random_Normal | 15 ++++++++--- ...h-55abbf82c64b5a62e299b93d7b254045471199c9 | 6 ++--- ...h-5a64c214e5c2038299c8f2e85f143f1163077c1b | 4 +-- ...h-ba5efdfd9c412a8507087120783fe6529b1ac0cb | 4 +-- .../random_largest-port-value | 4 +-- .../random_many_choose_hosts | 8 ++++-- .../random_max_ports | 15 ++++++++--- .../random_overflowing_ports | 15 ++++++++--- ...t-eed4596101efb3e737f736c8d5bcd4f0815a8728 | 20 +++++++++++--- .../random_slow-unit-test | 20 +++++++++++--- .../random_test_something | 15 ++++++++--- ...t-6b0d6b83136a4cf0b9ccd468f11207a792859d43 | 10 +++++-- ...t-9144cfbb40b5101ecc28b205b10e6c36a72aae83 | 10 +++++-- .../random_with-locality | 15 ++++++++--- .../random_with-locality-high-number-of-hosts | 15 ++++++++--- .../random_with_locality-50000-hosts | 15 ++++++++--- test/fuzz/random.h | 27 +++++-------------- test/fuzz/random_test.cc | 18 ++++++++----- 23 files changed, 202 insertions(+), 91 deletions(-) diff --git a/test/common/upstream/load_balancer_fuzz.proto b/test/common/upstream/load_balancer_fuzz.proto index debde43378080..af5a52662451e 100644 --- a/test/common/upstream/load_balancer_fuzz.proto +++ b/test/common/upstream/load_balancer_fuzz.proto @@ -15,7 +15,10 @@ message UpdateHealthFlags { uint32 num_degraded_hosts = 3; uint32 num_excluded_hosts = 4; // This is used to determine which hosts get marked as healthy, degraded, and excluded. - bytes random_bytestring = 5 [(validate.rules).bytes = {min_len: 4, max_len: 40000}]; + //bytes random_bytestring = 5 [(validate.rules).bytes = {min_len: 4, max_len: 40000}]; + // TODO: What should this be capped at? + repeated uint32 random_bytestring = 5 + [(validate.rules).repeated = {min_items: 1, max_items: 10000}]; } message LbAction { @@ -38,7 +41,8 @@ message SetupPriorityLevel { // Hard cap at 3 localities for simplicity uint32 num_hosts_locality_c = 4 [(validate.rules).uint32.lte = 60000]; // For choosing which hosts go in which locality - bytes random_bytestring = 5 [(validate.rules).bytes = {min_len: 4, max_len: 50000}]; + repeated uint32 random_bytestring = 5 + [(validate.rules).repeated = {min_items: 1, max_items: 10000}]; } // This message represents what LoadBalancerFuzzBase will interact with, performing setup of host sets and calling into load balancers. diff --git a/test/common/upstream/load_balancer_fuzz_base.cc b/test/common/upstream/load_balancer_fuzz_base.cc index c6d37857027d1..367a9b95deb98 100644 --- a/test/common/upstream/load_balancer_fuzz_base.cc +++ b/test/common/upstream/load_balancer_fuzz_base.cc @@ -9,6 +9,16 @@ namespace { constexpr uint32_t MaxNumHostsPerPriorityLevel = 60000; +// Helper function for converting repeated proto fields to byte vectors to pass into random subset +std::vector +constructByteVectorForRandom(const Protobuf::RepeatedField& random_bytestring) { + std::vector random_bytestring_vector; + for (int i = 0; i < random_bytestring.size(); ++i) { + random_bytestring_vector.push_back(random_bytestring.at(i)); + } + return random_bytestring_vector; +} + } // namespace HostVector @@ -36,7 +46,8 @@ void LoadBalancerFuzzBase::initializeASingleHostSet( ++hosts_made; } - Fuzz::ProperSubsetSelector subset_selector(setup_priority_level.random_bytestring()); + Fuzz::ProperSubsetSelector subset_selector( + constructByteVectorForRandom(setup_priority_level.random_bytestring())); const std::vector> localities = subset_selector.constructSubsets( {setup_priority_level.num_hosts_locality_a(), setup_priority_level.num_hosts_locality_b(), @@ -85,11 +96,10 @@ void LoadBalancerFuzzBase::initializeLbComponents( // Updating host sets is shared amongst all the load balancer tests. Since logically, we're just // setting the mock priority set to have certain values, and all load balancers interface with host // sets and their health statuses, this action maps to all load balancers. -void LoadBalancerFuzzBase::updateHealthFlagsForAHostSet(const uint64_t host_priority, - const uint32_t num_healthy_hosts, - const uint32_t num_degraded_hosts, - const uint32_t num_excluded_hosts, - const std::string random_bytestring) { +void LoadBalancerFuzzBase::updateHealthFlagsForAHostSet( + const uint64_t host_priority, const uint32_t num_healthy_hosts, + const uint32_t num_degraded_hosts, const uint32_t num_excluded_hosts, + const Protobuf::RepeatedField& random_bytestring) { const uint8_t priority_of_host_set = host_priority % num_priority_levels_; ENVOY_LOG_MISC(trace, "Updating health flags for host set at priority: {}", priority_of_host_set); MockHostSet& host_set = *priority_set_.getMockHostSet(priority_of_host_set); @@ -113,7 +123,7 @@ void LoadBalancerFuzzBase::updateHealthFlagsForAHostSet(const uint64_t host_prio EXCLUDED = 2, }; - Fuzz::ProperSubsetSelector subset_selector(random_bytestring); + Fuzz::ProperSubsetSelector subset_selector(constructByteVectorForRandom(random_bytestring)); const std::vector> subsets = subset_selector.constructSubsets( {num_healthy_hosts, num_degraded_hosts, num_excluded_hosts}, host_set_size); @@ -240,7 +250,6 @@ void LoadBalancerFuzzBase::replay( } void LoadBalancerFuzzBase::clearStaticHostsHealthFlags() { - // Have to clear the hosts health flags here - how do we know what hosts to clear? // The only outstanding health flags set are those that are set from hosts being placed in // degraded and excluded. Thus, use the priority set pointer to know which flags to clear. for (uint32_t priority_level = 0; priority_level < priority_set_.hostSetsPerPriority().size(); diff --git a/test/common/upstream/load_balancer_fuzz_base.h b/test/common/upstream/load_balancer_fuzz_base.h index b6938e7046237..27e407c2250cd 100644 --- a/test/common/upstream/load_balancer_fuzz_base.h +++ b/test/common/upstream/load_balancer_fuzz_base.h @@ -23,10 +23,10 @@ class LoadBalancerFuzzBase { // Initializes load balancer components shared amongst every load balancer, random_, and // priority_set_ void initializeLbComponents(const test::common::upstream::LoadBalancerTestCase& input); - void updateHealthFlagsForAHostSet(const uint64_t host_priority, const uint32_t num_healthy_hosts, - const uint32_t num_degraded_hosts, - const uint32_t num_excluded_hosts, - const std::string random_bytestring); + void + updateHealthFlagsForAHostSet(const uint64_t host_priority, const uint32_t num_healthy_hosts, + const uint32_t num_degraded_hosts, const uint32_t num_excluded_hosts, + const Protobuf::RepeatedField& random_bytestring); // These two actions have a lot of logic attached to them. However, all the logic that the load // balancer needs to run its algorithm is already encapsulated within the load balancer. Thus, // once the load balancer is constructed, all this class has to do is call lb_->peekAnotherHost() diff --git a/test/common/upstream/random_load_balancer_corpus/random_256_ports b/test/common/upstream/random_load_balancer_corpus/random_256_ports index 306a4f8280fb8..e2792414cfe8f 100644 --- a/test/common/upstream/random_load_balancer_corpus/random_256_ports +++ b/test/common/upstream/random_load_balancer_corpus/random_256_ports @@ -6,7 +6,7 @@ actions { update_health_flags { host_priority: 0 num_healthy_hosts: 256 - random_bytestring: "\x01\x02\x03\x04\x45\x80" + random_bytestring: 1 } } actions { @@ -31,11 +31,11 @@ actions { } setup_priority_levels { num_hosts_in_priority_level: 256 - random_bytestring: "\x01\x02\x01\x02\x01\x02\x01\x02" + random_bytestring: 1 } setup_priority_levels { num_hosts_in_priority_level: 256 - random_bytestring: "\x01\x02\x01\x02\x01\x02\x01\x02" + random_bytestring: 1 } seed_for_prng: 4 } diff --git a/test/common/upstream/random_load_balancer_corpus/random_NoHosts b/test/common/upstream/random_load_balancer_corpus/random_NoHosts index bbd0eb803656f..63b10ab1aa3d8 100644 --- a/test/common/upstream/random_load_balancer_corpus/random_NoHosts +++ b/test/common/upstream/random_load_balancer_corpus/random_NoHosts @@ -14,11 +14,17 @@ actions { } setup_priority_levels { num_hosts_in_priority_level: 0 - random_bytestring: "\x01\x02\x01\x02" + random_bytestring: 1 + random_bytestring: 2 + random_bytestring: 1 + random_bytestring: 2 } setup_priority_levels { num_hosts_in_priority_level: 0 - random_bytestring: "\x01\x02\x01\x02" + random_bytestring: 1 + random_bytestring: 2 + random_bytestring: 1 + random_bytestring: 2 } seed_for_prng: 2 } diff --git a/test/common/upstream/random_load_balancer_corpus/random_Normal b/test/common/upstream/random_load_balancer_corpus/random_Normal index 27947391c6b48..66bff38e17c65 100644 --- a/test/common/upstream/random_load_balancer_corpus/random_Normal +++ b/test/common/upstream/random_load_balancer_corpus/random_Normal @@ -6,7 +6,10 @@ actions { update_health_flags { host_priority: 0 num_healthy_hosts: 2 - random_bytestring: "aergteawthgrstyhaersgeasrgreasg" + random_bytestring: 1 + random_bytestring: 2 + random_bytestring: 1 + random_bytestring: 2 } } actions { @@ -31,11 +34,17 @@ actions { } setup_priority_levels { num_hosts_in_priority_level: 2 - random_bytestring: "aergagerageraegr" + random_bytestring: 1 + random_bytestring: 2 + random_bytestring: 1 + random_bytestring: 2 } setup_priority_levels { num_hosts_in_priority_level: 0 - random_bytestring: "agreaergvaergaegr" + random_bytestring: 1 + random_bytestring: 2 + random_bytestring: 1 + random_bytestring: 2 } seed_for_prng: 1 } diff --git a/test/common/upstream/random_load_balancer_corpus/random_crash-55abbf82c64b5a62e299b93d7b254045471199c9 b/test/common/upstream/random_load_balancer_corpus/random_crash-55abbf82c64b5a62e299b93d7b254045471199c9 index e4dbc5a7cd693..ca01834b31162 100644 --- a/test/common/upstream/random_load_balancer_corpus/random_crash-55abbf82c64b5a62e299b93d7b254045471199c9 +++ b/test/common/upstream/random_load_balancer_corpus/random_crash-55abbf82c64b5a62e299b93d7b254045471199c9 @@ -6,7 +6,7 @@ actions { update_health_flags { host_priority: 0 num_healthy_hosts: 2 - random_bytestring: "aegrkiyuttkyumfae" + random_bytestring: 1 } } actions { @@ -31,11 +31,11 @@ actions { } setup_priority_levels { num_hosts_in_priority_level: 250 - random_bytestring: "ukjyrkjyrujaegregaeagr" + random_bytestring: 1 } setup_priority_levels { num_hosts_in_priority_level: 250 - random_bytestring: "aerhyytjtyukytufagfe" + random_bytestring: 1 } seed_for_prng: 4 } diff --git a/test/common/upstream/random_load_balancer_corpus/random_crash-5a64c214e5c2038299c8f2e85f143f1163077c1b b/test/common/upstream/random_load_balancer_corpus/random_crash-5a64c214e5c2038299c8f2e85f143f1163077c1b index 776eccfd8a37d..cb19f383c3870 100644 --- a/test/common/upstream/random_load_balancer_corpus/random_crash-5a64c214e5c2038299c8f2e85f143f1163077c1b +++ b/test/common/upstream/random_load_balancer_corpus/random_crash-5a64c214e5c2038299c8f2e85f143f1163077c1b @@ -14,12 +14,12 @@ load_balancer_test_case { update_health_flags { host_priority: 270582939648 num_degraded_hosts: 4194304 - random_bytestring: "aergaergaerghaerhgaerghaergaerg" + random_bytestring: 1 } } setup_priority_levels { num_hosts_in_priority_level: 1024 - random_bytestring: "yrfukykyrthrtgrgera" + random_bytestring: 1 } seed_for_prng: 62208 } diff --git a/test/common/upstream/random_load_balancer_corpus/random_crash-ba5efdfd9c412a8507087120783fe6529b1ac0cb b/test/common/upstream/random_load_balancer_corpus/random_crash-ba5efdfd9c412a8507087120783fe6529b1ac0cb index fbd29c7b9425f..65c8062d59c0a 100644 --- a/test/common/upstream/random_load_balancer_corpus/random_crash-ba5efdfd9c412a8507087120783fe6529b1ac0cb +++ b/test/common/upstream/random_load_balancer_corpus/random_crash-ba5efdfd9c412a8507087120783fe6529b1ac0cb @@ -28,11 +28,11 @@ actions { } setup_priority_levels { num_hosts_in_priority_level: 2 - random_bytestring: "\x01\x02\x01\x02" + random_bytestring: 1 } setup_priority_levels { num_hosts_in_priority_level: 9007199259945536 - random_bytestring: "\x01\x02\x01\x02" + random_bytestring: 1 } seed_for_prng: 6 } diff --git a/test/common/upstream/random_load_balancer_corpus/random_largest-port-value b/test/common/upstream/random_load_balancer_corpus/random_largest-port-value index 7801b65715b18..a89ecba1b8de4 100644 --- a/test/common/upstream/random_load_balancer_corpus/random_largest-port-value +++ b/test/common/upstream/random_load_balancer_corpus/random_largest-port-value @@ -24,11 +24,11 @@ actions { } nsetup_priority_levels { num_hosts_in_priority_level: 65455 - random_bytestring: "\x01\x02\x01\x02" + random_bytestring: 1 } setup_priority_levels { num_hosts_in_priority_level: 65455 - random_bytestring: "\x01\x02\x01\x02" + random_bytestring: 1 } seed_for_prng: 5 } diff --git a/test/common/upstream/random_load_balancer_corpus/random_many_choose_hosts b/test/common/upstream/random_load_balancer_corpus/random_many_choose_hosts index 562f60b80a10e..53a69c852f58f 100644 --- a/test/common/upstream/random_load_balancer_corpus/random_many_choose_hosts +++ b/test/common/upstream/random_load_balancer_corpus/random_many_choose_hosts @@ -51,11 +51,15 @@ actions { } setup_priority_levels { num_hosts_in_priority_level: 2 - random_bytestring: "\x01\x02\x01\x02" + random_bytestring: 1 + random_bytestring: 2 } setup_priority_levels { num_hosts_in_priority_level: 0 - random_bytestring: "\x01\x02\x01\x02" + random_bytestring: 1 + random_bytestring: 2 + random_bytestring: 1 + random_bytestring: 2 } seed_for_prng: 1 } diff --git a/test/common/upstream/random_load_balancer_corpus/random_max_ports b/test/common/upstream/random_load_balancer_corpus/random_max_ports index b309c42775850..73e56d8d76370 100644 --- a/test/common/upstream/random_load_balancer_corpus/random_max_ports +++ b/test/common/upstream/random_load_balancer_corpus/random_max_ports @@ -6,7 +6,10 @@ actions { update_health_flags { host_priority: 0 num_healthy_hosts: 2 - random_bytestring: "\x01\x02\x03\x04" + random_bytestring: 1 + random_bytestring: 2 + random_bytestring: 3 + random_bytestring: 4 } } actions { @@ -31,11 +34,17 @@ actions { } setup_priority_levels { num_hosts_in_priority_level: 32726 - random_bytestring: "\x01\x02\x01\x02" + random_bytestring: 1 + random_bytestring: 2 + random_bytestring: 1 + random_bytestring: 2 } setup_priority_levels { num_hosts_in_priority_level: 32726 - random_bytestring: "\x01\x02\x01\x02" + random_bytestring: 1 + random_bytestring: 2 + random_bytestring: 1 + random_bytestring: 2 } seed_for_prng: 88 } diff --git a/test/common/upstream/random_load_balancer_corpus/random_overflowing_ports b/test/common/upstream/random_load_balancer_corpus/random_overflowing_ports index 4c1e2309fa48e..4ec8cd27d2ac6 100644 --- a/test/common/upstream/random_load_balancer_corpus/random_overflowing_ports +++ b/test/common/upstream/random_load_balancer_corpus/random_overflowing_ports @@ -6,7 +6,10 @@ actions { update_health_flags { host_priority: 0 num_healthy_hosts: 2 - random_bytestring: "laierghilaerghfliakreg" + random_bytestring: 1 + random_bytestring: 2 + random_bytestring: 1 + random_bytestring: 2 } } actions { @@ -31,11 +34,17 @@ actions { } setup_priority_levels { num_hosts_in_priority_level: 60000 - random_bytestring: "aergaergaegrfkijhilaegr" + random_bytestring: 1 + random_bytestring: 2 + random_bytestring: 1 + random_bytestring: 2 } setup_priority_levels { num_hosts_in_priority_level: 60000 - random_bytestring: "3q4tgsrht674eu43" + random_bytestring: 1 + random_bytestring: 2 + random_bytestring: 1 + random_bytestring: 2 } seed_for_prng: 4 } diff --git a/test/common/upstream/random_load_balancer_corpus/random_slow-unit-eed4596101efb3e737f736c8d5bcd4f0815a8728 b/test/common/upstream/random_load_balancer_corpus/random_slow-unit-eed4596101efb3e737f736c8d5bcd4f0815a8728 index 906d7ec670cbe..b8f81a4d451cb 100644 --- a/test/common/upstream/random_load_balancer_corpus/random_slow-unit-eed4596101efb3e737f736c8d5bcd4f0815a8728 +++ b/test/common/upstream/random_load_balancer_corpus/random_slow-unit-eed4596101efb3e737f736c8d5bcd4f0815a8728 @@ -7,7 +7,10 @@ load_balancer_test_case { actions { update_health_flags { num_healthy_hosts: 2 - random_bytestring: "\001\002\003\004" + random_bytestring: 1 + random_bytestring: 2 + random_bytestring: 3 + random_bytestring: 4 } } actions { @@ -25,16 +28,25 @@ load_balancer_test_case { actions { update_health_flags { num_healthy_hosts: 2 - random_bytestring: "\001\002\003\004" + random_bytestring: 1 + random_bytestring: 2 + random_bytestring: 3 + random_bytestring: 4 } } setup_priority_levels { num_hosts_in_priority_level: 536903638 - random_bytestring: "\001\002\003\004" + random_bytestring: 1 + random_bytestring: 2 + random_bytestring: 3 + random_bytestring: 4 } setup_priority_levels { num_hosts_in_priority_level: 32726 - random_bytestring: "\001\002\003\004" + random_bytestring: 1 + random_bytestring: 2 + random_bytestring: 3 + random_bytestring: 4 } seed_for_prng: 88 } diff --git a/test/common/upstream/random_load_balancer_corpus/random_slow-unit-test b/test/common/upstream/random_load_balancer_corpus/random_slow-unit-test index 48292e8963583..1abe2824c65b4 100644 --- a/test/common/upstream/random_load_balancer_corpus/random_slow-unit-test +++ b/test/common/upstream/random_load_balancer_corpus/random_slow-unit-test @@ -7,7 +7,10 @@ load_balancer_test_case { actions { update_health_flags { num_healthy_hosts: 2 - random_bytestring: "aergswyhtydjkkyugikt" + random_bytestring: 1 + random_bytestring: 2 + random_bytestring: 1 + random_bytestring: 2 } } actions { @@ -25,7 +28,10 @@ load_balancer_test_case { actions { update_health_flags { num_healthy_hosts: 2 - random_bytestring: "arwefawefeaqgftrsehttyjhui" + random_bytestring: 1 + random_bytestring: 2 + random_bytestring: 1 + random_bytestring: 2 } } setup_priority_levels { @@ -33,14 +39,20 @@ load_balancer_test_case { num_hosts_locality_one: 50 num_hosts_locality_two: 50 num_hosts_locality_three: 50 - random_bytestring: "awertfeyjuhytukgjmu" + random_bytestring: 1 + random_bytestring: 2 + random_bytestring: 1 + random_bytestring: 2 } setup_priority_levels { num_hosts_in_priority_level: 500 num_hosts_locality_one: 50 num_hosts_locality_two: 50 num_hosts_locality_three: 50 - random_bytestring: "awerfuilyetrs" + random_bytestring: 1 + random_bytestring: 2 + random_bytestring: 1 + random_bytestring: 2 } seed_for_prng: 88 } diff --git a/test/common/upstream/random_load_balancer_corpus/random_test_something b/test/common/upstream/random_load_balancer_corpus/random_test_something index e4dbc5a7cd693..7025e0fed767b 100644 --- a/test/common/upstream/random_load_balancer_corpus/random_test_something +++ b/test/common/upstream/random_load_balancer_corpus/random_test_something @@ -6,7 +6,10 @@ actions { update_health_flags { host_priority: 0 num_healthy_hosts: 2 - random_bytestring: "aegrkiyuttkyumfae" + random_bytestring: 1 + random_bytestring: 2 + random_bytestring: 1 + random_bytestring: 2 } } actions { @@ -31,11 +34,17 @@ actions { } setup_priority_levels { num_hosts_in_priority_level: 250 - random_bytestring: "ukjyrkjyrujaegregaeagr" + random_bytestring: 1 + random_bytestring: 2 + random_bytestring: 1 + random_bytestring: 2 } setup_priority_levels { num_hosts_in_priority_level: 250 - random_bytestring: "aerhyytjtyukytufagfe" + random_bytestring: 1 + random_bytestring: 2 + random_bytestring: 1 + random_bytestring: 2 } seed_for_prng: 4 } diff --git a/test/common/upstream/random_load_balancer_corpus/random_timeout-6b0d6b83136a4cf0b9ccd468f11207a792859d43 b/test/common/upstream/random_load_balancer_corpus/random_timeout-6b0d6b83136a4cf0b9ccd468f11207a792859d43 index aa119d68145b6..75df003cee291 100644 --- a/test/common/upstream/random_load_balancer_corpus/random_timeout-6b0d6b83136a4cf0b9ccd468f11207a792859d43 +++ b/test/common/upstream/random_load_balancer_corpus/random_timeout-6b0d6b83136a4cf0b9ccd468f11207a792859d43 @@ -20,12 +20,18 @@ load_balancer_test_case { actions { update_health_flags { num_excluded_hosts: 268435456 - random_bytestring: "aergaergyhreaggear" + random_bytestring: 1 + random_bytestring: 2 + random_bytestring: 1 + random_bytestring: 2 } } setup_priority_levels { num_hosts_in_priority_level: 13534154135 - random_bytestring: "earghaegraergaergaergaerg" + random_bytestring: 1 + random_bytestring: 2 + random_bytestring: 1 + random_bytestring: 2 } seed_for_prng: 32 } diff --git a/test/common/upstream/random_load_balancer_corpus/random_timeout-9144cfbb40b5101ecc28b205b10e6c36a72aae83 b/test/common/upstream/random_load_balancer_corpus/random_timeout-9144cfbb40b5101ecc28b205b10e6c36a72aae83 index 776eccfd8a37d..79d6fde49fdef 100644 --- a/test/common/upstream/random_load_balancer_corpus/random_timeout-9144cfbb40b5101ecc28b205b10e6c36a72aae83 +++ b/test/common/upstream/random_load_balancer_corpus/random_timeout-9144cfbb40b5101ecc28b205b10e6c36a72aae83 @@ -14,12 +14,18 @@ load_balancer_test_case { update_health_flags { host_priority: 270582939648 num_degraded_hosts: 4194304 - random_bytestring: "aergaergaerghaerhgaerghaergaerg" + random_bytestring: 1 + random_bytestring: 2 + random_bytestring: 1 + random_bytestring: 2 } } setup_priority_levels { num_hosts_in_priority_level: 1024 - random_bytestring: "yrfukykyrthrtgrgera" + random_bytestring: 1 + random_bytestring: 2 + random_bytestring: 1 + random_bytestring: 2 } seed_for_prng: 62208 } diff --git a/test/common/upstream/random_load_balancer_corpus/random_with-locality b/test/common/upstream/random_load_balancer_corpus/random_with-locality index 39023351784a3..15adcc4de667b 100644 --- a/test/common/upstream/random_load_balancer_corpus/random_with-locality +++ b/test/common/upstream/random_load_balancer_corpus/random_with-locality @@ -8,7 +8,10 @@ actions { num_healthy_hosts: 2 num_degraded_hosts: 3 num_excluded_hosts: 4 - random_bytestring: "eargfaergaergaergaerggaereargaegr" + random_bytestring: 1 + random_bytestring: 2 + random_bytestring: 1 + random_bytestring: 2 } } actions { @@ -36,14 +39,20 @@ setup_priority_levels { num_hosts_locality_a: 3 num_hosts_locality_b: 4 num_hosts_locality_c: 5 - random_bytestring: "eragaerghahtgrathaertthgrtahrathggraaergeargaergae" + random_bytestring: 1 + random_bytestring: 2 + random_bytestring: 1 + random_bytestring: 2 } setup_priority_levels { num_hosts_in_priority_level: 20 num_hosts_locality_a: 3 num_hosts_locality_b: 4 num_hosts_locality_c: 5 - random_bytestring: "dsfawetfawertfrawawetukyfyguukytfufrrawer" + random_bytestring: 1 + random_bytestring: 2 + random_bytestring: 1 + random_bytestring: 2 } seed_for_prng: 1 } diff --git a/test/common/upstream/random_load_balancer_corpus/random_with-locality-high-number-of-hosts b/test/common/upstream/random_load_balancer_corpus/random_with-locality-high-number-of-hosts index 6af6e39d0d2b5..2a96d688b5d6c 100644 --- a/test/common/upstream/random_load_balancer_corpus/random_with-locality-high-number-of-hosts +++ b/test/common/upstream/random_load_balancer_corpus/random_with-locality-high-number-of-hosts @@ -8,7 +8,10 @@ actions { num_healthy_hosts: 2 num_degraded_hosts: 3 num_excluded_hosts: 4 - random_bytestring: "eargfaergaergaergaerggaereargaegr" + random_bytestring: 100000 + random_bytestring: 1000000 + random_bytestring: 1500000 + random_bytestring: 2000000 } } actions { @@ -36,14 +39,20 @@ setup_priority_levels { num_hosts_locality_a: 1000 num_hosts_locality_b: 500 num_hosts_locality_c: 1500 - random_bytestring: "eragaerghahtgrathaertthgrtahrathggraaergeargaergae" + random_bytestring: 100000 + random_bytestring: 1000000 + random_bytestring: 1500000 + random_bytestring: 2000000 } setup_priority_levels { num_hosts_in_priority_level: 3000 num_hosts_locality_a: 300 num_hosts_locality_b: 1200 num_hosts_locality_c: 1500 - random_bytestring: "dsfawetfawertfrawawetukyfyguukytfufrrawer" + random_bytestring: 100000 + random_bytestring: 1000000 + random_bytestring: 1500000 + random_bytestring: 2000000 } seed_for_prng: 1 } diff --git a/test/common/upstream/random_load_balancer_corpus/random_with_locality-50000-hosts b/test/common/upstream/random_load_balancer_corpus/random_with_locality-50000-hosts index 2357bf88768f8..7a1784375405a 100644 --- a/test/common/upstream/random_load_balancer_corpus/random_with_locality-50000-hosts +++ b/test/common/upstream/random_load_balancer_corpus/random_with_locality-50000-hosts @@ -8,7 +8,10 @@ actions { num_healthy_hosts: 2 num_degraded_hosts: 3 num_excluded_hosts: 4 - random_bytestring: "eargfaergaergaergaerggaereargaegr" + random_bytestring: 1 + random_bytestring: 2 + random_bytestring: 1 + random_bytestring: 2 } } actions { @@ -36,14 +39,20 @@ setup_priority_levels { num_hosts_locality_a: 1000 num_hosts_locality_b: 500 num_hosts_locality_c: 1500 - random_bytestring: "eragaerghahtgrathaertthgrtahrathggraaergeargaergae" + random_bytestring: 1 + random_bytestring: 2 + random_bytestring: 1 + random_bytestring: 2 } setup_priority_levels { num_hosts_in_priority_level: 50000 num_hosts_locality_a: 300 num_hosts_locality_b: 1200 num_hosts_locality_c: 1500 - random_bytestring: "dsfawetfawertfrawawetukyfyguukytfufrrawer" + random_bytestring: 1 + random_bytestring: 2 + random_bytestring: 1 + random_bytestring: 2 } seed_for_prng: 1 } diff --git a/test/fuzz/random.h b/test/fuzz/random.h index 4245e197c730a..d6528964f8580 100644 --- a/test/fuzz/random.h +++ b/test/fuzz/random.h @@ -36,16 +36,8 @@ namespace Fuzz { class ProperSubsetSelector { public: - ProperSubsetSelector(const std::string& random_bytestring) - : random_bytestring_(random_bytestring) { - // Must be at least 4 bytes wide to serve as randomness for the subset selector - ASSERT(random_bytestring_.length() >= 4); - // Pull off the last few bits to make random_bytestring_ a multiple of 4 - this will make - // iteration through the bytestring a lot easier and cleaner - while (random_bytestring_.length() % 4 != 0) { - random_bytestring_.pop_back(); - } - } + ProperSubsetSelector(const std::vector& random_bytestring) + : random_bytestring_(random_bytestring) {} /** * This function does proper subset selection on a certain number of elements. It returns a vector @@ -83,22 +75,16 @@ class ProperSubsetSelector { std::vector subset; for (uint32_t i = 0; i < number_of_elements_in_subset && !(num_elements_left_ == 0); i++) { - // Index of bytestring will wrap around if it "overflows" past the random bytestring's length. - // uint32_t* bytes_from_bytestring = reinterpret_cast( - // &random_bytestring_[index_of_random_bytestring_ % random_bytestring_.length()]); - std::string bytes_from_bytestring = - random_bytestring_.substr(index_of_random_bytestring_ % random_bytestring_.length(), 4); - /*uint32_t random_32_bits; - absl::SimpleAtoi(bytes_from_bytestring, &random_32_bits);*/ uint32_t index_of_index_vector = - *reinterpret_cast(&bytes_from_bytestring) % num_elements_left_; + random_bytestring_.at(index_of_random_bytestring_ % random_bytestring_.size()) % + num_elements_left_; uint32_t index = index_vector.at(index_of_index_vector); subset.push_back(index); // Move the index chosen to the end of the vector - will not be chosen again std::swap(index_vector[index_of_index_vector], index_vector[num_elements_left_ - 1]); --num_elements_left_; - index_of_random_bytestring_ += 4; + ++index_of_random_bytestring_; } return subset; @@ -106,8 +92,7 @@ class ProperSubsetSelector { // This bytestring will be iterated through representing randomness in order to choose // subsets - std::string random_bytestring_; - // This will iterate by 4 every time bytestring is iterated + std::vector random_bytestring_; uint32_t index_of_random_bytestring_ = 0; // Used to make subset construction linear time complexity with std::swap - chosen indexes will be diff --git a/test/fuzz/random_test.cc b/test/fuzz/random_test.cc index 9c8f85d37a5ce..4613583d468d2 100644 --- a/test/fuzz/random_test.cc +++ b/test/fuzz/random_test.cc @@ -9,14 +9,18 @@ namespace Envoy { namespace Fuzz { // Test the subset selection - since selection is based on a passed in random bytestring you can -// work the algorithm yourself Pass in 5 elements, expect first subset to be element 0 and element -// 4, second subset to be elements 2, 3, 1 -TEST(BasicSubsetSelection, RandomTest) { - std::string random_bytestring = "aergaergaerwhgaerlgnj"; +// work the algorithm yourself. This test also tests if the subset selection handles 32 bits. +TEST(BasicSubsetSelection, ValidateScaleTest) { + std::vector random_bytestring; + random_bytestring.push_back(1000000); + random_bytestring.push_back(1500000); + random_bytestring.push_back(2000000); + random_bytestring.push_back(2500000); ProperSubsetSelector subset_selector(random_bytestring); - const std::vector> subsets = subset_selector.constructSubsets({2, 3}, 5); - const std::vector expected_subset_one = {0, 4}; - const std::vector expected_subset_two = {2, 3, 1}; + const std::vector> subsets = + subset_selector.constructSubsets({2, 2}, 10000000); + const std::vector expected_subset_one = {1000000, 1500000}; + const std::vector expected_subset_two = {2000000, 2500000}; EXPECT_THAT(subsets[0], ContainerEq(expected_subset_one)); EXPECT_THAT(subsets[1], ContainerEq(expected_subset_two)); } From ba6976f41a6d5adf1c1c9e94f9a2e3a8b421de5c Mon Sep 17 00:00:00 2001 From: Zach Date: Thu, 29 Oct 2020 16:03:10 +0000 Subject: [PATCH 5/6] Responded to Asra's comments Signed-off-by: Zach --- test/common/upstream/load_balancer_fuzz.proto | 8 ++++---- test/common/upstream/load_balancer_fuzz_base.cc | 13 ++++++------- test/common/upstream/load_balancer_fuzz_base.h | 6 +++--- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/test/common/upstream/load_balancer_fuzz.proto b/test/common/upstream/load_balancer_fuzz.proto index af5a52662451e..fab5acfd9fb31 100644 --- a/test/common/upstream/load_balancer_fuzz.proto +++ b/test/common/upstream/load_balancer_fuzz.proto @@ -15,10 +15,10 @@ message UpdateHealthFlags { uint32 num_degraded_hosts = 3; uint32 num_excluded_hosts = 4; // This is used to determine which hosts get marked as healthy, degraded, and excluded. - //bytes random_bytestring = 5 [(validate.rules).bytes = {min_len: 4, max_len: 40000}]; - // TODO: What should this be capped at? + // TODO: What should this be capped at? There might be some efficiency/code coverage tradeoff + // dependent on the amount of digits this random_bytestring is allowed to scale too. repeated uint32 random_bytestring = 5 - [(validate.rules).repeated = {min_items: 1, max_items: 10000}]; + [(validate.rules).repeated = {min_items: 1, max_items: 60000}]; } message LbAction { @@ -42,7 +42,7 @@ message SetupPriorityLevel { uint32 num_hosts_locality_c = 4 [(validate.rules).uint32.lte = 60000]; // For choosing which hosts go in which locality repeated uint32 random_bytestring = 5 - [(validate.rules).repeated = {min_items: 1, max_items: 10000}]; + [(validate.rules).repeated = {min_items: 1, max_items: 60000}]; } // This message represents what LoadBalancerFuzzBase will interact with, performing setup of host sets and calling into load balancers. diff --git a/test/common/upstream/load_balancer_fuzz_base.cc b/test/common/upstream/load_balancer_fuzz_base.cc index 367a9b95deb98..1bf578b214dfd 100644 --- a/test/common/upstream/load_balancer_fuzz_base.cc +++ b/test/common/upstream/load_balancer_fuzz_base.cc @@ -12,20 +12,18 @@ constexpr uint32_t MaxNumHostsPerPriorityLevel = 60000; // Helper function for converting repeated proto fields to byte vectors to pass into random subset std::vector constructByteVectorForRandom(const Protobuf::RepeatedField& random_bytestring) { - std::vector random_bytestring_vector; - for (int i = 0; i < random_bytestring.size(); ++i) { - random_bytestring_vector.push_back(random_bytestring.at(i)); - } + std::vector random_bytestring_vector(random_bytestring.begin(), + random_bytestring.end()); return random_bytestring_vector; } } // namespace HostVector -LoadBalancerFuzzBase::initializeHostsForUseInFuzzing(std::shared_ptr info_) { +LoadBalancerFuzzBase::initializeHostsForUseInFuzzing(std::shared_ptr info) { HostVector hosts; for (uint32_t i = 1; i <= 60000; ++i) { - hosts.push_back(makeTestHost(info_, "tcp://127.0.0.1:" + std::to_string(i))); + hosts.push_back(makeTestHost(info, "tcp://127.0.0.1:" + std::to_string(i))); } return hosts; } @@ -38,7 +36,8 @@ void LoadBalancerFuzzBase::initializeASingleHostSet( priority_level, num_hosts_in_priority_level); MockHostSet& host_set = *priority_set_.getMockHostSet(priority_level); uint32_t hosts_made = 0; - // Cap each host set at 256 hosts for efficiency - Leave port clause in for future changes + // Cap each host set at 60000 hosts - however, let port number enforce a max of 60k hosts across + // all priority levels. while (hosts_made < std::min(num_hosts_in_priority_level, MaxNumHostsPerPriorityLevel) && port < 60000) { host_set.hosts_.push_back(initialized_hosts_[port]); diff --git a/test/common/upstream/load_balancer_fuzz_base.h b/test/common/upstream/load_balancer_fuzz_base.h index 27e407c2250cd..fc9abcffbf0f6 100644 --- a/test/common/upstream/load_balancer_fuzz_base.h +++ b/test/common/upstream/load_balancer_fuzz_base.h @@ -63,10 +63,10 @@ class LoadBalancerFuzzBase { // in absl::node_hash_map locality_indexes_; - static HostVector initializeHostsForUseInFuzzing(std::shared_ptr info_); + static HostVector initializeHostsForUseInFuzzing(std::shared_ptr info); - // Will statically initialize 10000? hosts in this vector - // Will have to clear flags at the end of each iteration here + // Will statically initialize 60000 hosts in this vector. Will have to clear these static + // hosts flags at the end of each fuzz iteration HostVector initialized_hosts_; }; From 5ee5fdb50769223d3e9b0dd1866d3fe4edbde6be Mon Sep 17 00:00:00 2001 From: Zach Date: Thu, 29 Oct 2020 18:15:44 +0000 Subject: [PATCH 6/6] Spelling Signed-off-by: Zach --- test/common/upstream/load_balancer_fuzz.proto | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/common/upstream/load_balancer_fuzz.proto b/test/common/upstream/load_balancer_fuzz.proto index fab5acfd9fb31..c152adc21248c 100644 --- a/test/common/upstream/load_balancer_fuzz.proto +++ b/test/common/upstream/load_balancer_fuzz.proto @@ -15,7 +15,7 @@ message UpdateHealthFlags { uint32 num_degraded_hosts = 3; uint32 num_excluded_hosts = 4; // This is used to determine which hosts get marked as healthy, degraded, and excluded. - // TODO: What should this be capped at? There might be some efficiency/code coverage tradeoff + // TODO: What should this be capped at? There might be some efficiency/code coverage trade off // dependent on the amount of digits this random_bytestring is allowed to scale too. repeated uint32 random_bytestring = 5 [(validate.rules).repeated = {min_items: 1, max_items: 60000}];