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

envoy: move listener manager code back under source #31129

Merged
merged 6 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 0 additions & 2 deletions .github/workflows/mobile-core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ jobs:
image: ${{ needs.env.outputs.build_image_ubuntu }}
steps:
- uses: actions/checkout@v4
- name: Avoid dependencies leaking back in
run: rm source/extensions/listener_managers/listener_manager/listener_manager_impl.h source/common/quic/http_datagram_handler.h
- name: Add safe directory
run: git config --global --add safe.directory /__w/envoy/envoy
- name: 'Run tests'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/mobile-perf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Ensure files don't leak back into the main binary
run: rm source/extensions/listener_managers/listener_manager/listener_manager_impl.h source/server/overload_manager_impl.cc source/common/network/listen_socket_impl.h source/common/network/tcp_listener_impl.h source/server/guarddog_impl.h source/server/watchdog_impl.h source/server/options_impl.cc
run: rm source/common/listener_manager/listener_manager_impl.h source/server/overload_manager_impl.cc source/common/network/listen_socket_impl.h source/common/network/tcp_listener_impl.h source/server/guarddog_impl.h source/server/watchdog_impl.h source/server/options_impl.cc
- name: Add safe directory
run: git config --global --add safe.directory /__w/envoy/envoy
- name: 'Build test binary'
Expand Down
2 changes: 1 addition & 1 deletion contrib/dlb/source/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ envoy_cc_contrib_extension(
"//envoy/server:factory_context_interface",
"//envoy/server:filter_config_interface",
"//source/common/common:logger_lib",
"//source/common/listener_manager:active_tcp_listener",
"//source/common/network:connection_balancer_lib",
"//source/common/protobuf:utility_lib",
"//source/extensions/listener_managers/listener_manager:active_tcp_listener",
"@envoy_api//contrib/envoy/extensions/network/connection_balance/dlb/v3alpha:pkg_cc_proto",
] + select({
"//bazel:linux_x86_64": [
Expand Down
2 changes: 1 addition & 1 deletion contrib/dlb/source/connection_balancer_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
#include "envoy/server/filter_config.h"

#include "source/common/api/os_sys_calls_impl.h"
#include "source/common/listener_manager/active_tcp_listener.h"
#include "source/common/network/connection_balancer_impl.h"
#include "source/common/protobuf/protobuf.h"
#include "source/extensions/listener_managers/listener_manager/active_tcp_listener.h"

#include "contrib/envoy/extensions/network/connection_balance/dlb/v3alpha/dlb.pb.h"
#include "contrib/envoy/extensions/network/connection_balance/dlb/v3alpha/dlb.pb.validate.h"
Expand Down
2 changes: 1 addition & 1 deletion mobile/test/common/jni/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ cc_library(
deps = [
":server_envoy_jni_lib",
"//library/common/jni:envoy_jni_lib",
"@envoy//source/extensions/listener_managers/listener_manager:listener_manager_lib",
"@envoy//source/common/listener_manager:listener_manager_lib",
],
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
load(
"//bazel:envoy_build_system.bzl",
"envoy_cc_extension",
"envoy_cc_library",
"envoy_extension_package",
"envoy_package",
"envoy_select_enable_http3",
)

licenses(["notice"]) # Apache 2

envoy_extension_package()
envoy_package()

envoy_cc_extension(
envoy_cc_library(
name = "listener_manager_lib",
srcs = [
"listener_impl.cc",
Expand All @@ -20,13 +19,6 @@ envoy_cc_extension(
"listener_impl.h",
"listener_manager_impl.h",
],
# any changes to this should be reviewed by mobile maintainers
# to ensure that listener code doesn't leak back into Envoy Mobile.
extra_visibility = [
"//source/server/admin:__subpackages__",
"//source/server/config_validation:__subpackages__",
"//test:__subpackages__",
],
deps = [
":active_raw_udp_listener_config",
":connection_handler_lib",
Expand Down Expand Up @@ -82,15 +74,13 @@ envoy_cc_extension(
"//source/common/quic:udp_gso_batch_writer_lib",
"//source/extensions/udp_packet_writer/gso:config",
]),
alwayslink = True,
)

envoy_cc_library(
name = "active_raw_udp_listener_config",
srcs = ["active_raw_udp_listener_config.cc"],
hdrs = ["active_raw_udp_listener_config.h"],
visibility = [
"//test:__subpackages__",
],
deps = [
":connection_handler_lib",
"//envoy/registry",
Expand Down Expand Up @@ -155,16 +145,12 @@ envoy_cc_library(
],
)

envoy_cc_extension(
envoy_cc_library(
name = "connection_handler_lib",
srcs = ["connection_handler_impl.cc"],
hdrs = [
"connection_handler_impl.h",
],
# core code.
extra_visibility = [
"//test:__subpackages__",
],
deps = [
"active_tcp_listener",
"//envoy/common:time_interface",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include "source/extensions/listener_managers/listener_manager/active_raw_udp_listener_config.h"
#include "source/common/listener_manager/active_raw_udp_listener_config.h"

#include <memory>
#include <string>

#include "source/extensions/listener_managers/listener_manager/connection_handler_impl.h"
#include "source/common/listener_manager/connection_handler_impl.h"
#include "source/server/active_udp_listener.h"

namespace Envoy {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "source/extensions/listener_managers/listener_manager/active_stream_listener_base.h"
#include "source/common/listener_manager/active_stream_listener_base.h"

#include "envoy/network/filter.h"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

#include "source/common/common/linked_object.h"
#include "source/common/formatter/http_specific_formatter.h"
#include "source/extensions/listener_managers/listener_manager/active_tcp_socket.h"
#include "source/common/listener_manager/active_tcp_socket.h"
#include "source/server/active_listener_base.h"

namespace Envoy {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "source/extensions/listener_managers/listener_manager/active_tcp_listener.h"
#include "source/common/listener_manager/active_tcp_listener.h"

#include <chrono>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
#include "envoy/stream_info/stream_info.h"

#include "source/common/common/linked_object.h"
#include "source/extensions/listener_managers/listener_manager/active_stream_listener_base.h"
#include "source/extensions/listener_managers/listener_manager/active_tcp_socket.h"
#include "source/common/listener_manager/active_stream_listener_base.h"
#include "source/common/listener_manager/active_tcp_socket.h"
#include "source/server/active_listener_base.h"

namespace Envoy {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include "source/extensions/listener_managers/listener_manager/active_tcp_socket.h"
#include "source/common/listener_manager/active_tcp_socket.h"

#include "envoy/network/filter.h"

#include "source/common/listener_manager/active_stream_listener_base.h"
#include "source/common/stream_info/stream_info_impl.h"
#include "source/extensions/listener_managers/listener_manager/active_stream_listener_base.h"

namespace Envoy {
namespace Server {
Expand Down
140 changes: 140 additions & 0 deletions source/common/listener_manager/async_tcp_client_impl.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
#include <cstddef>
#include <memory>
#include <utility>

#include "envoy/event/dispatcher.h"
#include "envoy/network/connection.h"
#include "envoy/tcp/async_tcp_client.h"
#include "envoy/upstream/upstream.h"

#include "source/common/common/assert.h"
#include "source/common/stats/timespan_impl.h"
#include "source/common/tcp/async_tcp_client_impl.h"

namespace Envoy {
namespace Tcp {

AsyncTcpClientImpl::AsyncTcpClientImpl(Event::Dispatcher& dispatcher,
Upstream::ThreadLocalCluster& thread_local_cluster,
Upstream::LoadBalancerContext* context,
bool enable_half_close)
: dispatcher_(dispatcher), thread_local_cluster_(thread_local_cluster),
cluster_info_(thread_local_cluster_.info()), context_(context),
connect_timer_(dispatcher.createTimer([this]() { onConnectTimeout(); })),
enable_half_close_(enable_half_close) {
connect_timer_->enableTimer(cluster_info_->connectTimeout());
cluster_info_->trafficStats()->upstream_cx_active_.inc();
cluster_info_->trafficStats()->upstream_cx_total_.inc();
}

AsyncTcpClientImpl::~AsyncTcpClientImpl() {
cluster_info_->trafficStats()->upstream_cx_active_.dec();
}

bool AsyncTcpClientImpl::connect() {
connection_ = std::move(thread_local_cluster_.tcpConn(context_).connection_);
if (!connection_) {
return false;
}
connection_->enableHalfClose(enable_half_close_);
connection_->addConnectionCallbacks(*this);
connection_->addReadFilter(std::make_shared<NetworkReadFilter>(*this));
conn_connect_ms_ = std::make_unique<Stats::HistogramCompletableTimespanImpl>(
cluster_info_->trafficStats()->upstream_cx_connect_ms_, dispatcher_.timeSource());

connect_timer_->enableTimer(cluster_info_->connectTimeout());
connection_->setConnectionStats({cluster_info_->trafficStats()->upstream_cx_rx_bytes_total_,
cluster_info_->trafficStats()->upstream_cx_rx_bytes_buffered_,
cluster_info_->trafficStats()->upstream_cx_tx_bytes_total_,
cluster_info_->trafficStats()->upstream_cx_tx_bytes_buffered_,
&cluster_info_->trafficStats()->bind_errors_, nullptr});
connection_->noDelay(true);
connection_->connect();
return true;
}

void AsyncTcpClientImpl::onConnectTimeout() {
ENVOY_CONN_LOG(debug, "async tcp connection timed out", *connection_);
cluster_info_->trafficStats()->upstream_cx_connect_timeout_.inc();
close(Network::ConnectionCloseType::NoFlush);
}

void AsyncTcpClientImpl::close(Network::ConnectionCloseType type) {
if (connection_) {
connection_->close(type);
}
}

void AsyncTcpClientImpl::setAsyncTcpClientCallbacks(AsyncTcpClientCallbacks& callbacks) {
callbacks_ = &callbacks;
}

void AsyncTcpClientImpl::write(Buffer::Instance& data, bool end_stream) {
ASSERT(connection_ != nullptr);
connection_->write(data, end_stream);
}

void AsyncTcpClientImpl::onData(Buffer::Instance& data, bool end_stream) {
if (callbacks_) {
callbacks_->onData(data, end_stream);
}
}

void AsyncTcpClientImpl::disableConnectTimeout() {
if (connect_timer_) {
connect_timer_->disableTimer();
connect_timer_.reset();
}
}

void AsyncTcpClientImpl::reportConnectionDestroy(Network::ConnectionEvent event) {
auto& stats = cluster_info_->trafficStats();
stats->upstream_cx_destroy_.inc();
if (event == Network::ConnectionEvent::RemoteClose) {
stats->upstream_cx_destroy_remote_.inc();
} else {
stats->upstream_cx_destroy_local_.inc();
}
}

void AsyncTcpClientImpl::onEvent(Network::ConnectionEvent event) {
if (event == Network::ConnectionEvent::RemoteClose ||
event == Network::ConnectionEvent::LocalClose) {
if (disconnected_) {
cluster_info_->trafficStats()->upstream_cx_connect_fail_.inc();
}

if (!disconnected_ && conn_length_ms_ != nullptr) {
conn_length_ms_->complete();
conn_length_ms_.reset();
}
disableConnectTimeout();
reportConnectionDestroy(event);
disconnected_ = true;
if (connection_) {
detected_close_ = connection_->detectedCloseType();
}

dispatcher_.deferredDelete(std::move(connection_));
if (callbacks_) {
callbacks_->onEvent(event);
callbacks_ = nullptr;
}
} else {
disconnected_ = false;
conn_connect_ms_->complete();
conn_connect_ms_.reset();
disableConnectTimeout();

if (!conn_length_ms_) {
conn_length_ms_ = std::make_unique<Stats::HistogramCompletableTimespanImpl>(
cluster_info_->trafficStats()->upstream_cx_length_ms_, dispatcher_.timeSource());
}
if (callbacks_) {
callbacks_->onEvent(event);
}
}
}

} // namespace Tcp
} // namespace Envoy
Loading
Loading