Skip to content

Commit

Permalink
server: breaking into base and impl class (envoyproxy#30693)
Browse files Browse the repository at this point in the history
Also moving out the heap checker for E-M as an example of why we want to do this

Risk Level: low
Testing: n/a
Docs Changes: n/a
Release Notes: n/a

Signed-off-by: Alyssa Wilk <[email protected]>
  • Loading branch information
alyssawilk authored Nov 7, 2023
1 parent a33cde6 commit a9d8eb3
Show file tree
Hide file tree
Showing 11 changed files with 101 additions and 52 deletions.
9 changes: 7 additions & 2 deletions mobile/library/common/engine_common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ void registerMobileProtoDescriptors() {

namespace Envoy {

class ServerLite : public Server::InstanceBase {
public:
using Server::InstanceBase::InstanceBase;
void maybeCreateHeapShrinker() override {}
};

EngineCommon::EngineCommon(std::unique_ptr<Envoy::OptionsImpl>&& options)
: options_(std::move(options)) {

Expand All @@ -69,9 +75,8 @@ EngineCommon::EngineCommon(std::unique_ptr<Envoy::OptionsImpl>&& options)
ThreadLocal::Instance& tls, Thread::ThreadFactory& thread_factory,
Filesystem::Instance& file_system, std::unique_ptr<ProcessContext> process_context,
Buffer::WatermarkFactorySharedPtr watermark_factory) {
// TODO(alyssawilk) use InstanceLite not InstanceImpl.
auto local_address = Network::Utility::getLocalAddress(options.localAddressIpVersion());
auto server = std::make_unique<Server::InstanceImpl>(
auto server = std::make_unique<ServerLite>(
init_manager, options, time_system, hooks, restarter, store, access_log_lock,
std::move(random_generator), tls, thread_factory, file_system,
std::move(process_context), watermark_factory);
Expand Down
5 changes: 3 additions & 2 deletions source/exe/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ envoy_cc_library(
"//source/server:drain_manager_lib",
"//source/server:listener_hooks_lib",
"//source/server:options_lib",
"//source/server:server_lib",
"//source/server:server_base_lib",
] + select({
"//bazel:windows_x86_64": envoy_all_extensions(WINDOWS_SKIP_TARGETS),
"//bazel:linux_ppc": envoy_all_extensions(PPC_SKIP_TARGETS),
Expand Down Expand Up @@ -144,7 +144,7 @@ envoy_cc_library(
"//source/server:drain_manager_lib",
"//source/server:listener_hooks_lib",
"//source/server:options_lib",
"//source/server:server_lib",
"//source/server:server_base_lib",
] + envoy_all_core_extensions() +
# TODO(rojkov): drop io_uring dependency when it's fully integrated.
select({
Expand Down Expand Up @@ -175,6 +175,7 @@ envoy_cc_library(
"//source/extensions/listener_managers/validation_listener_manager:validation_listener_manager_lib",
"//source/server:hot_restart_lib",
"//source/server:hot_restart_nop_lib",
"//source/server:server_lib",
"//source/server/config_validation:server_lib",
] + envoy_select_signal_trace([
"//source/common/signal:sigaction_lib",
Expand Down
2 changes: 1 addition & 1 deletion source/exe/main_common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
#include "source/server/config_validation/server.h"
#include "source/server/drain_manager_impl.h"
#include "source/server/hot_restart_nop_impl.h"
#include "source/server/instance_impl.h"
#include "source/server/listener_hooks.h"
#include "source/server/options_impl.h"
#include "source/server/server.h"

#include "absl/debugging/symbolize.h"
#include "absl/strings/str_split.h"
Expand Down
13 changes: 11 additions & 2 deletions source/server/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ envoy_cc_library(
)

envoy_cc_library(
name = "server_lib",
name = "server_base_lib",
srcs = ["server.cc"],
hdrs = ["server.h"],
external_deps = [
Expand Down Expand Up @@ -424,7 +424,6 @@ envoy_cc_library(
"//source/common/http:headers_lib",
"//source/common/init:manager_lib",
"//source/common/local_info:local_info_lib",
"//source/common/memory:heap_shrinker_lib",
"//source/common/memory:stats_lib",
"//source/common/protobuf:utility_lib",
"//source/common/quic:quic_stat_names_lib",
Expand All @@ -444,6 +443,16 @@ envoy_cc_library(
],
)

envoy_cc_library(
name = "server_lib",
srcs = ["instance_impl.cc"],
hdrs = ["instance_impl.h"],
deps = [
":server_base_lib",
"//source/common/memory:heap_shrinker_lib",
],
)

envoy_cc_library(
name = "ssl_context_manager_lib",
srcs = ["ssl_context_manager.cc"],
Expand Down
11 changes: 11 additions & 0 deletions source/server/instance_impl.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include "source/server/instance_impl.h"

namespace Envoy {
namespace Server {
void InstanceImpl::maybeCreateHeapShrinker() {
heap_shrinker_ =
std::make_unique<Memory::HeapShrinker>(dispatcher(), overloadManager(), *stats().rootScope());
}

} // namespace Server
} // namespace Envoy
22 changes: 22 additions & 0 deletions source/server/instance_impl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#pragma once

#include "source/common/memory/heap_shrinker.h"
#include "source/server/server.h"

namespace Envoy {
namespace Server {

// The production server instance, which creates all of the required components.
class InstanceImpl : public InstanceBase {
public:
using InstanceBase::InstanceBase;

protected:
void maybeCreateHeapShrinker() override;

private:
std::unique_ptr<Memory::HeapShrinker> heap_shrinker_;
};

} // namespace Server
} // namespace Envoy
Loading

0 comments on commit a9d8eb3

Please sign in to comment.