diff --git a/api/envoy/admin/v3/server_info.proto b/api/envoy/admin/v3/server_info.proto index 08fb8dceedd43..108cb8a115487 100644 --- a/api/envoy/admin/v3/server_info.proto +++ b/api/envoy/admin/v3/server_info.proto @@ -58,7 +58,7 @@ message ServerInfo { config.core.v3.Node node = 7; } -// [#next-free-field: 37] +// [#next-free-field: 38] message CommandLineOptions { option (udpa.annotations.versioning).previous_message_type = "envoy.admin.v2alpha.CommandLineOptions"; @@ -189,4 +189,7 @@ message CommandLineOptions { // See :option:`--socket-mode` for details. uint32 socket_mode = 36; + + // See :option:`--enable-core-dump` for details. + bool enable_core_dump = 37; } diff --git a/api/envoy/admin/v4alpha/server_info.proto b/api/envoy/admin/v4alpha/server_info.proto index 9d4db6942f880..18e59c92b0eff 100644 --- a/api/envoy/admin/v4alpha/server_info.proto +++ b/api/envoy/admin/v4alpha/server_info.proto @@ -58,7 +58,7 @@ message ServerInfo { config.core.v4alpha.Node node = 7; } -// [#next-free-field: 37] +// [#next-free-field: 38] message CommandLineOptions { option (udpa.annotations.versioning).previous_message_type = "envoy.admin.v3.CommandLineOptions"; @@ -188,4 +188,7 @@ message CommandLineOptions { // See :option:`--socket-mode` for details. uint32 socket_mode = 36; + + // See :option:`--enable-core-dump` for details. + bool enable_core_dump = 37; } diff --git a/bazel/envoy_build_system.bzl b/bazel/envoy_build_system.bzl index e33386ed5b98b..a9bc9639332c5 100644 --- a/bazel/envoy_build_system.bzl +++ b/bazel/envoy_build_system.bzl @@ -8,7 +8,9 @@ load( _envoy_basic_cc_library = "envoy_basic_cc_library", _envoy_cc_extension = "envoy_cc_extension", _envoy_cc_library = "envoy_cc_library", + _envoy_cc_linux_library = "envoy_cc_linux_library", _envoy_cc_posix_library = "envoy_cc_posix_library", + _envoy_cc_posix_without_linux_library = "envoy_cc_posix_without_linux_library", _envoy_cc_win32_library = "envoy_cc_win32_library", _envoy_include_prefix = "envoy_include_prefix", _envoy_proto_library = "envoy_proto_library", @@ -145,6 +147,16 @@ def envoy_cc_platform_dep(name): "//conditions:default": [name + "_posix"], }) +# Used to select a dependency that has different implementations on Linux vs rest of POSIX vs Windows. +# The platform-specific implementations should be specified with envoy_cc_linux_library, +# envoy_cc_posix_without_library and envoy_cc_win32_library respectively +def envoy_cc_platform_specific_dep(name): + return select({ + "@envoy//bazel:windows_x86_64": [name + "_win32"], + "@envoy//bazel:linux": [name + "_linux"], + "//conditions:default": [name + "_posix"], + }) + # Envoy proto descriptor targets should be specified with this function. # This is used for testing only. def envoy_proto_descriptor(name, out, srcs = [], external_deps = []): @@ -202,7 +214,9 @@ envoy_cc_binary = _envoy_cc_binary envoy_basic_cc_library = _envoy_basic_cc_library envoy_cc_extension = _envoy_cc_extension envoy_cc_library = _envoy_cc_library +envoy_cc_linux_library = _envoy_cc_linux_library envoy_cc_posix_library = _envoy_cc_posix_library +envoy_cc_posix_without_linux_library = _envoy_cc_posix_without_linux_library envoy_cc_win32_library = _envoy_cc_win32_library envoy_include_prefix = _envoy_include_prefix envoy_proto_library = _envoy_proto_library diff --git a/bazel/envoy_library.bzl b/bazel/envoy_library.bzl index 14f2bd5d67779..b48328ac8e3b7 100644 --- a/bazel/envoy_library.bzl +++ b/bazel/envoy_library.bzl @@ -220,6 +220,38 @@ def envoy_cc_posix_library(name, srcs = [], hdrs = [], **kargs): **kargs ) +# Used to specify a library that only builds on POSIX excluding Linux +def envoy_cc_posix_without_linux_library(name, srcs = [], hdrs = [], **kargs): + envoy_cc_library( + name = name + "_posix", + srcs = select({ + "@envoy//bazel:windows_x86_64": [], + "@envoy//bazel:linux": [], + "//conditions:default": srcs, + }), + hdrs = select({ + "@envoy//bazel:windows_x86_64": [], + "@envoy//bazel:linux": [], + "//conditions:default": hdrs, + }), + **kargs + ) + +# Used to specify a library that only builds on Linux +def envoy_cc_linux_library(name, srcs = [], hdrs = [], **kargs): + envoy_cc_library( + name = name + "_linux", + srcs = select({ + "@envoy//bazel:linux": srcs, + "//conditions:default": [], + }), + hdrs = select({ + "@envoy//bazel:linux": hdrs, + "//conditions:default": [], + }), + **kargs + ) + # Used to specify a library that only builds on Windows def envoy_cc_win32_library(name, srcs = [], hdrs = [], **kargs): envoy_cc_library( diff --git a/docs/root/operations/cli.rst b/docs/root/operations/cli.rst index d9961783f496a..8ed5c73e6e512 100644 --- a/docs/root/operations/cli.rst +++ b/docs/root/operations/cli.rst @@ -351,3 +351,10 @@ following are the command line options that Envoy supports. * build mode - either ``RELEASE`` or ``DEBUG``, * TLS library - either ``BoringSSL`` or ``BoringSSL-FIPS``. + +.. option:: --enable-core-dump + + *(optional)* This flag is intended for Linux-based systems and it's a no-op for all other platforms. + It enables core dumps by invoking `prctl `_ using the + PR_SET_DUMPABLE option. This is useful for container environments when using capabilities, given that when + Envoy has more capabilities than its base environment core dumping will be disabled by the kernel. diff --git a/docs/root/version_history/current.rst b/docs/root/version_history/current.rst index 8c1b53e036d4d..d6d550e67c720 100644 --- a/docs/root/version_history/current.rst +++ b/docs/root/version_history/current.rst @@ -125,6 +125,7 @@ New Features * route config: added :ref:`allow_post field ` for allowing POST payload as raw TCP. * route config: added :ref:`max_direct_response_body_size_bytes ` to set maximum :ref:`direct response body ` size in bytes. If not specified the default remains 4096 bytes. * server: added *fips_mode* to :ref:`server compilation settings ` related statistic. +* server: added :option:`--enable-core-dump` flag to enable core dumps via prctl (Linux-based systems only). * tcp_proxy: add support for converting raw TCP streams into HTTP/1.1 CONNECT requests. See :ref:`upgrade documentation ` for details. * tcp_proxy: added a :ref:`use_post field ` for using HTTP POST to proxy TCP streams. * tcp_proxy: added a :ref:`headers_to_add field ` for setting additional headers to the HTTP requests for TCP proxing. diff --git a/generated_api_shadow/envoy/admin/v3/server_info.proto b/generated_api_shadow/envoy/admin/v3/server_info.proto index c7a19453b882e..7257453bc7259 100644 --- a/generated_api_shadow/envoy/admin/v3/server_info.proto +++ b/generated_api_shadow/envoy/admin/v3/server_info.proto @@ -59,7 +59,7 @@ message ServerInfo { config.core.v3.Node node = 7; } -// [#next-free-field: 37] +// [#next-free-field: 38] message CommandLineOptions { option (udpa.annotations.versioning).previous_message_type = "envoy.admin.v2alpha.CommandLineOptions"; @@ -189,6 +189,9 @@ message CommandLineOptions { // See :option:`--socket-mode` for details. uint32 socket_mode = 36; + // See :option:`--enable-core-dump` for details. + bool enable_core_dump = 37; + uint64 hidden_envoy_deprecated_max_stats = 20 [deprecated = true, (envoy.annotations.disallowed_by_default) = true]; diff --git a/generated_api_shadow/envoy/admin/v4alpha/server_info.proto b/generated_api_shadow/envoy/admin/v4alpha/server_info.proto index 9d4db6942f880..18e59c92b0eff 100644 --- a/generated_api_shadow/envoy/admin/v4alpha/server_info.proto +++ b/generated_api_shadow/envoy/admin/v4alpha/server_info.proto @@ -58,7 +58,7 @@ message ServerInfo { config.core.v4alpha.Node node = 7; } -// [#next-free-field: 37] +// [#next-free-field: 38] message CommandLineOptions { option (udpa.annotations.versioning).previous_message_type = "envoy.admin.v3.CommandLineOptions"; @@ -188,4 +188,7 @@ message CommandLineOptions { // See :option:`--socket-mode` for details. uint32 socket_mode = 36; + + // See :option:`--enable-core-dump` for details. + bool enable_core_dump = 37; } diff --git a/include/envoy/server/options.h b/include/envoy/server/options.h index 9b3709af846b7..05729bbe0181d 100644 --- a/include/envoy/server/options.h +++ b/include/envoy/server/options.h @@ -234,6 +234,11 @@ class Options { */ virtual bool mutexTracingEnabled() const PURE; + /** + * @return bool indicating whether core dumps have been enabled. + */ + virtual bool coreDumpEnabled() const PURE; + /** * @return bool indicating whether cpuset size should determine the number of worker threads. */ diff --git a/source/exe/BUILD b/source/exe/BUILD index afae353c9dd75..031609ecb05e5 100644 --- a/source/exe/BUILD +++ b/source/exe/BUILD @@ -2,8 +2,9 @@ load( "//bazel:envoy_build_system.bzl", "envoy_cc_binary", "envoy_cc_library", - "envoy_cc_platform_dep", - "envoy_cc_posix_library", + "envoy_cc_linux_library", + "envoy_cc_platform_specific_dep", + "envoy_cc_posix_without_linux_library", "envoy_cc_win32_library", "envoy_package", ) @@ -142,7 +143,7 @@ envoy_cc_library( envoy_cc_library( name = "platform_impl_lib", deps = [":platform_header_lib"] + - envoy_cc_platform_dep("platform_impl_lib"), + envoy_cc_platform_specific_dep("platform_impl_lib"), ) envoy_cc_library( @@ -154,7 +155,7 @@ envoy_cc_library( ], ) -envoy_cc_posix_library( +envoy_cc_posix_without_linux_library( name = "platform_impl_lib", srcs = ["posix/platform_impl.cc"], deps = [ @@ -164,6 +165,16 @@ envoy_cc_posix_library( ], ) +envoy_cc_linux_library( + name = "platform_impl_lib", + srcs = ["linux/platform_impl.cc"], + deps = [ + ":platform_header_lib", + "//source/common/common:thread_lib", + "//source/common/filesystem:filesystem_lib", + ], +) + envoy_cc_win32_library( name = "platform_impl_lib", srcs = ["win32/platform_impl.cc"], diff --git a/source/exe/linux/platform_impl.cc b/source/exe/linux/platform_impl.cc new file mode 100644 index 0000000000000..60e2ae80914ab --- /dev/null +++ b/source/exe/linux/platform_impl.cc @@ -0,0 +1,22 @@ +#if !defined(__linux__) +#error "Linux platform file is part of non-Linux build." +#endif + +#include + +#include "common/common/thread_impl.h" +#include "common/filesystem/filesystem_impl.h" + +#include "exe/platform_impl.h" + +namespace Envoy { + +PlatformImpl::PlatformImpl() + : thread_factory_(std::make_unique()), + file_system_(std::make_unique()) {} + +PlatformImpl::~PlatformImpl() = default; + +bool PlatformImpl::enableCoreDump() { return prctl(PR_SET_DUMPABLE, 1) != -1; } + +} // namespace Envoy diff --git a/source/exe/main_common.cc b/source/exe/main_common.cc index eebe54bc66fd3..052ab0ecda8ba 100644 --- a/source/exe/main_common.cc +++ b/source/exe/main_common.cc @@ -45,16 +45,25 @@ Runtime::LoaderPtr ProdComponentFactory::createRuntime(Server::Instance& server, MainCommonBase::MainCommonBase(const Server::Options& options, Event::TimeSystem& time_system, ListenerHooks& listener_hooks, Server::ComponentFactory& component_factory, + std::unique_ptr platform_impl, std::unique_ptr&& random_generator, - Thread::ThreadFactory& thread_factory, - Filesystem::Instance& file_system, std::unique_ptr process_context) - : options_(options), component_factory_(component_factory), thread_factory_(thread_factory), - file_system_(file_system), stats_allocator_(symbol_table_) { + : platform_impl_(std::move(platform_impl)), options_(options), + component_factory_(component_factory), stats_allocator_(symbol_table_) { // Process the option to disable extensions as early as possible, // before we do any configuration loading. OptionsImpl::disableExtensions(options.disabledExtensions()); + // Enable core dumps as early as possible. + if (options_.coreDumpEnabled()) { + const auto ret = platform_impl_->enableCoreDump(); + if (ret) { + ENVOY_LOG_MISC(info, "core dump enabled"); + } else { + ENVOY_LOG_MISC(warn, "failed to enable core dump"); + } + } + switch (options_.mode()) { case Server::Mode::InitOnly: case Server::Mode::Serve: { @@ -79,7 +88,7 @@ MainCommonBase::MainCommonBase(const Server::Options& options, Event::TimeSystem server_ = std::make_unique( *init_manager_, options_, time_system, local_address, listener_hooks, *restarter_, *stats_store_, access_log_lock, component_factory, std::move(random_generator), *tls_, - thread_factory_, file_system_, std::move(process_context)); + platform_impl_->threadFactory(), platform_impl_->fileSystem(), std::move(process_context)); break; } @@ -163,8 +172,8 @@ bool MainCommonBase::run() { return true; case Server::Mode::Validate: { auto local_address = Network::Utility::getLocalAddress(options_.localAddressIpVersion()); - return Server::validateConfig(options_, local_address, component_factory_, thread_factory_, - file_system_); + return Server::validateConfig(options_, local_address, component_factory_, + platform_impl_->threadFactory(), platform_impl_->fileSystem()); } case Server::Mode::InitOnly: PERF_DUMP(); @@ -188,14 +197,14 @@ void MainCommonBase::adminRequest(absl::string_view path_and_query, absl::string MainCommon::MainCommon(const std::vector& args) : options_(args, &MainCommon::hotRestartVersion, spdlog::level::info), base_(options_, real_time_system_, default_listener_hooks_, prod_component_factory_, - std::make_unique(), platform_impl_.threadFactory(), - platform_impl_.fileSystem(), nullptr) {} + std::make_unique(), std::make_unique(), + nullptr) {} MainCommon::MainCommon(int argc, const char* const* argv) : options_(argc, argv, &MainCommon::hotRestartVersion, spdlog::level::info), base_(options_, real_time_system_, default_listener_hooks_, prod_component_factory_, - std::make_unique(), platform_impl_.threadFactory(), - platform_impl_.fileSystem(), nullptr) {} + std::make_unique(), std::make_unique(), + nullptr) {} std::string MainCommon::hotRestartVersion(bool hot_restart_enabled) { #ifdef ENVOY_HOT_RESTART diff --git a/source/exe/main_common.h b/source/exe/main_common.h index 3a9dacfc507c9..99a2c14315b3d 100644 --- a/source/exe/main_common.h +++ b/source/exe/main_common.h @@ -38,8 +38,8 @@ class MainCommonBase { // destructed. MainCommonBase(const Server::Options& options, Event::TimeSystem& time_system, ListenerHooks& listener_hooks, Server::ComponentFactory& component_factory, + std::unique_ptr platform_impl, std::unique_ptr&& random_generator, - Thread::ThreadFactory& thread_factory, Filesystem::Instance& file_system, std::unique_ptr process_context); bool run(); @@ -66,6 +66,7 @@ class MainCommonBase { const AdminRequestFn& handler); protected: + std::unique_ptr platform_impl_; ProcessWide process_wide_; // Process-wide state setup/teardown (excluding grpc). // We instantiate this class regardless of ENVOY_GOOGLE_GRPC, to avoid having // an ifdef in a header file exposed in a C++ library. It is too easy to have @@ -73,8 +74,6 @@ class MainCommonBase { Grpc::GoogleGrpcContext google_grpc_context_; const Envoy::Server::Options& options_; Server::ComponentFactory& component_factory_; - Thread::ThreadFactory& thread_factory_; - Filesystem::Instance& file_system_; Stats::SymbolTableImpl symbol_table_; Stats::AllocatorImpl stats_allocator_; @@ -146,7 +145,6 @@ class MainCommon { Envoy::TerminateHandler log_on_terminate_; #endif - PlatformImpl platform_impl_; Envoy::OptionsImpl options_; Event::RealTimeSystem real_time_system_; DefaultListenerHooks default_listener_hooks_; diff --git a/source/exe/platform_impl.h b/source/exe/platform_impl.h index 6e1ec22ce872a..bb7120aed828d 100644 --- a/source/exe/platform_impl.h +++ b/source/exe/platform_impl.h @@ -8,9 +8,10 @@ namespace Envoy { class PlatformImpl { public: PlatformImpl(); - ~PlatformImpl(); + virtual ~PlatformImpl(); Thread::ThreadFactory& threadFactory() { return *thread_factory_; } Filesystem::Instance& fileSystem() { return *file_system_; } + virtual bool enableCoreDump(); private: Thread::ThreadFactoryPtr thread_factory_; diff --git a/source/exe/posix/platform_impl.cc b/source/exe/posix/platform_impl.cc index 8fc227724bee5..730280c4bd960 100644 --- a/source/exe/posix/platform_impl.cc +++ b/source/exe/posix/platform_impl.cc @@ -11,4 +11,6 @@ PlatformImpl::PlatformImpl() PlatformImpl::~PlatformImpl() = default; +bool PlatformImpl::enableCoreDump() { return false; } + } // namespace Envoy diff --git a/source/exe/win32/platform_impl.cc b/source/exe/win32/platform_impl.cc index 52107ae546fe4..4b10bece2bbf2 100644 --- a/source/exe/win32/platform_impl.cc +++ b/source/exe/win32/platform_impl.cc @@ -58,4 +58,6 @@ PlatformImpl::PlatformImpl() PlatformImpl::~PlatformImpl() { ::WSACleanup(); } +bool PlatformImpl::enableCoreDump() { return false; } + } // namespace Envoy diff --git a/source/server/options_impl.cc b/source/server/options_impl.cc index d4623d5a41412..370e460694be9 100644 --- a/source/server/options_impl.cc +++ b/source/server/options_impl.cc @@ -156,6 +156,7 @@ OptionsImpl::OptionsImpl(std::vector args, TCLAP::ValueArg socket_mode("", "socket-mode", "Socket file permission", false, "600", "string", cmd); + TCLAP::SwitchArg enable_core_dump("", "enable-core-dump", "Enable core dumps", cmd, false); cmd.setExceptionHandling(false); try { @@ -177,6 +178,7 @@ OptionsImpl::OptionsImpl(std::vector args, hot_restart_disabled_ = disable_hot_restart.getValue(); mutex_tracing_enabled_ = enable_mutex_tracing.getValue(); + core_dump_enabled_ = enable_core_dump.getValue(); cpuset_threads_ = cpuset_threads.getValue(); diff --git a/source/server/options_impl.h b/source/server/options_impl.h index 85897ac7d8227..370480c755f75 100644 --- a/source/server/options_impl.h +++ b/source/server/options_impl.h @@ -146,6 +146,7 @@ class OptionsImpl : public Server::Options, protected Logger::Loggable disabled_extensions_; uint32_t count_; diff --git a/test/exe/BUILD b/test/exe/BUILD index d6bebbd68edb9..a654dc3392212 100644 --- a/test/exe/BUILD +++ b/test/exe/BUILD @@ -131,3 +131,12 @@ envoy_cc_test( "//test/test_common:environment_lib", ], ) + +envoy_cc_test( + name = "platform_impl_test", + srcs = ["platform_impl_test.cc"], + deps = [ + "//source/exe:platform_impl_lib", + "//test/mocks/runtime:runtime_mocks", + ], +) diff --git a/test/exe/main_common_test.cc b/test/exe/main_common_test.cc index 3505e323b5134..672c05b9282bb 100644 --- a/test/exe/main_common_test.cc +++ b/test/exe/main_common_test.cc @@ -128,10 +128,46 @@ TEST_P(MainCommonTest, ConstructWritesBasePathId) { #endif } +// Exercise enabling core dump and succeeding. +// Note: this test will call the real system call, which is what we want. +TEST_P(MainCommonTest, EnableCoreDump) { +#ifdef __linux__ + addArg("--enable-core-dump"); + auto test = [&]() { MainCommon main_common(argc(), argv()); }; + EXPECT_LOG_CONTAINS("info", "core dump enabled", test()); +#endif +} + +class MockPlatformImpl : public PlatformImpl { +public: + MOCK_METHOD(bool, enableCoreDump, ()); +}; + +// Exercise enabling core dump and failing. +TEST_P(MainCommonTest, EnableCoreDumpFails) { + Event::TestRealTimeSystem real_time_system; + DefaultListenerHooks default_listener_hooks; + ProdComponentFactory prod_component_factory; + + const auto args = std::vector( + {"envoy-static", "--use-dynamic-base-id", "-c", config_file_, "--enable-core-dump"}); + OptionsImpl options(args, &MainCommon::hotRestartVersion, spdlog::level::info); + + auto test = [&]() { + auto* platform_impl = new NiceMock(); + EXPECT_CALL(*platform_impl, enableCoreDump()).WillOnce(Return(false)); + MainCommonBase first(options, real_time_system, default_listener_hooks, prod_component_factory, + std::unique_ptr{platform_impl}, + std::make_unique(), nullptr); + }; + + EXPECT_NO_THROW(test()); + EXPECT_LOG_CONTAINS("warn", "failed to enable core dump", test()); +} + // Test that an in-use base id triggers a retry and that we eventually give up. TEST_P(MainCommonTest, RetryDynamicBaseIdFails) { #ifdef ENVOY_HOT_RESTART - PlatformImpl platform; Event::TestRealTimeSystem real_time_system; DefaultListenerHooks default_listener_hooks; ProdComponentFactory prod_component_factory; @@ -142,8 +178,8 @@ TEST_P(MainCommonTest, RetryDynamicBaseIdFails) { config_file_, "--base-id-path", base_id_path}); OptionsImpl first_options(first_args, &MainCommon::hotRestartVersion, spdlog::level::info); MainCommonBase first(first_options, real_time_system, default_listener_hooks, - prod_component_factory, std::make_unique(), - platform.threadFactory(), platform.fileSystem(), nullptr); + prod_component_factory, std::make_unique(), + std::make_unique(), nullptr); const std::string base_id_str = TestEnvironment::readFileToStringForTest(base_id_path); uint32_t base_id; @@ -156,11 +192,11 @@ TEST_P(MainCommonTest, RetryDynamicBaseIdFails) { std::vector({"envoy-static", "--use-dynamic-base-id", "-c", config_file_}); OptionsImpl second_options(second_args, &MainCommon::hotRestartVersion, spdlog::level::info); - EXPECT_THROW_WITH_MESSAGE( - MainCommonBase(second_options, real_time_system, default_listener_hooks, - prod_component_factory, std::unique_ptr{mock_rng}, - platform.threadFactory(), platform.fileSystem(), nullptr), - EnvoyException, "unable to select a dynamic base id"); + EXPECT_THROW_WITH_MESSAGE(MainCommonBase(second_options, real_time_system, default_listener_hooks, + prod_component_factory, std::make_unique(), + std::unique_ptr{mock_rng}, + nullptr), + EnvoyException, "unable to select a dynamic base id"); #endif } diff --git a/test/exe/platform_impl_test.cc b/test/exe/platform_impl_test.cc new file mode 100644 index 0000000000000..955a55710eb84 --- /dev/null +++ b/test/exe/platform_impl_test.cc @@ -0,0 +1,21 @@ +#include "exe/platform_impl.h" + +#include "test/mocks/common.h" +#include "test/test_common/utility.h" + +#include "gmock/gmock.h" +#include "gtest/gtest.h" + +namespace Envoy { + +TEST(PlatformImpl, Basic) { + PlatformImpl platform; + +#ifdef __linux__ + EXPECT_EQ(true, platform.enableCoreDump()); +#else + EXPECT_EQ(false, platform.enableCoreDump()); +#endif +} + +} // namespace Envoy diff --git a/test/extensions/common/redis/BUILD b/test/extensions/common/redis/BUILD index 96ae92a2a8613..4b54046b37900 100644 --- a/test/extensions/common/redis/BUILD +++ b/test/extensions/common/redis/BUILD @@ -1,6 +1,5 @@ load( "//bazel:envoy_build_system.bzl", - "envoy_cc_platform_dep", "envoy_cc_test_library", "envoy_package", ) @@ -30,6 +29,7 @@ envoy_extension_cc_test( deps = [ "//source/common/common:lock_guard_lib", "//source/common/common:thread_lib", + "//source/exe:platform_impl_lib", "//source/extensions/common/redis:cluster_refresh_manager_lib", "//test/extensions/filters/network/common/redis:redis_mocks", "//test/extensions/filters/network/redis_proxy:redis_mocks", @@ -37,5 +37,5 @@ envoy_extension_cc_test( "//test/mocks/upstream:priority_set_mocks", "//test/test_common:simulated_time_system_lib", "//test/test_common:utility_lib", - ] + envoy_cc_platform_dep("//source/exe:platform_impl_lib"), + ], ) diff --git a/test/mocks/server/options.cc b/test/mocks/server/options.cc index 354628ee65c75..09409e2772c53 100644 --- a/test/mocks/server/options.cc +++ b/test/mocks/server/options.cc @@ -38,6 +38,7 @@ MockOptions::MockOptions(const std::string& config_path) : config_path_(config_p ON_CALL(*this, hotRestartDisabled()).WillByDefault(ReturnPointee(&hot_restart_disabled_)); ON_CALL(*this, signalHandlingEnabled()).WillByDefault(ReturnPointee(&signal_handling_enabled_)); ON_CALL(*this, mutexTracingEnabled()).WillByDefault(ReturnPointee(&mutex_tracing_enabled_)); + ON_CALL(*this, coreDumpEnabled()).WillByDefault(ReturnPointee(&core_dump_enabled_)); ON_CALL(*this, cpusetThreadsEnabled()).WillByDefault(ReturnPointee(&cpuset_threads_enabled_)); ON_CALL(*this, disabledExtensions()).WillByDefault(ReturnRef(disabled_extensions_)); ON_CALL(*this, toCommandLineOptions()).WillByDefault(Invoke([] { diff --git a/test/mocks/server/options.h b/test/mocks/server/options.h index d28fd47b143ae..9bc6e721ea68f 100644 --- a/test/mocks/server/options.h +++ b/test/mocks/server/options.h @@ -47,6 +47,7 @@ class MockOptions : public Options { MOCK_METHOD(bool, hotRestartDisabled, (), (const)); MOCK_METHOD(bool, signalHandlingEnabled, (), (const)); MOCK_METHOD(bool, mutexTracingEnabled, (), (const)); + MOCK_METHOD(bool, coreDumpEnabled, (), (const)); MOCK_METHOD(bool, cpusetThreadsEnabled, (), (const)); MOCK_METHOD(const std::vector&, disabledExtensions, (), (const)); MOCK_METHOD(Server::CommandLineOptionsPtr, toCommandLineOptions, (), (const)); @@ -71,6 +72,7 @@ class MockOptions : public Options { bool hot_restart_disabled_{}; bool signal_handling_enabled_{true}; bool mutex_tracing_enabled_{}; + bool core_dump_enabled_{}; bool cpuset_threads_enabled_{}; std::vector disabled_extensions_; std::string socket_path_; diff --git a/test/server/options_impl_test.cc b/test/server/options_impl_test.cc index 8b5019ee01f3b..9ed6289c323e7 100644 --- a/test/server/options_impl_test.cc +++ b/test/server/options_impl_test.cc @@ -243,6 +243,7 @@ TEST_F(OptionsImplTest, SetAll) { EXPECT_EQ(options->serviceZone(), command_line_options->service_zone()); EXPECT_EQ(options->hotRestartDisabled(), command_line_options->disable_hot_restart()); EXPECT_EQ(options->mutexTracingEnabled(), command_line_options->enable_mutex_tracing()); + EXPECT_EQ(options->coreDumpEnabled(), command_line_options->enable_core_dump()); EXPECT_EQ(options->cpusetThreadsEnabled(), command_line_options->cpuset_threads()); EXPECT_EQ(options->socketPath(), command_line_options->socket_path()); EXPECT_EQ(options->socketMode(), command_line_options->socket_mode()); diff --git a/test/server/server_test.cc b/test/server/server_test.cc index 681bb9cf068e0..142fac58a03fd 100644 --- a/test/server/server_test.cc +++ b/test/server/server_test.cc @@ -1334,6 +1334,13 @@ TEST_P(ServerInstanceImplTest, MutexContentionEnabled) { EXPECT_NO_THROW(initialize("test/server/test_data/server/empty_bootstrap.yaml")); } +TEST_P(ServerInstanceImplTest, CoreDumpEnabled) { + options_.service_cluster_name_ = "some_cluster_name"; + options_.service_node_name_ = "some_node_name"; + options_.core_dump_enabled_ = true; + EXPECT_NO_THROW(initialize("test/server/test_data/server/empty_bootstrap.yaml")); +} + TEST_P(ServerInstanceImplTest, NoHttpTracing) { options_.service_cluster_name_ = "some_cluster_name"; options_.service_node_name_ = "some_node_name"; diff --git a/tools/BUILD b/tools/BUILD index d9dec1be786be..5d1d9bde640da 100644 --- a/tools/BUILD +++ b/tools/BUILD @@ -2,7 +2,6 @@ load("@rules_python//python:defs.bzl", "py_library") load( "//bazel:envoy_build_system.bzl", "envoy_cc_binary", - "envoy_cc_platform_dep", "envoy_package", "envoy_py_test_binary", ) @@ -40,11 +39,12 @@ envoy_cc_binary( deps = [ "//source/common/api:api_lib", "//source/common/common:assert_lib", + "//source/common/common:random_generator_lib", "//source/common/protobuf:message_validator_lib", "//source/common/protobuf:utility_lib", - "//source/common/common:random_generator_lib", "//source/common/stats:isolated_store_lib", + "//source/exe:platform_impl_lib", "//test/test_common:test_version_linkstamp", "@envoy_api//envoy/config/bootstrap/v2:pkg_cc_proto", - ] + envoy_cc_platform_dep("//source/exe:platform_impl_lib"), + ], )