Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Golang: remove HTTP related elements from the golang network … #28759

Merged
merged 1 commit into from
Aug 1, 2023
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
7 changes: 4 additions & 3 deletions contrib/golang/filters/network/source/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,10 @@ envoy_cc_library(
"//source/common/common:assert_lib",
"//source/common/common:minimal_logger_lib",
"//source/common/common:thread_lib",
"//source/common/http:header_map_lib",
"//source/common/http:headers_lib",
"//source/common/memory:utils_lib",
"//source/common/network:connection_lib",
"//source/common/network:filter_state_dst_address_lib",
"//source/common/network:utility_lib",
"//source/common/stream_info:stream_info_lib",
"//source/common/tcp:conn_pool_lib",
"//source/common/upstream:load_balancer_lib",
"//source/extensions/filters/network/common:factory_base_lib",
Expand Down Expand Up @@ -94,6 +93,8 @@ envoy_cc_contrib_extension(
"//source/common/buffer:buffer_lib",
"//source/common/common:assert_lib",
"//source/common/common:minimal_logger_lib",
"//source/common/http:header_map_lib",
"//source/common/http:headers_lib",
"//source/common/memory:utils_lib",
"//source/common/network:connection_lib",
"//source/common/upstream:load_balancer_lib",
Expand Down
5 changes: 4 additions & 1 deletion contrib/golang/filters/network/source/golang.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "envoy/buffer/buffer.h"
#include "envoy/event/dispatcher.h"
#include "envoy/http/header_map.h"
#include "envoy/network/connection.h"
#include "envoy/network/filter.h"
#include "envoy/ssl/connection.h"
Expand All @@ -10,6 +11,8 @@

#include "source/common/buffer/buffer_impl.h"
#include "source/common/common/logger.h"
#include "source/common/http/header_map_impl.h"
#include "source/common/http/headers.h"
#include "source/common/network/connection_impl.h"
#include "source/common/upstream/load_balancer_impl.h"
#include "source/extensions/filters/network/common/factory_base.h"
Expand All @@ -24,7 +27,7 @@ namespace NetworkFilters {
namespace Golang {

/**
* Configuration for the Golang network filter.
* Configuration for the HTTP golang extension filter.
*/
class FilterConfig {
public:
Expand Down
15 changes: 2 additions & 13 deletions contrib/golang/filters/network/source/upstream.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
#include "envoy/tcp/conn_pool.h"

#include "source/common/common/assert.h"
#include "source/common/network/filter_state_dst_address.h"
#include "source/common/network/utility.h"

namespace Envoy {
namespace Extensions {
Expand All @@ -27,9 +25,6 @@ void UpstreamConn::initThreadLocalStorage(Server::Configuration::FactoryContext&
SlotPtrContainer& slot_ptr_container = slotPtrContainer();
slot_ptr_container.slot_ = tls.allocateSlot();

TimeSourceContainer& time_source_container = timeSourceContainer();
time_source_container.time_source_ = &context.timeSource();

Thread::ThreadId main_thread_id = context.api().threadFactory().currentThreadId();
slot_ptr_container.slot_->set(
[&context, main_thread_id,
Expand Down Expand Up @@ -58,14 +53,8 @@ UpstreamConn::UpstreamConn(std::string addr, Dso::NetworkFilterDsoPtr dynamic_li
ASSERT(!store.dispatchers_.empty());
dispatcher_ = &store.dispatchers_[store.dispatcher_idx_++ % store.dispatchers_.size()].get();
}
stream_info_ = std::make_unique<StreamInfo::StreamInfoImpl>(
*timeSourceContainer().time_source_, nullptr, StreamInfo::FilterState::LifeSpan::FilterChain);
stream_info_->filterState()->setData(
Network::DestinationAddress::key(),
std::make_shared<Network::DestinationAddress>(
Network::Utility::parseInternetAddressAndPort(addr, false)),
StreamInfo::FilterState::StateType::ReadOnly, StreamInfo::FilterState::LifeSpan::FilterChain,
StreamInfo::StreamSharingMayImpactPooling::None);
header_map_ = Http::createHeaderMap<Http::RequestHeaderMapImpl>(
{{Http::Headers::get().EnvoyOriginalDstHost, addr}});
}

void UpstreamConn::connect() {
Expand Down
15 changes: 5 additions & 10 deletions contrib/golang/filters/network/source/upstream.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "envoy/buffer/buffer.h"
#include "envoy/event/dispatcher.h"
#include "envoy/http/header_map.h"
#include "envoy/network/connection.h"
#include "envoy/network/filter.h"
#include "envoy/tcp/conn_pool.h"
Expand All @@ -13,9 +14,10 @@
#include "source/common/buffer/buffer_impl.h"
#include "source/common/common/logger.h"
#include "source/common/common/thread.h"
#include "source/common/http/header_map_impl.h"
#include "source/common/http/headers.h"
#include "source/common/memory/utils.h"
#include "source/common/network/connection_impl.h"
#include "source/common/stream_info/stream_info_impl.h"
#include "source/common/upstream/load_balancer_impl.h"
#include "source/extensions/filters/network/common/factory_base.h"

Expand Down Expand Up @@ -61,7 +63,7 @@ class UpstreamConn : public Tcp::ConnectionPool::Callbacks,
void onEvent(Network::ConnectionEvent event) override;

// Upstream::LoadBalancerContextBase
const StreamInfo::StreamInfo* requestStreamInfo() const override { return stream_info_.get(); }
const Http::RequestHeaderMap* downstreamHeaders() const override { return header_map_.get(); };

void connect();
void write(Buffer::Instance& buf, bool end_stream);
Expand Down Expand Up @@ -94,18 +96,11 @@ class UpstreamConn : public Tcp::ConnectionPool::Callbacks,
MUTABLE_CONSTRUCT_ON_FIRST_USE(ClusterManagerContainer);
}

struct TimeSourceContainer {
TimeSource* time_source_{nullptr};
};
static TimeSourceContainer& timeSourceContainer() {
MUTABLE_CONSTRUCT_ON_FIRST_USE(TimeSourceContainer);
}

Dso::NetworkFilterDsoPtr dynamic_lib_{nullptr};
unsigned long long int goConnID_{0};
UpstreamConnWrapper* wrapper_{nullptr};
Event::Dispatcher* dispatcher_{nullptr};
std::unique_ptr<StreamInfo::StreamInfoImpl> stream_info_{nullptr};
std::unique_ptr<Http::RequestHeaderMapImpl> header_map_{nullptr};
Tcp::ConnectionPool::ConnectionDataPtr conn_{nullptr};
Upstream::HostDescriptionConstSharedPtr host_{nullptr};
Tcp::ConnectionPool::Cancellable* handler_{nullptr};
Expand Down
1 change: 0 additions & 1 deletion contrib/golang/filters/network/test/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ envoy_cc_test(
deps = [
"//contrib/golang/common/dso/test:dso_mocks",
"//contrib/golang/filters/network/source:upstream",
"//source/common/network:filter_state_dst_address_lib",
"//test/mocks/api:api_mocks",
"//test/mocks/network:network_mocks",
"//test/mocks/server:factory_context_mocks",
Expand Down
7 changes: 0 additions & 7 deletions contrib/golang/filters/network/test/upstream_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

#include "envoy/registry/registry.h"

#include "source/common/network/filter_state_dst_address.h"

#include "test/mocks/server/factory_context.h"
#include "test/test_common/environment.h"
#include "test/test_common/utility.h"
Expand Down Expand Up @@ -59,11 +57,6 @@ class UpstreamConnTest : public testing::Test {
TEST_F(UpstreamConnTest, ConnectUpstream) {
initialize();

const auto* dst_addr =
upConn_->requestStreamInfo()->filterState().getDataReadOnly<Network::DestinationAddress>(
Network::DestinationAddress::key());
EXPECT_EQ(dst_addr->address()->asString(), addr_);

EXPECT_CALL(context_.cluster_manager_.thread_local_cluster_.tcp_conn_pool_, newConnection(_))
.WillOnce(
Invoke([&](Tcp::ConnectionPool::Callbacks& cb) -> Tcp::ConnectionPool::Cancellable* {
Expand Down
2 changes: 2 additions & 0 deletions examples/golang-network/envoy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ static_resources:
- name: plainText
type: ORIGINAL_DST
lb_policy: CLUSTER_PROVIDED
original_dst_lb_config:
use_http_header: true