-
Notifications
You must be signed in to change notification settings - Fork 5.4k
upstream: Add ability to disable host selection during panic #8024
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
c35f5ab
867d7c5
d1f513f
fbce2af
5a93215
668f729
c45f03d
0616d4f
10a08b5
095be1b
b7a649c
bc54103
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -539,6 +539,39 @@ TEST_P(FailoverTest, PriorityUpdatesWithLocalHostSet) { | |
| EXPECT_EQ(tertiary_host_set_.hosts_[0], lb_->chooseHost(nullptr)); | ||
| } | ||
|
|
||
| // Test that extending the priority set with an existing LB causes the correct updates when the | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does 'an existing LB' refer to in this comment?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I inherited that particular phrasing from the comment on the previous test which I adapted for this PR. It looks to me as if it refers to checking the behavior of a load balancer before and after adding an additional host set. |
||
| // cluster is configured to disable on panic. | ||
| TEST_P(FailoverTest, PriorityUpdatesWithLocalHostSetDisableOnPanic) { | ||
| host_set_.hosts_ = {makeTestHost(info_, "tcp://127.0.0.1:80")}; | ||
| failover_host_set_.hosts_ = {makeTestHost(info_, "tcp://127.0.0.1:81")}; | ||
| common_config_.mutable_zone_aware_lb_config()->set_fail_traffic_on_panic(true); | ||
|
|
||
| init(false); | ||
| // With both the primary and failover hosts unhealthy, we should select no host. | ||
| EXPECT_EQ(nullptr, lb_->chooseHost(nullptr)); | ||
|
|
||
| // Update the priority set with a new priority level P=2 and ensure the host | ||
| // is chosen | ||
| MockHostSet& tertiary_host_set_ = *priority_set_.getMockHostSet(2); | ||
| HostVectorSharedPtr hosts(new HostVector({makeTestHost(info_, "tcp://127.0.0.1:82")})); | ||
| tertiary_host_set_.hosts_ = *hosts; | ||
| tertiary_host_set_.healthy_hosts_ = tertiary_host_set_.hosts_; | ||
| HostVector add_hosts; | ||
| add_hosts.push_back(tertiary_host_set_.hosts_[0]); | ||
| tertiary_host_set_.runCallbacks(add_hosts, {}); | ||
| EXPECT_EQ(tertiary_host_set_.hosts_[0], lb_->chooseHost(nullptr)); | ||
|
|
||
| // Now add a healthy host in P=0 and make sure it is immediately selected. | ||
| host_set_.healthy_hosts_ = host_set_.hosts_; | ||
| host_set_.runCallbacks(add_hosts, {}); | ||
| EXPECT_EQ(host_set_.hosts_[0], lb_->chooseHost(nullptr)); | ||
|
|
||
| // Remove the healthy host and ensure we fail back over to tertiary_host_set_ | ||
| host_set_.healthy_hosts_ = {}; | ||
| host_set_.runCallbacks({}, {}); | ||
| EXPECT_EQ(tertiary_host_set_.hosts_[0], lb_->chooseHost(nullptr)); | ||
| } | ||
|
|
||
| // Test extending the priority set. | ||
| TEST_P(FailoverTest, ExtendPrioritiesUpdatingPrioritySet) { | ||
| host_set_.hosts_ = {makeTestHost(info_, "tcp://127.0.0.1:80")}; | ||
|
|
@@ -829,6 +862,32 @@ TEST_P(RoundRobinLoadBalancerTest, MaxUnhealthyPanic) { | |
| EXPECT_EQ(3UL, stats_.lb_healthy_panic_.value()); | ||
| } | ||
|
|
||
| // Test that no hosts are selected when fail_traffic_on_panic is enabled. | ||
| TEST_P(RoundRobinLoadBalancerTest, MaxUnhealthyPanicDisableOnPanic) { | ||
| hostSet().healthy_hosts_ = {makeTestHost(info_, "tcp://127.0.0.1:80"), | ||
| makeTestHost(info_, "tcp://127.0.0.1:81")}; | ||
| hostSet().hosts_ = { | ||
| makeTestHost(info_, "tcp://127.0.0.1:80"), makeTestHost(info_, "tcp://127.0.0.1:81"), | ||
| makeTestHost(info_, "tcp://127.0.0.1:82"), makeTestHost(info_, "tcp://127.0.0.1:83"), | ||
| makeTestHost(info_, "tcp://127.0.0.1:84"), makeTestHost(info_, "tcp://127.0.0.1:85")}; | ||
|
|
||
| common_config_.mutable_zone_aware_lb_config()->set_fail_traffic_on_panic(true); | ||
|
|
||
| init(false); | ||
| EXPECT_EQ(nullptr, lb_->chooseHost(nullptr)); | ||
|
|
||
| // Take the threshold back above the panic threshold. | ||
| hostSet().healthy_hosts_ = { | ||
| makeTestHost(info_, "tcp://127.0.0.1:80"), makeTestHost(info_, "tcp://127.0.0.1:81"), | ||
| makeTestHost(info_, "tcp://127.0.0.1:82"), makeTestHost(info_, "tcp://127.0.0.1:83")}; | ||
| hostSet().runCallbacks({}, {}); | ||
|
|
||
| EXPECT_EQ(hostSet().healthy_hosts_[0], lb_->chooseHost(nullptr)); | ||
| EXPECT_EQ(hostSet().healthy_hosts_[1], lb_->chooseHost(nullptr)); | ||
|
|
||
| EXPECT_EQ(1UL, stats_.lb_healthy_panic_.value()); | ||
| } | ||
|
|
||
| // Ensure if the panic threshold is 0%, panic mode is disabled. | ||
| TEST_P(RoundRobinLoadBalancerTest, DisablePanicMode) { | ||
| hostSet().healthy_hosts_ = {}; | ||
|
|
@@ -1177,6 +1236,41 @@ TEST_P(RoundRobinLoadBalancerTest, NoZoneAwareRoutingLocalEmpty) { | |
| EXPECT_EQ(1U, stats_.lb_local_cluster_not_ok_.value()); | ||
| } | ||
|
|
||
| TEST_P(RoundRobinLoadBalancerTest, NoZoneAwareRoutingLocalEmptyFailTrafficOnPanic) { | ||
| common_config_.mutable_zone_aware_lb_config()->set_fail_traffic_on_panic(true); | ||
|
|
||
| if (&hostSet() == &failover_host_set_) { // P = 1 does not support zone-aware routing. | ||
| return; | ||
| } | ||
| HostVectorSharedPtr upstream_hosts(new HostVector( | ||
| {makeTestHost(info_, "tcp://127.0.0.1:80"), makeTestHost(info_, "tcp://127.0.0.1:81")})); | ||
| HostVectorSharedPtr local_hosts(new HostVector({}, {})); | ||
|
|
||
| HostsPerLocalitySharedPtr upstream_hosts_per_locality = makeHostsPerLocality( | ||
| {{makeTestHost(info_, "tcp://127.0.0.1:80")}, {makeTestHost(info_, "tcp://127.0.0.1:81")}}); | ||
| HostsPerLocalitySharedPtr local_hosts_per_locality = makeHostsPerLocality({{}, {}}); | ||
|
|
||
| EXPECT_CALL(runtime_.snapshot_, getInteger("upstream.healthy_panic_threshold", 50)) | ||
| .WillOnce(Return(50)) | ||
| .WillOnce(Return(50)); | ||
| EXPECT_CALL(runtime_.snapshot_, featureEnabled("upstream.zone_routing.enabled", 100)) | ||
| .WillOnce(Return(true)); | ||
| EXPECT_CALL(runtime_.snapshot_, getInteger("upstream.zone_routing.min_cluster_size", 6)) | ||
| .WillOnce(Return(1)); | ||
|
|
||
| hostSet().healthy_hosts_ = *upstream_hosts; | ||
| hostSet().hosts_ = *upstream_hosts; | ||
| hostSet().healthy_hosts_per_locality_ = upstream_hosts_per_locality; | ||
| init(true); | ||
| updateHosts(local_hosts, local_hosts_per_locality); | ||
|
|
||
| // Local cluster is not OK, we'll do regular routing (and select no host, since we're in global | ||
| // panic). | ||
| EXPECT_EQ(nullptr, lb_->chooseHost(nullptr)); | ||
| EXPECT_EQ(0U, stats_.lb_healthy_panic_.value()); | ||
| EXPECT_EQ(1U, stats_.lb_local_cluster_not_ok_.value()); | ||
| } | ||
|
|
||
| // Validate that if we have healthy host lists >= 2, but there is no local | ||
| // locality included, that we skip zone aware routing and fallback. | ||
| TEST_P(RoundRobinLoadBalancerTest, NoZoneAwareRoutingNoLocalLocality) { | ||
|
|
@@ -1388,20 +1482,40 @@ INSTANTIATE_TEST_SUITE_P(PrimaryOrFailover, LeastRequestLoadBalancerTest, | |
|
|
||
| class RandomLoadBalancerTest : public LoadBalancerTestBase { | ||
| public: | ||
| RandomLoadBalancer lb_{priority_set_, nullptr, stats_, runtime_, random_, common_config_}; | ||
| void init() { | ||
| lb_.reset( | ||
| new RandomLoadBalancer(priority_set_, nullptr, stats_, runtime_, random_, common_config_)); | ||
| } | ||
| std::shared_ptr<LoadBalancer> lb_; | ||
| }; | ||
|
|
||
| TEST_P(RandomLoadBalancerTest, NoHosts) { EXPECT_EQ(nullptr, lb_.chooseHost(nullptr)); } | ||
| TEST_P(RandomLoadBalancerTest, NoHosts) { | ||
| init(); | ||
| EXPECT_EQ(nullptr, lb_->chooseHost(nullptr)); | ||
| } | ||
|
|
||
| TEST_P(RandomLoadBalancerTest, Normal) { | ||
| init(); | ||
|
|
||
| hostSet().healthy_hosts_ = {makeTestHost(info_, "tcp://127.0.0.1:80"), | ||
| makeTestHost(info_, "tcp://127.0.0.1:81")}; | ||
| hostSet().hosts_ = hostSet().healthy_hosts_; | ||
| hostSet().runCallbacks({}, {}); // Trigger callbacks. The added/removed lists are not relevant. | ||
| EXPECT_CALL(random_, random()).WillOnce(Return(0)).WillOnce(Return(2)); | ||
| EXPECT_EQ(hostSet().healthy_hosts_[0], lb_.chooseHost(nullptr)); | ||
| EXPECT_EQ(hostSet().healthy_hosts_[0], lb_->chooseHost(nullptr)); | ||
| EXPECT_CALL(random_, random()).WillOnce(Return(0)).WillOnce(Return(3)); | ||
| EXPECT_EQ(hostSet().healthy_hosts_[1], lb_.chooseHost(nullptr)); | ||
| EXPECT_EQ(hostSet().healthy_hosts_[1], lb_->chooseHost(nullptr)); | ||
| } | ||
|
|
||
| TEST_P(RandomLoadBalancerTest, FailClusterOnPanic) { | ||
| common_config_.mutable_zone_aware_lb_config()->set_fail_traffic_on_panic(true); | ||
| init(); | ||
|
|
||
| hostSet().healthy_hosts_ = {}; | ||
| hostSet().hosts_ = {makeTestHost(info_, "tcp://127.0.0.1:80"), | ||
| makeTestHost(info_, "tcp://127.0.0.1:81")}; | ||
| hostSet().runCallbacks({}, {}); // Trigger callbacks. The added/removed lists are not relevant. | ||
| EXPECT_EQ(nullptr, lb_->chooseHost(nullptr)); | ||
| } | ||
|
|
||
| INSTANTIATE_TEST_SUITE_P(PrimaryOrFailover, RandomLoadBalancerTest, ::testing::Values(true, false)); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.