Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
9d8c32d
server: add --enable-core-dump flag
Mar 1, 2021
82e1ceb
Fix docs
Mar 1, 2021
906aaa5
Fix windows
Mar 1, 2021
1b85c69
Skip prctl for OS X too
Mar 1, 2021
57e810f
Check prctl's return value and log accordingly
Mar 1, 2021
09d58c0
Move code to platform specific files
Mar 2, 2021
aa46afc
Fix bazel helpers
Mar 2, 2021
193bae6
Fix selectors
Mar 2, 2021
2896729
Update envoy_cc_posix_without_linux_library
Mar 2, 2021
7c831e3
Fix CI
Mar 2, 2021
d120e3e
Info log when prctl succeeds
Mar 2, 2021
fd4f178
Fix format
Mar 2, 2021
61a490c
Improve changelog
Mar 2, 2021
9474964
Merge remote-tracking branch 'upstream/main' into prctl-set-dumpable
Mar 2, 2021
5373bd2
Merge remote-tracking branch 'upstream/main' into prctl-set-dumpable
Mar 3, 2021
2276fce
Add test for enableCoreDump()
Mar 3, 2021
803bb02
Merge remote-tracking branch 'upstream/main' into prctl-set-dumpable
Mar 3, 2021
e628490
Add test to exercise --enable-core-dump
Mar 3, 2021
224f5ff
Reduce branching to avoid coverage issues
Mar 3, 2021
ee968ed
Decouple logging call from enabling call
Mar 3, 2021
7aa249b
Merge remote-tracking branch 'upstream/main' into prctl-set-dumpable
Mar 3, 2021
ff2e246
Link to cmdline flag
Mar 4, 2021
b3b5b27
Merge remote-tracking branch 'upstream/main' into prctl-set-dumpable
Mar 4, 2021
1e31170
Merge remote-tracking branch 'upstream/main' into prctl-set-dumpable
Mar 4, 2021
1905d17
Merge remote-tracking branch 'upstream/main' into prctl-set-dumpable
Mar 4, 2021
9c5ae2e
Split info vs warn depending on enableCoreDump()'s return
Mar 4, 2021
129d19c
Fix logging
Mar 4, 2021
7330093
Test enableCoreDump() fails path
Mar 4, 2021
d0532e2
unique_ptr
Mar 4, 2021
4f89e2e
Merge remote-tracking branch 'upstream/main' into prctl-set-dumpable
Mar 4, 2021
641e72b
Improve test
Mar 4, 2021
e6abf4b
Fixes
Mar 4, 2021
bdefe7a
Fix format
Mar 4, 2021
042277e
Merge remote-tracking branch 'upstream/main' into prctl-set-dumpable
Mar 5, 2021
e9128dd
Drop the per architecture match, since it's not needed
Mar 5, 2021
21da012
Fix format
Mar 5, 2021
ef02146
Merge remote-tracking branch 'upstream/main' into prctl-set-dumpable
Mar 5, 2021
583bf9e
Fix
Mar 5, 2021
938e4dd
Fix test
Mar 5, 2021
db5045c
Merge remote-tracking branch 'upstream/main' into prctl-set-dumpable
Mar 5, 2021
fcb514c
prctl() will only work on Linux, so use an ifdef
Mar 5, 2021
37f19aa
Be more consistent in the use of ifdefs
Mar 5, 2021
b0026f4
Fix clang tidy
Mar 5, 2021
0790c5e
Use a proper mock method
Mar 5, 2021
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
5 changes: 4 additions & 1 deletion api/envoy/admin/v3/server_info.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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;
}
5 changes: 4 additions & 1 deletion api/envoy/admin/v4alpha/server_info.proto

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions bazel/envoy_build_system.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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 = []):
Expand Down Expand Up @@ -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
Expand Down
32 changes: 32 additions & 0 deletions bazel/envoy_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
7 changes: 7 additions & 0 deletions docs/root/operations/cli.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://man7.org/linux/man-pages/man2/prctl.2.html>`_ 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.
1 change: 1 addition & 0 deletions docs/root/version_history/current.rst
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ New Features
* route config: added :ref:`allow_post field <envoy_v3_api_field_config.route.v3.RouteAction.UpgradeConfig.ConnectConfig.allow_post>` for allowing POST payload as raw TCP.
* route config: added :ref:`max_direct_response_body_size_bytes <envoy_v3_api_field_config.route.v3.RouteConfiguration.max_direct_response_body_size_bytes>` to set maximum :ref:`direct response body <envoy_v3_api_field_config.route.v3.DirectResponseAction.body>` size in bytes. If not specified the default remains 4096 bytes.
* server: added *fips_mode* to :ref:`server compilation settings <server_compilation_settings_statistics>` 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 <tunneling-tcp-over-http>` for details.
* tcp_proxy: added a :ref:`use_post field <envoy_v3_api_field_extensions.filters.network.tcp_proxy.v3.TcpProxy.TunnelingConfig.use_post>` for using HTTP POST to proxy TCP streams.
* tcp_proxy: added a :ref:`headers_to_add field <envoy_v3_api_field_extensions.filters.network.tcp_proxy.v3.TcpProxy.TunnelingConfig.headers_to_add>` for setting additional headers to the HTTP requests for TCP proxing.
Expand Down
5 changes: 4 additions & 1 deletion generated_api_shadow/envoy/admin/v3/server_info.proto

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion generated_api_shadow/envoy/admin/v4alpha/server_info.proto

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions include/envoy/server/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
19 changes: 15 additions & 4 deletions source/exe/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
Expand Down Expand Up @@ -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(
Expand All @@ -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 = [
Expand All @@ -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"],
Expand Down
22 changes: 22 additions & 0 deletions source/exe/linux/platform_impl.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#if !defined(__linux__)
#error "Linux platform file is part of non-Linux build."
#endif

#include <sys/prctl.h>

#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<Thread::ThreadFactoryImplPosix>()),
file_system_(std::make_unique<Filesystem::InstanceImplPosix>()) {}

PlatformImpl::~PlatformImpl() = default;

bool PlatformImpl::enableCoreDump() { return prctl(PR_SET_DUMPABLE, 1) != -1; }

} // namespace Envoy
31 changes: 20 additions & 11 deletions source/exe/main_common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<PlatformImpl> platform_impl,
std::unique_ptr<Random::RandomGenerator>&& random_generator,
Thread::ThreadFactory& thread_factory,
Filesystem::Instance& file_system,
std::unique_ptr<ProcessContext> 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: {
Expand All @@ -79,7 +88,7 @@ MainCommonBase::MainCommonBase(const Server::Options& options, Event::TimeSystem
server_ = std::make_unique<Server::InstanceImpl>(
*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;
}
Expand Down Expand Up @@ -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();
Expand All @@ -188,14 +197,14 @@ void MainCommonBase::adminRequest(absl::string_view path_and_query, absl::string
MainCommon::MainCommon(const std::vector<std::string>& args)
: options_(args, &MainCommon::hotRestartVersion, spdlog::level::info),
base_(options_, real_time_system_, default_listener_hooks_, prod_component_factory_,
std::make_unique<Random::RandomGeneratorImpl>(), platform_impl_.threadFactory(),
platform_impl_.fileSystem(), nullptr) {}
std::make_unique<PlatformImpl>(), std::make_unique<Random::RandomGeneratorImpl>(),
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<Random::RandomGeneratorImpl>(), platform_impl_.threadFactory(),
platform_impl_.fileSystem(), nullptr) {}
std::make_unique<PlatformImpl>(), std::make_unique<Random::RandomGeneratorImpl>(),
nullptr) {}

std::string MainCommon::hotRestartVersion(bool hot_restart_enabled) {
#ifdef ENVOY_HOT_RESTART
Expand Down
6 changes: 2 additions & 4 deletions source/exe/main_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<PlatformImpl> platform_impl,
std::unique_ptr<Random::RandomGenerator>&& random_generator,
Thread::ThreadFactory& thread_factory, Filesystem::Instance& file_system,
std::unique_ptr<ProcessContext> process_context);

bool run();
Expand All @@ -66,15 +66,14 @@ class MainCommonBase {
const AdminRequestFn& handler);

protected:
std::unique_ptr<PlatformImpl> 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
// the ifdef be inconsistent across build-system boundaries.
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_;

Expand Down Expand Up @@ -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_;
Expand Down
3 changes: 2 additions & 1 deletion source/exe/platform_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
Expand Down
2 changes: 2 additions & 0 deletions source/exe/posix/platform_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ PlatformImpl::PlatformImpl()

PlatformImpl::~PlatformImpl() = default;

bool PlatformImpl::enableCoreDump() { return false; }

} // namespace Envoy
2 changes: 2 additions & 0 deletions source/exe/win32/platform_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,6 @@ PlatformImpl::PlatformImpl()

PlatformImpl::~PlatformImpl() { ::WSACleanup(); }

bool PlatformImpl::enableCoreDump() { return false; }

} // namespace Envoy
2 changes: 2 additions & 0 deletions source/server/options_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ OptionsImpl::OptionsImpl(std::vector<std::string> args,

TCLAP::ValueArg<std::string> 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 {
Expand All @@ -177,6 +178,7 @@ OptionsImpl::OptionsImpl(std::vector<std::string> 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();

Expand Down
Loading