Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 5 additions & 0 deletions bazel/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,11 @@ config_setting(
values = {"define": "admin_html=disabled"},
)

config_setting(
name = "disable_admin_functionality",
values = {"define": "admin_functionality=disabled"},
)

config_setting(
name = "disable_hot_restart_setting",
values = {"define": "hot_restart=disabled"},
Expand Down
1 change: 1 addition & 0 deletions bazel/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,7 @@ The following optional features can be disabled on the Bazel build command-line:
* http3/quic with --//bazel:http3=False
* autolinking libraries with --define=library_autolink=disabled
* admin HTML home page with `--define=admin_html=disabled`
* admin functionlity with `--define=admin_functionaity=disabled`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: "admin_functionaity" => "admin_functionality", I think?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, thanks


## Enabling optional features

Expand Down
6 changes: 4 additions & 2 deletions bazel/envoy_build_system.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ load(
load(":envoy_pch.bzl", _envoy_pch_library = "envoy_pch_library")
load(
":envoy_select.bzl",
_envoy_select_admin_functionality = "envoy_select_admin_functionality",
_envoy_select_admin_html = "envoy_select_admin_html",
_envoy_select_admin_no_html = "envoy_select_admin_no_html",
_envoy_select_boringssl = "envoy_select_boringssl",
Expand Down Expand Up @@ -51,8 +52,8 @@ load(
)
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")

def envoy_package():
native.package(default_visibility = ["//visibility:public"])
def envoy_package(default_visibility = ["//visibility:public"]):
native.package(default_visibility = default_visibility)

def envoy_extension_package(enabled_default = True, default_visibility = EXTENSION_PACKAGE_VISIBILITY):
native.package(default_visibility = default_visibility)
Expand Down Expand Up @@ -210,6 +211,7 @@ def envoy_google_grpc_external_deps():
# Select wrappers (from envoy_select.bzl)
envoy_select_admin_html = _envoy_select_admin_html
envoy_select_admin_no_html = _envoy_select_admin_no_html
envoy_select_admin_functionality = _envoy_select_admin_functionality
envoy_select_boringssl = _envoy_select_boringssl
envoy_select_google_grpc = _envoy_select_google_grpc
envoy_select_enable_http3 = _envoy_select_enable_http3
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_functionality", "envoy_select_admin_html", "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 @@ -123,6 +123,7 @@ def envoy_copts(repository, test = False):
"//conditions:default": [],
}) + envoy_select_hot_restart(["-DENVOY_HOT_RESTART"], repository) + \
envoy_select_admin_html(["-DENVOY_ADMIN_HTML"], repository) + \
envoy_select_admin_functionality(["-DENVOY_ADMIN_FUNCTIONALITY"], repository) + \
envoy_select_enable_http3(["-DENVOY_ENABLE_QUIC"], repository) + \
_envoy_select_perf_annotation(["-DENVOY_PERF_ANNOTATION"]) + \
_envoy_select_perfetto(["-DENVOY_PERFETTO"]) + \
Expand Down
7 changes: 7 additions & 0 deletions bazel/envoy_select.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ def envoy_select_admin_html(xs, repository = ""):
"//conditions:default": xs,
})

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

