diff --git a/bazel/BUILD b/bazel/BUILD index dcaf8989ebfd7..2bb8d27e56d11 100644 --- a/bazel/BUILD +++ b/bazel/BUILD @@ -31,3 +31,8 @@ config_setting( name = "disable_signal_trace", values = {"define": "signal_trace=disabled"}, ) + +config_setting( + name = "disable_hot_restart", + values = {"define": "hot_restart=disabled"}, +) diff --git a/bazel/README.md b/bazel/README.md index 35d1389ef30d9..8f022c856fca9 100644 --- a/bazel/README.md +++ b/bazel/README.md @@ -195,7 +195,6 @@ You can use the `-c ` flag to control this, e.g. bazel build -c opt //source/exe:envoy-static ``` - ## Sanitizers To build and run tests with the gcc compiler's [address sanitizer @@ -230,6 +229,11 @@ remove log statements of lower importance during compilation to enhance performa bazel build --copt=-DNVLOG //source/exe:envoy-static ``` +## Hot Restart + +Hot restart can be disabled in any build by specifying `--define=hot_restart=disabled` +on the Bazel command line. + # Release builds diff --git a/bazel/envoy_build_system.bzl b/bazel/envoy_build_system.bzl index 17586d55edf56..ad1a6423e1fbe 100644 --- a/bazel/envoy_build_system.bzl +++ b/bazel/envoy_build_system.bzl @@ -28,7 +28,7 @@ def envoy_copts(repository, test = False): # TCLAP command line parser needs this to support int64_t/uint64_t "@bazel_tools//tools/osx:darwin": ["-DHAVE_LONG_LONG"], "//conditions:default": [], - }) + }) + envoy_select_hot_restart(["-DENVOY_HOT_RESTART"]) # Compute the final linkopts based on various options. def envoy_linkopts(): @@ -267,7 +267,7 @@ def envoy_sh_test(name, name = name + "_gen_test_runner", srcs = srcs, outs = [test_runner_cc], - cmd = "$(location //bazel:gen_sh_test_runner.sh) $(location " + srcs[0] + ") >> $@", + cmd = "$(location //bazel:gen_sh_test_runner.sh) $(SRCS) >> $@", tools = ["//bazel:gen_sh_test_runner.sh"], ) envoy_cc_test_library( @@ -281,7 +281,7 @@ def envoy_sh_test(name, name = name, srcs = ["//bazel:sh_test_wrapper.sh"], data = srcs + data, - args = ["$(location " + srcs[0] + ")"], + args = srcs, **kargs ) @@ -338,3 +338,11 @@ def envoy_proto_descriptor(name, out, srcs = [], external_deps = []): cmd = cmd, tools = ["//external:protoc"], ) + +# Selects the given values if hot restart is enabled in the current build. +def envoy_select_hot_restart(xs): + return select({ + "//bazel:disable_hot_restart": [], + "@bazel_tools//tools/osx:darwin": [], + "//conditions:default": xs, + }) diff --git a/bazel/sh_test_wrapper.sh b/bazel/sh_test_wrapper.sh index 17b357b308b53..80df983f9207e 100755 --- a/bazel/sh_test_wrapper.sh +++ b/bazel/sh_test_wrapper.sh @@ -3,4 +3,6 @@ # Where the runfiles are for tests. export TEST_RUNDIR="${TEST_SRCDIR}/${TEST_WORKSPACE}" +cd $(dirname "$0") + "$@" diff --git a/source/exe/BUILD b/source/exe/BUILD index d6cc85d41c8b4..cc6a084fb599e 100644 --- a/source/exe/BUILD +++ b/source/exe/BUILD @@ -57,7 +57,7 @@ envoy_cc_library( srcs = ["main.cc"], deps = [ ":envoy_main_common_lib", - ":hot_restart_lib", + "//source/server:hot_restart_lib", "//source/server:options_lib", "//source/server/config/http:lightstep_lib", "//source/server/config/http:zipkin_lib", @@ -73,29 +73,13 @@ envoy_cc_library( hdrs = ["main_common.h"], deps = [ ":envoy_common_lib", - ":hot_restart_lib", "//source/common/common:compiler_requirements_lib", + "//source/server:hot_restart_lib", + "//source/server:hot_restart_nop_lib", "//source/server/config_validation:server_lib", ], ) -envoy_cc_library( - name = "hot_restart_lib", - srcs = ["hot_restart.cc"], - hdrs = ["hot_restart.h"], - deps = [ - "//include/envoy/event:dispatcher_interface", - "//include/envoy/event:file_event_interface", - "//include/envoy/server:hot_restart_interface", - "//include/envoy/server:instance_interface", - "//include/envoy/server:options_interface", - "//source/common/common:assert_lib", - "//source/common/common:utility_lib", - "//source/common/network:utility_lib", - "//source/common/stats:stats_lib", - ], -) - envoy_cc_library( name = "sigaction_lib", srcs = ["signal_action.cc"], diff --git a/source/exe/main.cc b/source/exe/main.cc index 90dc80fc236a5..4b9dc0fa7fc52 100644 --- a/source/exe/main.cc +++ b/source/exe/main.cc @@ -1,13 +1,16 @@ #include #include -#include "exe/hot_restart.h" #include "exe/main_common.h" #ifdef ENVOY_HANDLE_SIGNALS #include "exe/signal_action.h" #endif +#ifdef ENVOY_HOT_RESTART +#include "server/hot_restart_impl.h" +#endif + #include "server/options_impl.h" #include "spdlog/spdlog.h" @@ -19,7 +22,7 @@ * * This should be used to do setup tasks specific to a particular site's * deployment such as initializing signal handling. It calls main_common - * after setting up command line options and the hot restarter. + * after setting up command line options. */ int main(int argc, char** argv) { #ifdef ENVOY_HANDLE_SIGNALS @@ -27,16 +30,14 @@ int main(int argc, char** argv) { Envoy::SignalAction handle_sigs; #endif - Envoy::OptionsImpl options(argc, argv, Envoy::Server::SharedMemory::version(), - spdlog::level::warn); +#ifdef ENVOY_HOT_RESTART + // Enabled by default, except on OS X. Control with "bazel --define=hot_restart=disabled" + const std::string shared_mem_version = Envoy::Server::SharedMemory::version(); +#else + const std::string shared_mem_version = "disabled"; +#endif - std::unique_ptr restarter; - try { - restarter.reset(new Envoy::Server::HotRestartImpl(options)); - } catch (Envoy::EnvoyException& e) { - std::cerr << "unable to initialize hot restart: " << e.what() << std::endl; - return 1; - } + Envoy::OptionsImpl options(argc, argv, shared_mem_version, spdlog::level::warn); - return Envoy::main_common(options, *restarter); + return Envoy::main_common(options); } diff --git a/source/exe/main_common.cc b/source/exe/main_common.cc index 95d5515233e3d..ece0e31f40ffc 100644 --- a/source/exe/main_common.cc +++ b/source/exe/main_common.cc @@ -8,14 +8,17 @@ #include "common/stats/stats_impl.h" #include "common/stats/thread_local_store.h" -#include "exe/hot_restart.h" - #include "server/config_validation/server.h" #include "server/drain_manager_impl.h" +#include "server/hot_restart_nop_impl.h" #include "server/options_impl.h" #include "server/server.h" #include "server/test_hooks.h" +#ifdef ENVOY_HOT_RESTART +#include "server/hot_restart_impl.h" +#endif + #include "ares.h" namespace Envoy { @@ -36,7 +39,27 @@ class ProdComponentFactory : public ComponentFactory { } // namespace Server -int main_common(OptionsImpl& options, Server::HotRestartImpl& restarter) { +int main_common(OptionsImpl& options) { +#ifdef ENVOY_HOT_RESTART + std::unique_ptr restarter; + try { + restarter.reset(new Server::HotRestartImpl(options)); + } catch (Envoy::EnvoyException& e) { + std::cerr << "unable to initialize hot restart: " << e.what() << std::endl; + return 1; + } + + Thread::BasicLockable& log_lock = restarter->logLock(); + Thread::BasicLockable& access_log_lock = restarter->accessLogLock(); + Stats::RawStatDataAllocator& stats_allocator = *restarter; +#else + std::unique_ptr restarter; + restarter.reset(new Server::HotRestartNopImpl()); + + Thread::MutexBasicLockable log_lock, access_log_lock; + Stats::HeapRawStatDataAllocator stats_allocator; +#endif + Event::Libevent::Global::initialize(); Server::ProdComponentFactory component_factory; LocalInfo::LocalInfoImpl local_info( @@ -54,12 +77,12 @@ int main_common(OptionsImpl& options, Server::HotRestartImpl& restarter) { ares_library_init(ARES_LIB_INIT_ALL); - Logger::Registry::initialize(options.logLevel(), restarter.logLock()); + Logger::Registry::initialize(options.logLevel(), log_lock); DefaultTestHooks default_test_hooks; ThreadLocal::InstanceImpl tls; - Stats::ThreadLocalStoreImpl stats_store(restarter); - Server::InstanceImpl server(options, default_test_hooks, restarter, stats_store, - restarter.accessLogLock(), component_factory, local_info, tls); + Stats::ThreadLocalStoreImpl stats_store(stats_allocator); + Server::InstanceImpl server(options, default_test_hooks, *restarter, stats_store, access_log_lock, + component_factory, local_info, tls); server.run(); ares_library_cleanup(); return 0; diff --git a/source/exe/main_common.h b/source/exe/main_common.h index 9b7c27a09275c..89f576ffba6e6 100644 --- a/source/exe/main_common.h +++ b/source/exe/main_common.h @@ -1,7 +1,5 @@ #pragma once -#include "exe/hot_restart.h" - #include "server/options_impl.h" namespace Envoy { @@ -10,9 +8,8 @@ namespace Envoy { * main() runs. * * @param options Options object initialized by site-specific code - * @param restarter HotRestart object initialized in site-specific code. * @return int Return code that should be returned from the actual main() */ -int main_common(Envoy::OptionsImpl& options, Envoy::Server::HotRestartImpl& restarter); +int main_common(Envoy::OptionsImpl& options); } // namespace Envoy diff --git a/source/server/BUILD b/source/server/BUILD index 407ad213db5f1..34e6ebe8e17e9 100644 --- a/source/server/BUILD +++ b/source/server/BUILD @@ -4,6 +4,7 @@ load( "//bazel:envoy_build_system.bzl", "envoy_cc_library", "envoy_package", + "envoy_select_hot_restart", ) envoy_package() @@ -95,6 +96,31 @@ envoy_cc_library( ], ) +envoy_cc_library( + name = "hot_restart_lib", + srcs = envoy_select_hot_restart(["hot_restart_impl.cc"]), + hdrs = envoy_select_hot_restart(["hot_restart_impl.h"]), + deps = [ + "//include/envoy/event:dispatcher_interface", + "//include/envoy/event:file_event_interface", + "//include/envoy/server:hot_restart_interface", + "//include/envoy/server:instance_interface", + "//include/envoy/server:options_interface", + "//source/common/common:assert_lib", + "//source/common/common:utility_lib", + "//source/common/network:utility_lib", + "//source/common/stats:stats_lib", + ], +) + +envoy_cc_library( + name = "hot_restart_nop_lib", + hdrs = ["hot_restart_nop_impl.h"], + deps = [ + "//include/envoy/server:hot_restart_interface", + ], +) + envoy_cc_library( name = "init_manager_lib", srcs = ["init_manager_impl.cc"], diff --git a/source/exe/hot_restart.cc b/source/server/hot_restart_impl.cc similarity index 99% rename from source/exe/hot_restart.cc rename to source/server/hot_restart_impl.cc index 0f8516fd41764..cf0bd601491dd 100644 --- a/source/exe/hot_restart.cc +++ b/source/server/hot_restart_impl.cc @@ -1,4 +1,4 @@ -#include "exe/hot_restart.h" +#include "server/hot_restart_impl.h" #include #include diff --git a/source/exe/hot_restart.h b/source/server/hot_restart_impl.h similarity index 100% rename from source/exe/hot_restart.h rename to source/server/hot_restart_impl.h diff --git a/source/server/hot_restart_nop_impl.h b/source/server/hot_restart_nop_impl.h new file mode 100644 index 0000000000000..bbf479733ab99 --- /dev/null +++ b/source/server/hot_restart_nop_impl.h @@ -0,0 +1,28 @@ +#pragma once + +#include + +#include "envoy/server/hot_restart.h" + +namespace Envoy { +namespace Server { + +/** + * No-op implementation of HotRestart. + */ +class HotRestartNopImpl : public Server::HotRestart { +public: + HotRestartNopImpl(){}; + + void drainParentListeners() override {} + int duplicateParentListenSocket(const std::string&) override { return -1; } + void getParentStats(GetParentStatsInfo& info) override { memset(&info, 0, sizeof(info)); } + void initialize(Event::Dispatcher&, Server::Instance&) override {} + void shutdownParentAdmin(ShutdownParentAdminInfo&) override {} + void terminateParent() override {} + void shutdown() override {} + std::string version() override { return "disabled"; } +}; + +} // namespace Server +} // namespace Envoy diff --git a/test/integration/BUILD b/test/integration/BUILD index 62797beb8e2b6..51de5e5acf94d 100644 --- a/test/integration/BUILD +++ b/test/integration/BUILD @@ -6,13 +6,14 @@ load( "envoy_cc_test_library", "envoy_package", "envoy_sh_test", + "envoy_select_hot_restart", ) envoy_package() envoy_sh_test( name = "hotrestart_test", - srcs = ["hotrestart_test.sh"], + srcs = envoy_select_hot_restart(["hotrestart_test.sh"]), data = [ "//source/exe:envoy-static", "//test/common/runtime:filesystem_setup.sh", @@ -143,6 +144,7 @@ envoy_cc_test_library( "//source/common/upstream:upstream_includes", "//source/common/upstream:upstream_lib", "//source/server:connection_handler_lib", + "//source/server:hot_restart_nop_lib", "//source/server:server_lib", "//source/server:test_hooks_lib", "//source/server/config/http:buffer_lib", diff --git a/test/integration/server.cc b/test/integration/server.cc index 68e7f6862d549..3d19dc7e4a374 100644 --- a/test/integration/server.cc +++ b/test/integration/server.cc @@ -3,13 +3,14 @@ #include #include "envoy/http/header_map.h" -#include "envoy/server/hot_restart.h" #include "common/local_info/local_info_impl.h" #include "common/network/utility.h" #include "common/stats/thread_local_store.h" #include "common/thread_local/thread_local_impl.h" +#include "server/hot_restart_nop_impl.h" + #include "test/integration/integration.h" #include "test/integration/utility.h" #include "test/test_common/environment.h" @@ -17,22 +18,6 @@ #include "gtest/gtest.h" namespace Envoy { -namespace Server { - -class TestHotRestart : public HotRestart { -public: - // Server::HotRestart - void drainParentListeners() override {} - int duplicateParentListenSocket(const std::string&) override { return -1; } - void getParentStats(GetParentStatsInfo& info) override { memset(&info, 0, sizeof(info)); } - void initialize(Event::Dispatcher&, Server::Instance&) override {} - void shutdownParentAdmin(ShutdownParentAdminInfo&) override {} - void terminateParent() override {} - void shutdown() override {} - std::string version() override { return "1"; } -}; - -} // namespace Server IntegrationTestServerPtr IntegrationTestServer::create(const std::string& config_path, const std::string& bootstrap_path, @@ -91,7 +76,7 @@ void IntegrationTestServer::onWorkerListenerRemoved() { void IntegrationTestServer::threadRoutine(const Network::Address::IpVersion version) { Server::TestOptionsImpl options(config_path_, bootstrap_path_); - Server::TestHotRestart restarter; + Server::HotRestartNopImpl restarter; Thread::MutexBasicLockable lock; LocalInfo::LocalInfoImpl local_info(Network::Utility::getLocalAddress(version), "zone_name", "cluster_name", "node_name");