Skip to content

Commit

Permalink
dfp_cluster: use requestStreamInfo() directly (envoyproxy#29539)
Browse files Browse the repository at this point in the history
---------

Signed-off-by: ohadvano <[email protected]>
Signed-off-by: ohadvano <[email protected]>
  • Loading branch information
ohadvano authored Sep 12, 2023
1 parent 5cd9755 commit 5cd9a5d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
4 changes: 4 additions & 0 deletions source/common/tcp_proxy/tcp_proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,10 @@ class Filter : public Network::ReadFilter,
return &read_callbacks_->connection();
}

const StreamInfo::StreamInfo* requestStreamInfo() const override {
return &read_callbacks_->connection().streamInfo();
}

Network::TransportSocketOptionsConstSharedPtr upstreamTransportSocketOptions() const override {
return transport_socket_options_;
}
Expand Down
16 changes: 6 additions & 10 deletions source/extensions/clusters/dynamic_forward_proxy/cluster.cc
Original file line number Diff line number Diff line change
Expand Up @@ -343,12 +343,10 @@ Cluster::LoadBalancer::chooseHost(Upstream::LoadBalancerContext* context) {
}

const Router::StringAccessor* dynamic_host_filter_state = nullptr;
if (context->downstreamConnection()) {
if (context->requestStreamInfo()) {
dynamic_host_filter_state =
context->downstreamConnection()
->streamInfo()
.filterState()
.getDataReadOnly<Router::StringAccessor>(DynamicHostFilterStateKey);
context->requestStreamInfo()->filterState().getDataReadOnly<Router::StringAccessor>(
DynamicHostFilterStateKey);
}

absl::string_view raw_host;
Expand All @@ -370,12 +368,10 @@ Cluster::LoadBalancer::chooseHost(Upstream::LoadBalancerContext* context) {
.resolve(nullptr)
.factory_.implementsSecureTransport();
uint32_t port = is_secure ? 443 : 80;
if (context->downstreamConnection()) {
if (context->requestStreamInfo()) {
const StreamInfo::UInt32Accessor* dynamic_port_filter_state =
context->downstreamConnection()
->streamInfo()
.filterState()
.getDataReadOnly<StreamInfo::UInt32Accessor>(DynamicPortFilterStateKey);
context->requestStreamInfo()->filterState().getDataReadOnly<StreamInfo::UInt32Accessor>(
DynamicPortFilterStateKey);
if (dynamic_port_filter_state != nullptr && dynamic_port_filter_state->value() > 0 &&
dynamic_port_filter_state->value() <= 65535) {
port = dynamic_port_filter_state->value();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class ClusterTest : public testing::Test,

ON_CALL(lb_context_, downstreamHeaders()).WillByDefault(Return(&downstream_headers_));
ON_CALL(connection_, streamInfo()).WillByDefault(ReturnRef(stream_info_));
ON_CALL(lb_context_, requestStreamInfo()).WillByDefault(Return(&stream_info_));
ON_CALL(lb_context_, downstreamConnection()).WillByDefault(Return(&connection_));

member_update_cb_ = cluster_->prioritySet().addMemberUpdateCb(
Expand Down Expand Up @@ -118,8 +119,8 @@ class ClusterTest : public testing::Test,
}

Upstream::MockLoadBalancerContext* setFilterStateHostAndReturnContext(const std::string& host) {
StreamInfo::FilterState& filter_state = const_cast<StreamInfo::FilterState&>(
lb_context_.downstreamConnection()->streamInfo().filterState());
StreamInfo::FilterState& filter_state =
const_cast<StreamInfo::FilterState&>(lb_context_.requestStreamInfo()->filterState());

filter_state.setData(
"envoy.upstream.dynamic_host", std::make_shared<Router::StringAccessorImpl>(host),
Expand Down

0 comments on commit 5cd9a5d

Please sign in to comment.