Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion source/common/upstream/cluster_manager_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ void ClusterManagerImpl::postThreadLocalClusterUpdate(const Cluster& cluster, ui
// TODO(htuch): Can we skip these copies by exporting out const shared_ptr from HostSet?
HostVectorConstSharedPtr hosts_copy(new HostVector(host_set->hosts()));
HostVectorConstSharedPtr healthy_hosts_copy(new HostVector(host_set->healthyHosts()));
HostVectorConstSharedPtr degraded_hosts_copy(new HostVector(host_set->healthyHosts()));
HostVectorConstSharedPtr degraded_hosts_copy(new HostVector(host_set->degradedHosts()));
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't find a good place to add a test for this - any ideas?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should be able to add a test in cluster_manager_impl_test that does a sequence of updates and then verifies that the thread local host sets have the hosts they should?

HostsPerLocalityConstSharedPtr hosts_per_locality_copy = host_set->hostsPerLocality().clone();
HostsPerLocalityConstSharedPtr healthy_hosts_per_locality_copy =
host_set->healthyHostsPerLocality().clone();
Expand Down
3 changes: 2 additions & 1 deletion source/common/upstream/health_checker_base_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,9 @@ void HealthCheckerImplBase::ActiveHealthCheckSession::handleSuccess(bool degrade

// This check ensures that we honor the decision made about Changed vs ChangePending in the
// above block.
// TODO(snowp): should there be degraded_threshold?
if (changed_state == HealthTransition::Unchanged) {
changed_state = HealthTransition::ChangePending;
changed_state = HealthTransition::Changed;
}
}

Expand Down
51 changes: 51 additions & 0 deletions test/common/upstream/cluster_manager_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1181,6 +1181,57 @@ TEST_F(ClusterManagerImplTest, addOrUpdateClusterStaticExists) {
EXPECT_TRUE(Mock::VerifyAndClearExpectations(cluster1.get()));
}

// Verifies that we correctly propagate the host_set state to the TLS clusters.
TEST_F(ClusterManagerImplTest, HostsPostedToTlsCluster) {
const std::string json =
fmt::sprintf("{%s}", clustersJson({defaultStaticClusterJson("fake_cluster")}));
std::shared_ptr<MockCluster> cluster1(new NiceMock<MockCluster>());
InSequence s;
EXPECT_CALL(factory_, clusterFromProto_(_, _, _, _, _)).WillOnce(Return(cluster1));
ON_CALL(*cluster1, initializePhase()).WillByDefault(Return(Cluster::InitializePhase::Primary));
EXPECT_CALL(*cluster1, initialize(_));

create(parseBootstrapFromJson(json));

ReadyWatcher initialized;
cluster_manager_->setInitializedCb([&]() -> void { initialized.ready(); });

EXPECT_CALL(initialized, ready());
cluster1->initialize_callback_();

// Set up the HostSet with 1 healthy, 1 degraded and 1 unhealthy.
HostSharedPtr host1 = makeTestHost(cluster1->info_, "tcp://127.0.0.1:80");
host1->healthFlagSet(HostImpl::HealthFlag::DEGRADED_ACTIVE_HC);
HostSharedPtr host2 = makeTestHost(cluster1->info_, "tcp://127.0.0.1:80");
host2->healthFlagSet(HostImpl::HealthFlag::FAILED_ACTIVE_HC);
HostSharedPtr host3 = makeTestHost(cluster1->info_, "tcp://127.0.0.1:80");

HostVector hosts{host1, host2, host3};
auto hosts_ptr = std::make_shared<HostVector>(hosts);

cluster1->priority_set_.host_sets_[0] = std::make_unique<HostSetImpl>(0, absl::nullopt);
cluster1->priority_set_.host_sets_[0]->updateHosts(
HostSetImpl::partitionHosts(hosts_ptr, HostsPerLocalityImpl::empty()), nullptr, hosts, {},
{});

// Trigger a per thread cluster update. Normally this is called whenever the HostSet is modified,
// but since we mock out PrioritySet the callbacks aren't wired up.
cluster1->priority_set_.runUpdateCallbacks(0, hosts, {});

auto* tls_cluster = cluster_manager_->get(cluster1->info_->name());

EXPECT_EQ(1, tls_cluster->prioritySet().hostSetsPerPriority().size());
EXPECT_EQ(1, tls_cluster->prioritySet().hostSetsPerPriority()[0]->degradedHosts().size());
EXPECT_EQ(host1, tls_cluster->prioritySet().hostSetsPerPriority()[0]->degradedHosts()[0]);
EXPECT_EQ(1, tls_cluster->prioritySet().hostSetsPerPriority()[0]->healthyHosts().size());
EXPECT_EQ(host3, tls_cluster->prioritySet().hostSetsPerPriority()[0]->healthyHosts()[0]);
EXPECT_EQ(3, tls_cluster->prioritySet().hostSetsPerPriority()[0]->hosts().size());

factory_.tls_.shutdownThread();

EXPECT_TRUE(Mock::VerifyAndClearExpectations(cluster1.get()));
}

// Test that we close all HTTP connection pool connections when there is a host health failure.
TEST_F(ClusterManagerImplTest, CloseHttpConnectionsOnHealthFailure) {
const std::string json =
Expand Down
2 changes: 1 addition & 1 deletion test/common/upstream/health_checker_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ TEST_F(HttpHealthCheckerImplTest, Success) {

TEST_F(HttpHealthCheckerImplTest, Degraded) {
setupNoServiceValidationHC();
EXPECT_CALL(*this, onHostStatus(_, HealthTransition::ChangePending)).Times(2);
EXPECT_CALL(*this, onHostStatus(_, HealthTransition::Changed)).Times(2);

cluster_->prioritySet().getMockHostSet(0)->hosts_ = {
makeTestHost(cluster_->info_, "tcp://127.0.0.1:80")};
Expand Down