Skip to content

Commit

Permalink
debug output remove later
Browse files Browse the repository at this point in the history
Signed-off-by: Ali Beyad <abeyad@google.com>
  • Loading branch information
abeyad committed Oct 20, 2023
1 parent cbb8015 commit 305b849
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 14 deletions.
20 changes: 13 additions & 7 deletions source/common/upstream/cluster_manager_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ namespace {

void addOptionsIfNotNull(Network::Socket::OptionsSharedPtr& options,
const Network::Socket::OptionsSharedPtr& to_add) {
std::cerr << "==> AAB inside addOptionsIfNotNull, to_add="
<< (to_add.get() == nullptr ? "null" : std::to_string(to_add->size())) << std::endl;
if (to_add != nullptr) {
Network::Socket::appendOptions(options, to_add);
}
Expand Down Expand Up @@ -1976,7 +1978,6 @@ Http::ConnectionPool::Instance*
ClusterManagerImpl::ThreadLocalClusterManagerImpl::ClusterEntry::httpConnPoolImpl(
ResourcePriority priority, absl::optional<Http::Protocol> downstream_protocol,
LoadBalancerContext* context, bool peek) {
std::cerr << "==> AAB httpConnPool" << std::endl;
HostConstSharedPtr host = (peek ? peekAnotherHost(context) : chooseHost(context));
if (!host) {
if (!peek) {
Expand All @@ -1996,7 +1997,7 @@ ClusterManagerImpl::ThreadLocalClusterManagerImpl::ClusterEntry::httpConnPoolImp
for (auto protocol : upstream_protocols) {
hash_key.push_back(uint8_t(protocol));
}
std::cerr << "==> AAB 1 hash_key(" << hash_key.size() << ")=";
std::cerr << "==> AAB 1 hash_key(" << hash_key.size() << "): ";
for (auto x : hash_key)
std::cerr << x << " ";
std::cerr << std::endl;
Expand All @@ -2007,18 +2008,27 @@ ClusterManagerImpl::ThreadLocalClusterManagerImpl::ClusterEntry::httpConnPoolImp
if (context) {
// Inherit socket options from downstream connection, if set.
if (context->downstreamConnection()) {
std::cerr << "==> AAB addOptionsIfNotNull 1" << std::endl;
addOptionsIfNotNull(upstream_options, context->downstreamConnection()->socketOptions());
}
std::cerr << "==> AAB addOptionsIfNotNull 2, upstream_options.size=" << upstream_options->size()
<< std::endl;
addOptionsIfNotNull(upstream_options, context->upstreamSocketOptions());
std::cerr << "==> AAB addOptionsIfNotNull 3, upstream_options.size=" << upstream_options->size()
<< std::endl;
}
std::cerr << "==> AAB 2 hash_key(" << hash_key.size() << "): ";
for (auto x : hash_key)
std::cerr << x << " ";
std::cerr << std::endl;

// Use the socket options for computing connection pool hash key, if any.
// This allows socket options to control connection pooling so that connections with
// different options are not pooled together.
for (const auto& option : *upstream_options) {
option->hashKey(hash_key);
}
std::cerr << "==> AAB 2 hash_key(" << hash_key.size() << ")=";
std::cerr << "==> AAB 3 hash_key(" << hash_key.size() << "): ";
for (auto x : hash_key)
std::cerr << x << " ";
std::cerr << std::endl;
Expand All @@ -2039,10 +2049,6 @@ ClusterManagerImpl::ThreadLocalClusterManagerImpl::ClusterEntry::httpConnPoolImp

// Note: to simplify this, we assume that the factory is only called in the scope of this
// function. Otherwise, we'd need to capture a few of these variables by value.
std::cerr << "==> AAB FINAL hash_key(" << hash_key.size() << ")=";
for (auto x : hash_key)
std::cerr << x << " ";
std::cerr << std::endl;
ConnPoolsContainer::ConnPools::PoolOptRef pool =
container.pools_->getPool(priority, hash_key, [&]() {
auto pool = parent_.parent_.factory_.allocateConnPool(
Expand Down
7 changes: 2 additions & 5 deletions test/common/upstream/cluster_manager_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4537,29 +4537,26 @@ TEST_F(ClusterManagerImplTest, UpstreamSocketOptionsUsedInConnPoolHash) {
Network::Socket::OptionsSharedPtr options2 =
Network::SocketOptionFactory::buildSocketMarkOptions(3);

EXPECT_CALL(context1, upstreamSocketOptions()).WillRepeatedly(Return(options1));
EXPECT_CALL(context2, upstreamSocketOptions()).WillRepeatedly(Return(options2));
// EXPECT_CALL(context1, upstreamSocketOptions()).WillRepeatedly(Return(options1));
// EXPECT_CALL(context2, upstreamSocketOptions()).WillRepeatedly(Return(options2));

createWithBasicStaticCluster();

EXPECT_CALL(context1, upstreamSocketOptions()).WillRepeatedly(Return(options1));
EXPECT_CALL(factory_, allocateConnPool_(_, _, _, _, _)).WillOnce(Return(to_create1));
std::cerr << "==> AAB Test calling httpConnPool 1" << std::endl;
Http::ConnectionPool::Instance* cp1 = HttpPoolDataPeer::getPool(
cluster_manager_->getThreadLocalCluster("cluster_1")
->httpConnPool(ResourcePriority::Default, Http::Protocol::Http11, &context1));
EXPECT_NE(nullptr, cp1);

EXPECT_CALL(context2, upstreamSocketOptions()).WillRepeatedly(Return(options2));
EXPECT_CALL(factory_, allocateConnPool_(_, _, _, _, _)).WillOnce(Return(to_create2));
std::cerr << "==> AAB Test calling httpConnPool 2" << std::endl;
Http::ConnectionPool::Instance* cp2 = HttpPoolDataPeer::getPool(
cluster_manager_->getThreadLocalCluster("cluster_1")
->httpConnPool(ResourcePriority::Default, Http::Protocol::Http11, &context2));
EXPECT_NE(nullptr, cp2);

// The different upstream options should lead to different hashKeys, thus different pools.
std::cerr << "==> AAB Test compare cp1 and cp2" << std::endl;
EXPECT_NE(cp1, cp2);

Http::ConnectionPool::Instance* should_be_cp1 = HttpPoolDataPeer::getPool(
Expand Down
54 changes: 52 additions & 2 deletions test/integration/ads_integration_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -717,8 +717,58 @@ TEST_P(AdsIntegrationTest, CdsKeepEdsAfterWarmingFailure) {
makeSingleRequest();
}

// Validate that
TEST_P(AdsIntegrationTest, AdsStartedAfterAsyncClusterInitialization) {}
TEST_P(AdsIntegrationTest, AdsStartedAfterAsyncClusterInitialization) {
// config_helper_.addConfigModifier([](envoy::config::bootstrap::v3::Bootstrap& bootstrap) {
// // Enable health checking for the first cluster.
// auto* dummy_cluster = bootstrap.mutable_static_resources()->mutable_clusters(0);
// auto* health_check = dummy_cluster->add_health_checks();
// health_check->mutable_timeout()->set_seconds(30);
// health_check->mutable_interval()->CopyFrom(
// Protobuf::util::TimeUtil::MillisecondsToDuration(100));
// health_check->mutable_no_traffic_interval()->CopyFrom(
// Protobuf::util::TimeUtil::MillisecondsToDuration(100));
// health_check->mutable_unhealthy_threshold()->set_value(1);
// health_check->mutable_healthy_threshold()->set_value(1);
// health_check->mutable_http_health_check()->set_path("/healthcheck");
// health_check->mutable_http_health_check()->set_codec_client_type(
// envoy::type::v3::CodecClientType::HTTP2);
// });

// initialize();

// // Make sure statically provisioned runtime values were loaded.
// EXPECT_EQ("whatevs", getRuntimeKey("foo"));
// EXPECT_EQ("yar", getRuntimeKey("bar"));
// EXPECT_EQ("", getRuntimeKey("baz"));

// // Respond to the initial health check, which should complete initialization of primary
// clusters. waitForNextUpstreamRequest();
// upstream_request_->encodeHeaders(Http::TestResponseHeaderMapImpl{{":status", "200"}}, true);
// test_server_->waitForGaugeEq("cluster.dummy_cluster.membership_healthy", 1);

// // After this xDS connection should be established. Verify that dynamic runtime values are
// loaded. acceptXdsConnection();
// EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().Runtime, "", {"some_rtds_layer"},
// {"some_rtds_layer"}, {}, true));
// auto some_rtds_layer = TestUtility::parseYaml<envoy::service::runtime::v3::Runtime>(R"EOF(
// name: some_rtds_layer
// layer:
// foo: bar
// baz: meh
// )EOF");
// sendDiscoveryResponse<envoy::service::runtime::v3::Runtime>(
// Config::TypeUrl::get().Runtime, {some_rtds_layer}, {some_rtds_layer}, {}, "1");
// test_server_->waitForCounterGe("runtime.load_success", initial_load_success_ + 1);

// EXPECT_EQ("bar", getRuntimeKey("foo"));
// EXPECT_EQ("yar", getRuntimeKey("bar"));
// EXPECT_EQ("meh", getRuntimeKey("baz"));

// EXPECT_EQ(0, test_server_->counter("runtime.load_error")->value());
// EXPECT_EQ(initial_load_success_ + 1, test_server_->counter("runtime.load_success")->value());
// EXPECT_EQ(initial_keys_ + 1, test_server_->gauge("runtime.num_keys")->value());
// EXPECT_EQ(3, test_server_->gauge("runtime.num_layers")->value());
}

// Validate that the request with duplicate clusters in the initial request during server init is
// rejected.
Expand Down

0 comments on commit 305b849

Please sign in to comment.