Skip to content

Commit

Permalink
increase life span for data in tcp cluster rewrite (envoyproxy#2774)
Browse files Browse the repository at this point in the history
* increase life span for data in tcp cluster rewrite

* fix tests

* test

* typo
  • Loading branch information
yxue authored Mar 19, 2020
1 parent 4452d78 commit e8adf2a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ user.bazelrc
compile_commands.json
test/envoye2e/tcp_metadata_exchange/testoutput
test/envoye2e/http_metadata_exchange/testoutput
*.wasm
*.wasm
.vscode
23 changes: 18 additions & 5 deletions src/envoy/tcp/tcp_cluster_rewrite/tcp_cluster_rewrite.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,25 @@ Network::FilterStatus TcpClusterRewriteFilter::onNewConnection() {
"tcp_cluster_rewrite: final tcp proxy cluster name {}",
read_callbacks_->connection(), final_cluster_name);

// The data is mutable to allow other filters to change it.
read_callbacks_->connection().streamInfo().filterState()->setData(
TcpProxy::PerConnectionCluster::key(),
std::make_unique<TcpProxy::PerConnectionCluster>(final_cluster_name),
StreamInfo::FilterState::StateType::Mutable);
try {
// The data is mutable to allow other filters to change it.
read_callbacks_->connection().streamInfo().filterState()->setData(
TcpProxy::PerConnectionCluster::key(),
std::make_unique<TcpProxy::PerConnectionCluster>(final_cluster_name),
StreamInfo::FilterState::StateType::Mutable,
StreamInfo::FilterState::LifeSpan::DownstreamConnection);
} catch (const EnvoyException& e) {
ENVOY_CONN_LOG(critical, "tcp_cluster_rewrite: error setting data: {}",
read_callbacks_->connection(), e.what());
throw;
} catch (...) {
ENVOY_LOG(
critical,
"tcp_cluster_rewrite: error setting data due to unknown exception");
throw;
}
}

return Network::FilterStatus::Continue;
}

Expand Down
9 changes: 6 additions & 3 deletions src/envoy/tcp/tcp_cluster_rewrite/tcp_cluster_rewrite_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ TEST_F(TcpClusterRewriteFilterTest, ClusterRewrite) {
TcpProxy::PerConnectionCluster::key(),
std::make_unique<TcpProxy::PerConnectionCluster>(
"hello.ns1.svc.cluster.local"),
StreamInfo::FilterState::StateType::Mutable);
StreamInfo::FilterState::StateType::Mutable,
StreamInfo::FilterState::LifeSpan::DownstreamConnection);
filter_->onNewConnection();

EXPECT_TRUE(
Expand All @@ -87,7 +88,8 @@ TEST_F(TcpClusterRewriteFilterTest, ClusterRewrite) {
stream_info_.filterState()->setData(
TcpProxy::PerConnectionCluster::key(),
std::make_unique<TcpProxy::PerConnectionCluster>("hello.ns1.global"),
StreamInfo::FilterState::StateType::Mutable);
StreamInfo::FilterState::StateType::Mutable,
StreamInfo::FilterState::LifeSpan::DownstreamConnection);
filter_->onNewConnection();

EXPECT_TRUE(
Expand All @@ -111,7 +113,8 @@ TEST_F(TcpClusterRewriteFilterTest, ClusterRewrite) {
stream_info_.filterState()->setData(
TcpProxy::PerConnectionCluster::key(),
std::make_unique<TcpProxy::PerConnectionCluster>("hello.ns1.global"),
StreamInfo::FilterState::StateType::Mutable);
StreamInfo::FilterState::StateType::Mutable,
StreamInfo::FilterState::LifeSpan::DownstreamConnection);
filter_->onNewConnection();

EXPECT_TRUE(
Expand Down

0 comments on commit e8adf2a

Please sign in to comment.