def envoy_select_admin_no_html(xs, repository = ""):
return select({
repository + "//bazel:disable_admin_html": xs,
Expand Down
4 changes: 2 additions & 2 deletions ci/do_ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -396,8 +396,8 @@ elif [[ "$CI_TARGET" == "bazel.compile_time_options" ]]; then
echo "Building and testing with wasm=wamr: ${TEST_TARGETS[*]}"
bazel_with_collection test "${BAZEL_BUILD_OPTIONS[@]}" --define wasm=wamr "${COMPILE_TIME_OPTIONS[@]}" -c dbg "${TEST_TARGETS[@]}" --test_tag_filters=-nofips --build_tests_only

echo "Building and testing with wasm=wasmtime: ${TEST_TARGETS[*]}"
bazel_with_collection test "${BAZEL_BUILD_OPTIONS[@]}" --define wasm=wasmtime "${COMPILE_TIME_OPTIONS[@]}" -c dbg "${TEST_TARGETS[@]}" --test_tag_filters=-nofips --build_tests_only
echo "Building and testing with wasm=wasmtime: and admin_functionality disabled ${TEST_TARGETS[*]}"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Maybe mention admin_html too, for completeness?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

bazel_with_collection test "${BAZEL_BUILD_OPTIONS[@]}" --define wasm=wasmtime --define admin_html=disabled --define admin_functionality=disabled "${COMPILE_TIME_OPTIONS[@]}" -c dbg "${TEST_TARGETS[@]}" --test_tag_filters=-nofips --build_tests_only

echo "Building and testing with wasm=wavm: ${TEST_TARGETS[*]}"
bazel_with_collection test "${BAZEL_BUILD_OPTIONS[@]}" --define wasm=wavm "${COMPILE_TIME_OPTIONS[@]}" -c dbg "${TEST_TARGETS[@]}" --test_tag_filters=-nofips --build_tests_only
Expand Down
3 changes: 3 additions & 0 deletions configs/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,17 @@ filegroup(
"using_deprecated_config.yaml",
"**/*.template.yaml",
"freebind/freebind.yaml",
"envoy-tap-config.yaml",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity, why does this need to be added?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the tap filter has admin functionality. I didn't go through the exercise of carving that out, the entire tap filter simply won't compile.
Because of that we exempt tap here and add it back below as long as admin isn't disabled

"envoy-demo.yaml",
],
) + select({
"//bazel:apple": ["envoy-demo.yaml"],
"//bazel:windows_x86_64": [],
"//bazel:disable_admin_functionality": [],
"//conditions:default": [
"envoy-demo.yaml",
"freebind/freebind.yaml",
"envoy-tap-config.yaml",
],
}),
)
Expand Down
5 changes: 5 additions & 0 deletions envoy/server/admin.h
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,11 @@ class Admin {
*/
static RequestPtr makeStaticTextRequest(absl::string_view response_text, Http::Code code);
static RequestPtr makeStaticTextRequest(Buffer::Instance& response_text, Http::Code code);

/**
* Closes the listening socket for the admin.
*/
virtual void closeSocket() PURE;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't seem to figure out why this new pure virtual method is needed. Oh is it because we're using std::unique_ptr<Admin> admin_ instead of std::unique_ptr<AdminImpl> admin_ in server.h? Do we need to make that change?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we do, or the server (which now has an API pointer because it may not know about the impl class) can't close the socket.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe you, but I don't yet understand how to connect all the dots :) Why does the server need an API pointer now when before it had an impl pointer?

};

} // namespace Server
Expand Down
4 changes: 2 additions & 2 deletions envoy/server/factory_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ class FactoryContextBase {
virtual const LocalInfo::LocalInfo& localInfo() const PURE;

/**
* @return Server::Admin& the server's global admin HTTP endpoint.
* @return OptRef<Server::Admin> the global HTTP admin endpoint for the server.
*/
virtual Server::Admin& admin() PURE;
virtual OptRef<Server::Admin> admin() PURE;

/**
* @return Runtime::Loader& the singleton runtime loader for the server.
Expand Down
4 changes: 2 additions & 2 deletions envoy/server/instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ class Instance {
virtual ~Instance() = default;

/**
* @return Admin& the global HTTP admin endpoint for the server.
* @return OptRef<Admin> the global HTTP admin endpoint for the server.
*/
virtual Admin& admin() PURE;
virtual OptRef<Admin> admin() PURE;

/**
* @return Api::Api& the API used by the server.
Expand Down
4 changes: 2 additions & 2 deletions envoy/server/transport_socket_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ class TransportSocketFactoryContext {
virtual ~TransportSocketFactoryContext() = default;

/**
* @return Server::Admin& the server's admin interface.
* @return OptRef<Server::Admin> the global HTTP admin endpoint for the server.
*/
virtual Server::Admin& admin() PURE;
virtual OptRef<Server::Admin> admin() PURE;

/**
* @return Ssl::ContextManager& the SSL context manager.
Expand Down
16 changes: 9 additions & 7 deletions source/common/config/config_provider_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,16 @@ bool ConfigSubscriptionInstance::checkAndApplyConfigUpdate(const Protobuf::Messa
return true;
}

ConfigProviderManagerImplBase::ConfigProviderManagerImplBase(Server::Admin& admin,
ConfigProviderManagerImplBase::ConfigProviderManagerImplBase(OptRef<Server::Admin> admin,
const std::string& config_name) {
config_tracker_entry_ = admin.getConfigTracker().add(
config_name,
[this](const Matchers::StringMatcher& name_matcher) { return dumpConfigs(name_matcher); });
// ConfigTracker keys must be unique. We are asserting that no one has stolen the key
// from us, since the returned entry will be nullptr if the key already exists.
RELEASE_ASSERT(config_tracker_entry_, "");
if (admin.has_value()) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: early return

if (!admin.has_value()) {
  return;
}
...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just use the ifdef?

Or do you also support (or plan to support) disabling admin at runtime via a runtime or command-line flag while still compiling it in?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer most of the code compiling in both branches and minimal use of the ifdef. it means we can get coverage for more code for example

config_tracker_entry_ = admin->getConfigTracker().add(
config_name,
[this](const Matchers::StringMatcher& name_matcher) { return dumpConfigs(name_matcher); });
// ConfigTracker keys must be unique. We are asserting that no one has stolen the key
// from us, since the returned entry will be nullptr if the key already exists.
RELEASE_ASSERT(config_tracker_entry_, "");
}
}

const ConfigProviderManagerImplBase::ConfigProviderSet&
Expand Down
2 changes: 1 addition & 1 deletion source/common/config/config_provider_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ class ConfigProviderManagerImplBase : public ConfigProviderManager, public Singl
using ConfigSubscriptionMap =
absl::node_hash_map<uint64_t, std::weak_ptr<ConfigSubscriptionCommonBase>>;

ConfigProviderManagerImplBase(Server::Admin& admin, const std::string& config_name);
ConfigProviderManagerImplBase(OptRef<Server::Admin> admin, const std::string& config_name);

const ConfigSubscriptionMap& configSubscriptions() const { return config_subscriptions_; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ template <class Rds, class RouteConfiguration, int NameFieldNumber, class Config
class RouteConfigProviderManagerImpl : public RouteConfigProviderManager<Rds, RouteConfiguration>,
public Singleton::Instance {
public:
RouteConfigProviderManagerImpl(Server::Admin& admin)
RouteConfigProviderManagerImpl(OptRef<Server::Admin> admin)
: manager_(admin, absl::AsciiStrToLower(getRdsName()) + "_routes", proto_traits_) {}

// RouteConfigProviderManager
Expand Down
18 changes: 10 additions & 8 deletions source/common/rds/route_config_provider_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@
namespace Envoy {
namespace Rds {

RouteConfigProviderManager::RouteConfigProviderManager(Server::Admin& admin,
RouteConfigProviderManager::RouteConfigProviderManager(OptRef<Server::Admin> admin,
const std::string& config_tracker_key,
ProtoTraits& proto_traits)
: config_tracker_entry_(admin.getConfigTracker().add(
config_tracker_key,
[this](const Matchers::StringMatcher& matcher) { return dumpRouteConfigs(matcher); })),
proto_traits_(proto_traits) {
// ConfigTracker keys must be unique. We are asserting that no one has stolen the "routes" key
// from us, since the returned entry will be nullptr if the key already exists.
RELEASE_ASSERT(config_tracker_entry_, "");
: proto_traits_(proto_traits) {
if (admin.has_value()) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: early return

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

config_tracker_entry_ = admin->getConfigTracker().add(
config_tracker_key,
[this](const Matchers::StringMatcher& matcher) { return dumpRouteConfigs(matcher); });
// ConfigTracker keys must be unique. We are asserting that no one has stolen the "routes" key
// from us, since the returned entry will be nullptr if the key already exists.
RELEASE_ASSERT(config_tracker_entry_, "");
}
}

void RouteConfigProviderManager::eraseStaticProvider(RouteConfigProvider* provider) {
Expand Down
2 changes: 1 addition & 1 deletion source/common/rds/route_config_provider_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace Rds {

class RouteConfigProviderManager {
public:
RouteConfigProviderManager(Server::Admin& admin, const std::string& config_tracker_key,
RouteConfigProviderManager(OptRef<Server::Admin> admin, const std::string& config_tracker_key,
ProtoTraits& proto_traits);

void eraseStaticProvider(RouteConfigProvider* provider);
Expand Down
2 changes: 1 addition & 1 deletion source/common/router/rds_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ void RdsRouteConfigProviderImpl::requestVirtualHostsUpdate(
});
}

RouteConfigProviderManagerImpl::RouteConfigProviderManagerImpl(Server::Admin& admin)
RouteConfigProviderManagerImpl::RouteConfigProviderManagerImpl(OptRef<Server::Admin> admin)
: manager_(admin, "routes", proto_traits_) {}

Router::RouteConfigProviderSharedPtr RouteConfigProviderManagerImpl::createRdsRouteConfigProvider(
Expand Down
2 changes: 1 addition & 1 deletion source/common/router/rds_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ using ProtoTraitsImpl =
class RouteConfigProviderManagerImpl : public RouteConfigProviderManager,
public Singleton::Instance {
public:
RouteConfigProviderManagerImpl(Server::Admin& admin);
RouteConfigProviderManagerImpl(OptRef<Server::Admin> admin);

std::unique_ptr<envoy::admin::v3::RoutesConfigDump>
dumpRouteConfigs(const Matchers::StringMatcher& name_matcher) const {
Expand Down
3 changes: 2 additions & 1 deletion source/common/router/scoped_rds.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,8 @@ class ScopedRdsConfigProvider : public Envoy::Config::MutableConfigProviderCommo
class ScopedRoutesConfigProviderManager : public Envoy::Config::ConfigProviderManagerImplBase {
public:
ScopedRoutesConfigProviderManager(
Server::Admin& admin, Router::RouteConfigProviderManager& route_config_provider_manager)
OptRef<Server::Admin> admin,
Router::RouteConfigProviderManager& route_config_provider_manager)
: Envoy::Config::ConfigProviderManagerImplBase(admin, "route_scopes"),
route_config_provider_manager_(route_config_provider_manager) {}

Expand Down
14 changes: 9 additions & 5 deletions source/common/secret/secret_manager_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,15 @@
namespace Envoy {
namespace Secret {

SecretManagerImpl::SecretManagerImpl(Server::ConfigTracker& config_tracker)
: config_tracker_entry_(
config_tracker.add("secrets", [this](const Matchers::StringMatcher& name_matcher) {
return dumpSecretConfigs(name_matcher);
})) {}
SecretManagerImpl::SecretManagerImpl(OptRef<Server::ConfigTracker> config_tracker) {
if (config_tracker.has_value()) {
config_tracker_entry_ =
config_tracker->add("secrets", [this](const Matchers::StringMatcher& name_matcher) {
return dumpSecretConfigs(name_matcher);
});
}
}

void SecretManagerImpl::addStaticSecret(
const envoy::extensions::transport_sockets::tls::v3::Secret& secret) {
switch (secret.type_case()) {
Expand Down
2 changes: 1 addition & 1 deletion source/common/secret/secret_manager_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace Secret {

class SecretManagerImpl : public SecretManager {
public:
SecretManagerImpl(Server::ConfigTracker& config_tracker);
SecretManagerImpl(OptRef<Server::ConfigTracker> config_tracker);
void
addStaticSecret(const envoy::extensions::transport_sockets::tls::v3::Secret& secret) override;

Expand Down
2 changes: 1 addition & 1 deletion source/common/upstream/cluster_factory_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class ClusterFactoryContextImpl : public ClusterFactoryContext {
AccessLog::AccessLogManager& logManager() override { return server_context_.accessLogManager(); }
const LocalInfo::LocalInfo& localInfo() const override { return server_context_.localInfo(); }
const Server::Options& options() override { return server_context_.options(); }
Server::Admin& admin() override { return server_context_.admin(); }
OptRef<Server::Admin> admin() override { return server_context_.admin(); }
Api::Api& api() override { return server_context_.api(); }
Singleton::Manager& singletonManager() override { return server_context_.singletonManager(); }

Expand Down
13 changes: 7 additions & 6 deletions source/common/upstream/cluster_manager_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ ClusterManagerImpl::ClusterManagerImpl(
const envoy::config::bootstrap::v3::Bootstrap& bootstrap, ClusterManagerFactory& factory,
Stats::Store& stats, ThreadLocal::Instance& tls, Runtime::Loader& runtime,
const LocalInfo::LocalInfo& local_info, AccessLog::AccessLogManager& log_manager,
Event::Dispatcher& main_thread_dispatcher, Server::Admin& admin,
Event::Dispatcher& main_thread_dispatcher, OptRef<Server::Admin> admin,
ProtobufMessage::ValidationContext& validation_context, Api::Api& api,
Http::Context& http_context, Grpc::Context& grpc_context, Router::Context& router_context,
const Server::Instance& server)
Expand All @@ -292,18 +292,19 @@ ClusterManagerImpl::ClusterManagerImpl(
bind_config_(bootstrap.cluster_manager().upstream_bind_config()), local_info_(local_info),
cm_stats_(generateStats(stats)),
init_helper_(*this, [this](ClusterManagerCluster& cluster) { onClusterInit(cluster); }),
config_tracker_entry_(
admin.getConfigTracker().add("clusters",
[this](const Matchers::StringMatcher& name_matcher) {
return dumpClusterConfigs(name_matcher);
})),
time_source_(main_thread_dispatcher.timeSource()), dispatcher_(main_thread_dispatcher),
http_context_(http_context), router_context_(router_context),
cluster_stat_names_(stats.symbolTable()),
cluster_load_report_stat_names_(stats.symbolTable()),
cluster_circuit_breakers_stat_names_(stats.symbolTable()),
cluster_request_response_size_stat_names_(stats.symbolTable()),
cluster_timeout_budget_stat_names_(stats.symbolTable()) {
if (admin.has_value()) {
config_tracker_entry_ = admin->getConfigTracker().add(
"clusters", [this](const Matchers::StringMatcher& name_matcher) {
return dumpClusterConfigs(name_matcher);
});
}
async_client_manager_ = std::make_unique<Grpc::AsyncClientManagerImpl>(
*this, tls, time_source_, api, grpc_context.statNames());
const auto& cm_config = bootstrap.cluster_manager();
Expand Down
6 changes: 3 additions & 3 deletions source/common/upstream/cluster_manager_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ namespace Upstream {
class ProdClusterManagerFactory : public ClusterManagerFactory {
public:
ProdClusterManagerFactory(
Server::Configuration::ServerFactoryContext& server_context, Server::Admin& admin,
Server::Configuration::ServerFactoryContext& server_context, OptRef<Server::Admin> admin,
Runtime::Loader& runtime, Stats::Store& stats, ThreadLocal::Instance& tls,
Network::DnsResolverSharedPtr dns_resolver, Ssl::ContextManager& ssl_context_manager,
Event::Dispatcher& main_thread_dispatcher, const LocalInfo::LocalInfo& local_info,
Expand Down Expand Up @@ -105,7 +105,7 @@ class ProdClusterManagerFactory : public ClusterManagerFactory {
Http::Context& http_context_;
Grpc::Context& grpc_context_;
Router::Context& router_context_;
Server::Admin& admin_;
OptRef<Server::Admin> admin_;
Stats::Store& stats_;
ThreadLocal::Instance& tls_;
Network::DnsResolverSharedPtr dns_resolver_;
Expand Down Expand Up @@ -245,7 +245,7 @@ class ClusterManagerImpl : public ClusterManager,
ThreadLocal::Instance& tls, Runtime::Loader& runtime,
const LocalInfo::LocalInfo& local_info,
AccessLog::AccessLogManager& log_manager,
Event::Dispatcher& main_thread_dispatcher, Server::Admin& admin,
Event::Dispatcher& main_thread_dispatcher, OptRef<Server::Admin> admin,
ProtobufMessage::ValidationContext& validation_context, Api::Api& api,
Http::Context& http_context, Grpc::Context& grpc_context,
Router::Context& router_context, const Server::Instance& server);
Expand Down
4 changes: 2 additions & 2 deletions source/common/upstream/upstream_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -877,7 +877,7 @@ class FactoryContextImpl : public Server::Configuration::CommonFactoryContext {
Stats::Scope& serverScope() override { return server_scope_; }
Singleton::Manager& singletonManager() override { return singleton_manager_; }
ThreadLocal::SlotAllocator& threadLocal() override { return tls_; }
Server::Admin& admin() override { return admin_; }
OptRef<Server::Admin> admin() override { return admin_; }
TimeSource& timeSource() override { return api().timeSource(); }
ProtobufMessage::ValidationContext& messageValidationContext() override {
// TODO(davinci26): Needs an implementation for this context. Currently not used.
Expand Down Expand Up @@ -906,7 +906,7 @@ class FactoryContextImpl : public Server::Configuration::CommonFactoryContext {
Api::Api& api() override { return api_; }

private:
Server::Admin& admin_;
OptRef<Server::Admin> admin_;
Stats::Scope& server_scope_;
Stats::Scope& stats_scope_;
Upstream::ClusterManager& cluster_manager_;
Expand Down
4 changes: 3 additions & 1 deletion source/exe/main_common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,14 @@ bool MainCommonBase::run() {

void MainCommonBase::adminRequest(absl::string_view path_and_query, absl::string_view method,
const AdminRequestFn& handler) {
RELEASE_ASSERT(server_->admin().has_value(),
"adminRequest called with admin support compiled out");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'd know better than I would, but I wonder if instead of RELEASE_ASSERT if we should just ASSERT() in debug, and return in release? But I suspect you already thought about this.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would we want to assert at all? Can't we just call the handler with an http error code? Maybe a 501?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's a bug to call admin requests with them compiled out. I think we should definitely crash in debug mode at least.

std::string path_and_query_buf = std::string(path_and_query);
std::string method_buf = std::string(method);
server_->dispatcher().post([this, path_and_query_buf, method_buf, handler]() {
auto response_headers = Http::ResponseHeaderMapImpl::create();
std::string body;
server_->admin().request(path_and_query_buf, method_buf, *response_headers, body);
server_->admin()->request(path_and_query_buf, method_buf, *response_headers, body);
handler(*response_headers, body);
});
}
Expand Down
Loading