Skip to content

Commit

Permalink
upstream: set host on stream info for upstream filters
Browse files Browse the repository at this point in the history
Change-Id: Ia868bb4d9cbf78de23bc43b6a162edcc065aa762
Signed-off-by: Kuat Yessenov <[email protected]>
  • Loading branch information
kyessenov committed May 23, 2024
1 parent 580f37c commit a06e534
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions source/common/upstream/upstream_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,7 @@ Host::CreateConnectionData HostImplBase::createConnection(
cluster.setLocalInterfaceNameOnUpstreamConnections());
connection->setBufferLimits(cluster.perConnectionBufferLimitBytes());
cluster.createNetworkFilterChain(*connection);
connection->streamInfo().upstreamInfo()->setUpstreamHost(host);
return {std::move(connection), std::move(host)};
}

Expand Down
2 changes: 1 addition & 1 deletion test/common/tcp/conn_pool_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ class TcpConnPoolImplDestructorTest : public Event::TestUsingSimulatedTime, publ
EXPECT_CALL(*connection_, connect());
EXPECT_CALL(*connection_, setConnectionStats(_));
EXPECT_CALL(*connection_, noDelay(true));
EXPECT_CALL(*connection_, streamInfo());
EXPECT_CALL(*connection_, streamInfo()).Times(AnyNumber());
EXPECT_CALL(*connection_, id()).Times(AnyNumber());
EXPECT_CALL(*connection_, readDisable(_)).Times(AnyNumber());
EXPECT_CALL(*connection_, initializeReadFilters());
Expand Down
10 changes: 10 additions & 0 deletions test/common/upstream/upstream_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1624,9 +1624,11 @@ TEST_F(HostImplTest, CreateConnection) {
EXPECT_CALL(*connection, setBufferLimits(0));
EXPECT_CALL(dispatcher, createClientConnection_(_, _, _, _)).WillOnce(Return(connection));
EXPECT_CALL(*connection, connectionInfoSetter());
EXPECT_CALL(*connection, streamInfo());
Envoy::Upstream::Host::CreateConnectionData connection_data =
host->createConnection(dispatcher, options, transport_socket_options);
EXPECT_EQ(connection, connection_data.connection_.get());
EXPECT_EQ(host, connection->stream_info_.upstreamInfo()->upstreamHost());
}

TEST_F(HostImplTest, CreateConnectionHappyEyeballs) {
Expand Down Expand Up @@ -1664,11 +1666,13 @@ TEST_F(HostImplTest, CreateConnectionHappyEyeballs) {
EXPECT_CALL(dispatcher, createClientConnection_(address_list[0], _, _, _))
.WillOnce(Return(connection));
EXPECT_CALL(dispatcher, createTimer_(_));
EXPECT_CALL(*connection, streamInfo());

Envoy::Upstream::Host::CreateConnectionData connection_data =
host->createConnection(dispatcher, options, transport_socket_options);
// The created connection will be wrapped in a HappyEyeballsConnectionImpl.
EXPECT_NE(connection, connection_data.connection_.get());
EXPECT_EQ(host, connection->stream_info_.upstreamInfo()->upstreamHost());
}

TEST_F(HostImplTest, ProxyOverridesHappyEyeballs) {
Expand Down Expand Up @@ -1712,12 +1716,14 @@ TEST_F(HostImplTest, ProxyOverridesHappyEyeballs) {
// The underlying connection should be created to the proxy address.
EXPECT_CALL(dispatcher, createClientConnection_(proxy_address, _, _, _))
.WillOnce(Return(connection));
EXPECT_CALL(*connection, streamInfo());

Envoy::Upstream::Host::CreateConnectionData connection_data =
host->createConnection(dispatcher, options, transport_socket_options);
// The created connection will be a raw connection to the proxy address rather
// than a happy eyeballs connection.
EXPECT_EQ(connection, connection_data.connection_.get());
EXPECT_EQ(host, connection->stream_info_.upstreamInfo()->upstreamHost());
}

TEST_F(HostImplTest, CreateConnectionHappyEyeballsWithConfig) {
Expand Down Expand Up @@ -1768,11 +1774,13 @@ TEST_F(HostImplTest, CreateConnectionHappyEyeballsWithConfig) {
EXPECT_CALL(dispatcher, createClientConnection_(address_list[1], _, _, _))
.WillOnce(Return(connection));
EXPECT_CALL(dispatcher, createTimer_(_));
EXPECT_CALL(*connection, streamInfo());

Envoy::Upstream::Host::CreateConnectionData connection_data =
host->createConnection(dispatcher, options, transport_socket_options);
// The created connection will be wrapped in a HappyEyeballsConnectionImpl.
EXPECT_NE(connection, connection_data.connection_.get());
EXPECT_EQ(host, connection->stream_info_.upstreamInfo()->upstreamHost());
}

TEST_F(HostImplTest, CreateConnectionHappyEyeballsWithEmptyConfig) {
Expand Down Expand Up @@ -1820,11 +1828,13 @@ TEST_F(HostImplTest, CreateConnectionHappyEyeballsWithEmptyConfig) {
EXPECT_CALL(dispatcher, createClientConnection_(address_list[0], _, _, _))
.WillOnce(Return(connection));
EXPECT_CALL(dispatcher, createTimer_(_));
EXPECT_CALL(*connection, streamInfo());

Envoy::Upstream::Host::CreateConnectionData connection_data =
host->createConnection(dispatcher, options, transport_socket_options);
// The created connection will be wrapped in a HappyEyeballsConnectionImpl.
EXPECT_NE(connection, connection_data.connection_.get());
EXPECT_EQ(host, connection->stream_info_.upstreamInfo()->upstreamHost());
}

TEST_F(HostImplTest, HealthFlags) {
Expand Down
1 change: 1 addition & 0 deletions test/extensions/clusters/eds/eds_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,7 @@ TEST_F(EdsTest, DualStackEndpoint) {
EXPECT_CALL(dispatcher, createClientConnection_(hosts[0]->address(), _, _, _))
.WillOnce(Return(connection));
EXPECT_CALL(dispatcher, createTimer_(_));
EXPECT_CALL(*connection, streamInfo());

Envoy::Upstream::Host::CreateConnectionData connection_data =
hosts[0]->createConnection(dispatcher, options, transport_socket_options);
Expand Down

0 comments on commit a06e534

Please sign in to comment.