Skip to content
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

Allow disabling the guard dog #23316

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
21 changes: 21 additions & 0 deletions bazel/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,27 @@ config_setting(
values = {"define": "deprecated_features=disabled"},
)

bool_flag(
name = "guarddog",
build_setting_default = True,
visibility = ["//visibility:private"],
)

config_setting(
name = "disable_guarddog_setting",
flag_values = {
":guarddog": "False",
},
visibility = ["//visibility:private"],
)

selects.config_setting_group(
name = "disable_guarddog",
match_any = [
":disable_guarddog_setting",
],
)

bool_flag(
name = "http3",
build_setting_default = True,
Expand Down
2 changes: 2 additions & 0 deletions bazel/envoy_build_system.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ load(
_envoy_select_admin_html = "envoy_select_admin_html",
_envoy_select_admin_no_html = "envoy_select_admin_no_html",
_envoy_select_boringssl = "envoy_select_boringssl",
_envoy_select_enable_guarddog = "envoy_select_enable_guarddog",
_envoy_select_enable_http3 = "envoy_select_enable_http3",
_envoy_select_google_grpc = "envoy_select_google_grpc",
_envoy_select_hot_restart = "envoy_select_hot_restart",
Expand Down Expand Up @@ -212,6 +213,7 @@ envoy_select_admin_html = _envoy_select_admin_html
envoy_select_admin_no_html = _envoy_select_admin_no_html
envoy_select_boringssl = _envoy_select_boringssl
envoy_select_google_grpc = _envoy_select_google_grpc
envoy_select_enable_guarddog = _envoy_select_enable_guarddog
envoy_select_enable_http3 = _envoy_select_enable_http3
envoy_select_hot_restart = _envoy_select_hot_restart
envoy_select_wasm_cpp_tests = _envoy_select_wasm_cpp_tests
Expand Down
3 changes: 2 additions & 1 deletion bazel/envoy_internal.bzl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# DO NOT LOAD THIS FILE. Targets from this file should be considered private
# and not used outside of the @envoy//bazel package.
load(":envoy_select.bzl", "envoy_select_admin_html", "envoy_select_enable_http3", "envoy_select_google_grpc", "envoy_select_hot_restart")
load(":envoy_select.bzl", "envoy_select_admin_html", "envoy_select_enable_guarddog", "envoy_select_enable_http3", "envoy_select_google_grpc", "envoy_select_hot_restart")

# Compute the final copts based on various options.
def envoy_copts(repository, test = False):
Expand Down Expand Up @@ -124,6 +124,7 @@ def envoy_copts(repository, test = False):
}) + envoy_select_hot_restart(["-DENVOY_HOT_RESTART"], repository) + \
envoy_select_admin_html(["-DENVOY_ADMIN_HTML"], repository) + \
envoy_select_enable_http3(["-DENVOY_ENABLE_QUIC"], repository) + \
envoy_select_enable_guarddog(["-DENVOY_ENABLE_GUARDDOG"], repository) + \
_envoy_select_perf_annotation(["-DENVOY_PERF_ANNOTATION"]) + \
_envoy_select_perfetto(["-DENVOY_PERFETTO"]) + \
envoy_select_google_grpc(["-DENVOY_GOOGLE_GRPC"], repository) + \
Expand Down
7 changes: 7 additions & 0 deletions bazel/envoy_select.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ def envoy_select_enable_http3(xs, repository = ""):
"//conditions:default": xs,
})

# Selects the given values if the guard dog is enabled in the current build.
def envoy_select_enable_guarddog(xs, repository = ""):
return select({
repository + "//bazel:disable_guarddog": [],
"//conditions:default": xs,
})

# Selects the given values if hot restart is enabled in the current build.
def envoy_select_hot_restart(xs, repository = ""):
return select({
Expand Down
4 changes: 2 additions & 2 deletions source/server/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ load(
"envoy_cc_library",
"envoy_package",
"envoy_proto_library",
"envoy_select_enable_guarddog",
"envoy_select_enable_http3",
"envoy_select_hot_restart",
)
Expand Down Expand Up @@ -577,7 +578,6 @@ envoy_cc_library(
":active_raw_udp_listener_config",
":configuration_lib",
":connection_handler_lib",
":guarddog_lib",
":listener_hooks_lib",
":listener_manager_lib",
":ssl_context_manager_lib",
Expand Down Expand Up @@ -633,7 +633,7 @@ envoy_cc_library(
"//source/server/admin:admin_lib",
"@envoy_api//envoy/admin/v3:pkg_cc_proto",
"@envoy_api//envoy/config/bootstrap/v3:pkg_cc_proto",
],
] + envoy_select_enable_guarddog([":guarddog_lib"]),
)

envoy_cc_library(
Expand Down
11 changes: 10 additions & 1 deletion source/server/server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,13 @@
#include "source/server/admin/utils.h"
#include "source/server/configuration_impl.h"
#include "source/server/connection_handler_impl.h"
#include "source/server/guarddog_impl.h"
#include "source/server/listener_hooks.h"
#include "source/server/ssl_context_manager.h"

#ifdef ENVOY_ENABLE_GUARDDOG
#include "source/server/guarddog_impl.h"
#endif

namespace Envoy {
namespace Server {

Expand Down Expand Up @@ -731,12 +734,14 @@ void InstanceImpl::initialize(Network::Address::InstanceConstSharedPtr local_add
bootstrap_extension->onServerInitialized();
}

#ifdef ENVOY_ENABLE_GUARDDOG
// GuardDog (deadlock detection) object and thread setup before workers are
// started and before our own run() loop runs.
main_thread_guard_dog_ = std::make_unique<Server::GuardDogImpl>(
stats_store_, config_.mainThreadWatchdogConfig(), *api_, "main_thread");
worker_guard_dog_ = std::make_unique<Server::GuardDogImpl>(
stats_store_, config_.workerWatchdogConfig(), *api_, "workers");
#endif
}

void InstanceImpl::onClusterManagerPrimaryInitializationComplete() {
Expand Down Expand Up @@ -902,13 +907,17 @@ void InstanceImpl::run() {

// Run the main dispatch loop waiting to exit.
ENVOY_LOG(info, "starting main dispatch loop");
#ifdef ENVOY_ENABLE_GUARDDOG
auto watchdog = main_thread_guard_dog_->createWatchDog(api_->threadFactory().currentThreadId(),
"main_thread", *dispatcher_);
#endif
dispatcher_->post([this] { notifyCallbacksForStage(Stage::Startup); });
dispatcher_->run(Event::Dispatcher::RunType::Block);
ENVOY_LOG(info, "main dispatch loop exited");
#ifdef ENVOY_ENABLE_GUARDDOG
main_thread_guard_dog_->stopWatching(watchdog);
watchdog.reset();
#endif

terminate();
}
Expand Down