-
Notifications
You must be signed in to change notification settings - Fork 5.3k
mobile: allow using a light listener manager #24363
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
Changes from all commits
c4a121c
c19cdd7
e140c68
5fa97f2
ade2883
8883326
1edfa42
e4c2057
16664bf
e274ee1
ba6d083
8bed534
b1ba5d5
3e2d82e
eaa6084
663a784
9da477c
72c1c4c
feeb2dc
fca0861
8dc5e5e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,7 @@ envoy_cc_library( | |
| hdrs = ["extension_registry.h"], | ||
| repository = "@envoy", | ||
| deps = [ | ||
| "@envoy//source/extensions/listener_managers/listener_manager:listener_manager_lib", #TODO(2711) remove | ||
| "extension_registry_platform_additions", | ||
| "@envoy//source/common/network:socket_lib", | ||
| "@envoy//source/common/router:upstream_codec_filter_lib", | ||
|
|
@@ -27,7 +28,6 @@ envoy_cc_library( | |
| "@envoy//source/extensions/filters/http/router:config", | ||
| "@envoy//source/extensions/filters/network/http_connection_manager:config", | ||
| "@envoy//source/extensions/http/header_formatters/preserve_case:config", | ||
| "@envoy//source/extensions/listener_managers/listener_manager:listener_manager_lib", | ||
| "@envoy//source/extensions/network/dns_resolver/getaddrinfo:config", | ||
| "@envoy//source/extensions/request_id/uuid:config", | ||
| "@envoy//source/extensions/stat_sinks/metrics_service:config", | ||
|
|
@@ -44,6 +44,7 @@ envoy_cc_library( | |
| "@envoy_mobile//library/common/extensions/filters/http/platform_bridge:config", | ||
| "@envoy_mobile//library/common/extensions/filters/http/route_cache_reset:config", | ||
| "@envoy_mobile//library/common/extensions/filters/http/socket_tag:config", | ||
| "@envoy_mobile//library/common/extensions/listener_managers/api_listener_manager:api_listener_manager_lib", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. similar to my other comment - should we include this dep only if the new compiler/build flag is set?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it depends. if the long term plan is to have a bazel flag to have it optional, we can add it now. if long term we want to say E-M is a client library not a proxy, I'm inclined to not do the busy-work which I'd then have to unwind, and accept the additional include in the interim (we can remove it in-housE)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. actually having thought a bit more I think it is sensible to have a flag but I would like to add it when we flip the default, so have one for "enable TCP listener" where right now we have compile support for "enable API listener" |
||
| "@envoy_mobile//library/common/extensions/retry/options/network_configuration:config", | ||
| ] + envoy_select_enable_http3( | ||
| [ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,6 +37,7 @@ | |
| #include "library/common/extensions/filters/http/network_configuration/config.h" | ||
| #include "library/common/extensions/filters/http/platform_bridge/config.h" | ||
| #include "library/common/extensions/filters/http/route_cache_reset/config.h" | ||
| #include "library/common/extensions/listener_managers/api_listener_manager/api_listener_manager.h" | ||
| #include "library/common/extensions/retry/options/network_configuration/config.h" | ||
|
|
||
| namespace Envoy { | ||
|
|
@@ -81,6 +82,7 @@ void ExtensionRegistry::registerFactories() { | |
| Envoy::Network::forceRegisterGetAddrInfoDnsResolverFactory(); | ||
| Envoy::Extensions::RequestId::forceRegisterUUIDRequestIDExtensionFactory(); | ||
| Envoy::Server::forceRegisterDefaultListenerManagerFactoryImpl(); | ||
| Envoy::Server::forceRegisterApiListenerManagerFactoryImpl(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we force register in here only if
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was going to do that but I think it requires a bazel flag and additional plumbing to be useful given the library include |
||
|
|
||
| #ifdef ENVOY_ENABLE_QUIC | ||
| Quic::forceRegisterQuicServerTransportSocketConfigFactory(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| load( | ||
| "@envoy//bazel:envoy_build_system.bzl", | ||
| "envoy_cc_extension", | ||
| "envoy_extension_package", | ||
| ) | ||
|
|
||
| licenses(["notice"]) # Apache 2 | ||
|
|
||
| envoy_extension_package() | ||
|
|
||
| envoy_cc_extension( | ||
| name = "api_listener_manager_lib", | ||
| srcs = [ | ||
| "api_listener_manager.cc", | ||
| ], | ||
| hdrs = [ | ||
| "api_listener_manager.h", | ||
| ], | ||
| repository = "@envoy", | ||
| deps = [ | ||
| "@envoy//envoy/server:instance_interface", | ||
| "@envoy//envoy/server:listener_manager_interface", | ||
| "@envoy//source/server:api_listener_lib", | ||
| "@envoy//source/server:listener_manager_factory_lib", | ||
| ], | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| #include "library/common/extensions/listener_managers/api_listener_manager/api_listener_manager.h" | ||
|
|
||
| #include "envoy/config/listener/v3/listener.pb.h" | ||
| #include "envoy/network/listener.h" | ||
|
|
||
| #include "source/common/common/assert.h" | ||
| #include "source/common/common/fmt.h" | ||
| #include "source/common/config/utility.h" | ||
| #include "source/server/api_listener_impl.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Server { | ||
|
|
||
| ApiListenerManagerImpl::ApiListenerManagerImpl(Instance& server) : server_(server) {} | ||
| bool ApiListenerManagerImpl::addOrUpdateListener( | ||
| const envoy::config::listener::v3::Listener& config, const std::string&, bool added_via_api) { | ||
| std::string name; | ||
| if (!config.name().empty()) { | ||
| name = config.name(); | ||
| } else { | ||
| // TODO (soulxu): The random uuid name is bad for logging. We can use listening addresses in | ||
| // the log to improve that. | ||
| name = server_.api().randomGenerator().uuid(); | ||
| } | ||
|
|
||
| // TODO(junr03): currently only one ApiListener can be installed via bootstrap to avoid having to | ||
| // build a collection of listeners, and to have to be able to warm and drain the listeners. In the | ||
| // future allow multiple ApiListeners, and allow them to be created via LDS as well as bootstrap. | ||
| if (config.has_api_listener()) { | ||
| if (config.has_internal_listener()) { | ||
| throw EnvoyException(fmt::format( | ||
| "error adding listener named '{}': api_listener and internal_listener cannot be both set", | ||
| name)); | ||
| } | ||
| if (!api_listener_ && !added_via_api) { | ||
| // TODO(junr03): dispatch to different concrete constructors when there are other | ||
| // ApiListenerImplBase derived classes. | ||
| api_listener_ = std::make_unique<HttpApiListener>(config, server_, config.name()); | ||
| return true; | ||
| } else { | ||
| ENVOY_LOG(warn, "listener {} can not be added because currently only one ApiListener is " | ||
| "allowed, and it can only be added via bootstrap configuration"); | ||
| return false; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| REGISTER_FACTORY(ApiListenerManagerFactoryImpl, ListenerManagerFactory); | ||
|
|
||
| } // namespace Server | ||
| } // namespace Envoy |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| #pragma once | ||
|
|
||
| #include <memory> | ||
|
|
||
| #include "envoy/server/instance.h" | ||
| #include "envoy/server/listener_manager.h" | ||
|
|
||
| #include "source/server/listener_manager_factory.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Server { | ||
|
|
||
| /** | ||
| * Implementation of a lightweight ListenerManager for Envoy Mobile. | ||
| * This does not handle downstream TCP / UDP connections but only the API listener. | ||
| */ | ||
| class ApiListenerManagerImpl : public ListenerManager, Logger::Loggable<Logger::Id::config> { | ||
| public: | ||
| explicit ApiListenerManagerImpl(Instance& server); | ||
|
|
||
| // Server::ListenerManager | ||
| bool addOrUpdateListener(const envoy::config::listener::v3::Listener& config, | ||
| const std::string& version_info, bool added_via_api) override; | ||
| void createLdsApi(const envoy::config::core::v3::ConfigSource&, | ||
| const xds::core::v3::ResourceLocator*) override {} | ||
| std::vector<std::reference_wrapper<Network::ListenerConfig>> listeners(ListenerState) override { | ||
| return {}; | ||
| } | ||
| uint64_t numConnections() const override { return 0; } | ||
| bool removeListener(const std::string&) override { return true; } | ||
| void startWorkers(GuardDog&, std::function<void()> callback) override { callback(); } | ||
| void stopListeners(StopListenersType) override {} | ||
| void stopWorkers() override {} | ||
| void beginListenerUpdate() override {} | ||
| void endListenerUpdate(FailureStates&&) override {} | ||
| bool isWorkerStarted() override { return true; } | ||
| Http::Context& httpContext() { return server_.httpContext(); } | ||
| ApiListenerOptRef apiListener() override { | ||
| return api_listener_ ? ApiListenerOptRef(std::ref(*api_listener_)) : absl::nullopt; | ||
| } | ||
|
|
||
| private: | ||
| Instance& server_; | ||
| ApiListenerPtr api_listener_; | ||
| }; | ||
|
|
||
| class ApiListenerManagerFactoryImpl : public ListenerManagerFactory { | ||
| public: | ||
| std::unique_ptr<ListenerManager> | ||
| createListenerManager(Instance& server, std::unique_ptr<ListenerComponentFactory>&&, | ||
| WorkerFactory&, bool, Quic::QuicStatNames&) override { | ||
| return std::make_unique<ApiListenerManagerImpl>(server); | ||
| } | ||
| std::string name() const override { return "envoy.listener_manager_impl.api"; } | ||
| }; | ||
|
|
||
| DECLARE_FACTORY(ApiListenerManagerFactoryImpl); | ||
|
|
||
| } // namespace Server | ||
| } // namespace Envoy |
Uh oh!
There was an error while loading. Please reload this page.