Skip to content
Merged
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
2 changes: 1 addition & 1 deletion bazel/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def envoy_api_deps(skip_targets):
remote = REPO_LOCATIONS["envoy_api"],
commit = "0b35f3efc31621953bc2eb7458d01d8eab984394",
)
bind_targets = ["address", "base", "cds", "eds", "health_check", "protocol", "tls_context"]
bind_targets = ["address", "base", "bootstrap", "cds", "eds", "health_check", "protocol", "tls_context"]
for t in bind_targets:
native.bind(
name = "envoy_" + t,
Expand Down
8 changes: 8 additions & 0 deletions include/envoy/server/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ class Options {
*/
virtual const std::string& configPath() PURE;

/**
* @return const std::string& the path to the v2 bootstrap file.
* TODO(htuch): We can eventually consolidate configPath()/bootstrapPath(), but today
* the config fetched from bootstrapPath() acts as an overlay to the config fetched from
* configPath() during v2 API bringup.
*/
virtual const std::string& bootstrapPath() PURE;

/**
* @return const std::string& the admin address output file.
*/
Expand Down
5 changes: 4 additions & 1 deletion include/envoy/upstream/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ envoy_package()
envoy_cc_library(
name = "cluster_manager_interface",
hdrs = ["cluster_manager.h"],
external_deps = ["envoy_cds"],
external_deps = [
"envoy_bootstrap",
"envoy_cds",
],
deps = [
":load_balancer_interface",
":thread_local_cluster_interface",
Expand Down
14 changes: 8 additions & 6 deletions include/envoy/upstream/cluster_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "envoy/upstream/thread_local_cluster.h"
#include "envoy/upstream/upstream.h"

#include "api/bootstrap.pb.h"
#include "api/cds.pb.h"

namespace Envoy {
Expand Down Expand Up @@ -148,13 +149,14 @@ class ClusterManagerFactory {

/**
* Allocate a cluster manager from configuration JSON.
* TODO(htuch): Once bootstrap is sufficiently capable, switch to a translation from the JSON v1
* cluster manager config -> v2 proto and drop the config parameter.
*/
virtual ClusterManagerPtr clusterManagerFromJson(const Json::Object& config, Stats::Store& stats,
ThreadLocal::Instance& tls,
Runtime::Loader& runtime,
Runtime::RandomGenerator& random,
const LocalInfo::LocalInfo& local_info,
AccessLog::AccessLogManager& log_manager) PURE;
virtual ClusterManagerPtr
clusterManagerFromJson(const Json::Object& config, const envoy::api::v2::Bootstrap& bootstrap,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Any reason we are not just converting JSON to bootstrap like we are doing in other PRs? That seems like right long term approach?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Will add this in a later PR, once we grow the bootstrap proto to encompass the full cluster manager, so yeah, this is the plan, but for a minimal CDS/EDS end-to-end capability this isn't needed yet.

Stats::Store& stats, ThreadLocal::Instance& tls, Runtime::Loader& runtime,
Runtime::RandomGenerator& random, const LocalInfo::LocalInfo& local_info,
AccessLog::AccessLogManager& log_manager) PURE;

/**
* Allocate an HTTP connection pool.
Expand Down
2 changes: 1 addition & 1 deletion source/common/config/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ envoy_cc_library(
"//include/envoy/filesystem:filesystem_interface",
"//source/common/common:logger_lib",
"//source/common/config:utility_lib",
"//source/common/filesystem:filesystem_lib",
"//source/common/protobuf",
"//source/common/protobuf:utility_lib",
],
)

Expand Down
13 changes: 2 additions & 11 deletions source/common/config/filesystem_subscription_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
#include "common/common/logger.h"
#include "common/common/macros.h"
#include "common/config/utility.h"
#include "common/filesystem/filesystem_impl.h"
#include "common/protobuf/protobuf.h"
#include "common/protobuf/utility.h"

#include "api/base.pb.h"

Expand Down Expand Up @@ -53,17 +53,8 @@ class FilesystemSubscriptionImpl : public Config::Subscription<ResourceType>,
stats_.update_attempt_.inc();
bool config_update_available = false;
try {
const std::string json = Filesystem::fileReadToEnd(path_);
envoy::api::v2::DiscoveryResponse message;
const auto status =
Protobuf::util::JsonStringToMessage(ProtobufTypes::ToString(json), &message);
if (!status.ok()) {
callbacks_->onConfigUpdateFailed(nullptr);
ENVOY_LOG(warn, "Filesystem config JSON conversion error: {}",
ProtobufTypes::FromString(status.ToString()));
stats_.update_failure_.inc();
return;
}
MessageUtil::loadFromFile(path_, message);
const auto typed_resources = Config::Utility::getTypedResources<ResourceType>(message);
config_update_available = true;
callbacks_->onConfigUpdate(typed_resources);
Expand Down
1 change: 1 addition & 0 deletions source/common/protobuf/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ envoy_cc_library(
deps = [
":protobuf",
"//source/common/common:utility_lib",
"//source/common/filesystem:filesystem_lib",
],
)
10 changes: 10 additions & 0 deletions source/common/protobuf/utility.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "common/protobuf/utility.h"

#include "common/filesystem/filesystem_impl.h"

#include "spdlog/spdlog.h"

namespace Envoy {
Expand All @@ -9,4 +11,12 @@ MissingFieldException::MissingFieldException(const std::string& field_name,
: EnvoyException(fmt::format("Field '{}' is missing in: {}", field_name,
ProtobufTypes::FromString(message.DebugString()))) {}

void MessageUtil::loadFromFile(const std::string& path, Protobuf::Message& message) {
const std::string json = Filesystem::fileReadToEnd(path);
const auto status = Protobuf::util::JsonStringToMessage(ProtobufTypes::ToString(json), &message);
if (!status.ok()) {
throw EnvoyException("Unable to parse JSON as proto: " + json);
}
}

} // namespace Envoy
2 changes: 2 additions & 0 deletions source/common/protobuf/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ class MessageUtil {
static std::size_t hash(const Protobuf::Message& message) {
return std::hash<std::string>{}(message.SerializeAsString());
}

static void loadFromFile(const std::string& path, Protobuf::Message& message);
};

} // namespace Envoy
17 changes: 10 additions & 7 deletions source/common/upstream/cluster_manager_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,18 @@ void ClusterManagerInitHelper::setInitializedCb(std::function<void()> callback)
}
}

ClusterManagerImpl::ClusterManagerImpl(const Json::Object& config, ClusterManagerFactory& factory,
Stats::Store& stats, ThreadLocal::SlotAllocator& tls,
Runtime::Loader& runtime, Runtime::RandomGenerator& random,
ClusterManagerImpl::ClusterManagerImpl(const Json::Object& config,
const envoy::api::v2::Bootstrap& bootstrap,
ClusterManagerFactory& factory, Stats::Store& stats,
ThreadLocal::SlotAllocator& tls, Runtime::Loader& runtime,
Runtime::RandomGenerator& random,
const LocalInfo::LocalInfo& local_info,
AccessLog::AccessLogManager& log_manager)
: factory_(factory), runtime_(runtime), stats_(stats), tls_(tls.allocateSlot()),
random_(random), local_info_(local_info), cm_stats_(generateStats(stats)) {

config.validateSchema(Json::Schema::CLUSTER_MANAGER_SCHEMA);
UNREFERENCED_PARAMETER(bootstrap);

if (config.hasObject("outlier_detection")) {
std::string event_log_file_path =
Expand Down Expand Up @@ -576,11 +579,11 @@ ClusterManagerImpl::ThreadLocalClusterManagerImpl::ClusterEntry::connPool(
}

ClusterManagerPtr ProdClusterManagerFactory::clusterManagerFromJson(
const Json::Object& config, Stats::Store& stats, ThreadLocal::Instance& tls,
Runtime::Loader& runtime, Runtime::RandomGenerator& random,
const Json::Object& config, const envoy::api::v2::Bootstrap& bootstrap, Stats::Store& stats,
ThreadLocal::Instance& tls, Runtime::Loader& runtime, Runtime::RandomGenerator& random,
const LocalInfo::LocalInfo& local_info, AccessLog::AccessLogManager& log_manager) {
return ClusterManagerPtr{
new ClusterManagerImpl(config, *this, stats, tls, runtime, random, local_info, log_manager)};
return ClusterManagerPtr{new ClusterManagerImpl(config, bootstrap, *this, stats, tls, runtime,
random, local_info, log_manager)};
}

Http::ConnectionPool::InstancePtr
Expand Down
15 changes: 8 additions & 7 deletions source/common/upstream/cluster_manager_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ class ProdClusterManagerFactory : public ClusterManagerFactory {
local_info_(local_info) {}

// Upstream::ClusterManagerFactory
ClusterManagerPtr clusterManagerFromJson(const Json::Object& config, Stats::Store& stats,
ThreadLocal::Instance& tls, Runtime::Loader& runtime,
Runtime::RandomGenerator& random,
const LocalInfo::LocalInfo& local_info,
AccessLog::AccessLogManager& log_manager) override;
ClusterManagerPtr
clusterManagerFromJson(const Json::Object& config, const envoy::api::v2::Bootstrap& bootstrap,
Stats::Store& stats, ThreadLocal::Instance& tls, Runtime::Loader& runtime,
Runtime::RandomGenerator& random, const LocalInfo::LocalInfo& local_info,
AccessLog::AccessLogManager& log_manager) override;
Http::ConnectionPool::InstancePtr allocateConnPool(Event::Dispatcher& dispatcher,
HostConstSharedPtr host,
ResourcePriority priority) override;
Expand Down Expand Up @@ -119,8 +119,9 @@ struct ClusterManagerStats {
*/
class ClusterManagerImpl : public ClusterManager, Logger::Loggable<Logger::Id::upstream> {
public:
ClusterManagerImpl(const Json::Object& config, ClusterManagerFactory& factory,
Stats::Store& stats, ThreadLocal::SlotAllocator& tls, Runtime::Loader& runtime,
ClusterManagerImpl(const Json::Object& config, const envoy::api::v2::Bootstrap& bootstrap,
ClusterManagerFactory& factory, Stats::Store& stats,
ThreadLocal::SlotAllocator& tls, Runtime::Loader& runtime,
Runtime::RandomGenerator& random, const LocalInfo::LocalInfo& local_info,
AccessLog::AccessLogManager& log_manager);

Expand Down
3 changes: 3 additions & 0 deletions source/server/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ envoy_cc_library(
name = "configuration_lib",
srcs = ["configuration_impl.cc"],
hdrs = ["configuration_impl.h"],
external_deps = ["envoy_bootstrap"],
deps = [
":lds_api_lib",
"//include/envoy/http:filter_interface",
Expand Down Expand Up @@ -156,6 +157,7 @@ envoy_cc_library(
name = "server_lib",
srcs = ["server.cc"],
hdrs = ["server.h"],
external_deps = ["envoy_bootstrap"],
deps = [
":configuration_lib",
":connection_handler_lib",
Expand All @@ -181,6 +183,7 @@ envoy_cc_library(
"//source/common/common:utility_lib",
"//source/common/common:version_lib",
"//source/common/memory:stats_lib",
"//source/common/protobuf:utility_lib",
"//source/common/runtime:runtime_lib",
"//source/common/stats:statsd_lib",
"//source/common/upstream:cluster_manager_lib",
Expand Down
2 changes: 2 additions & 0 deletions source/server/config_validation/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ envoy_cc_library(
name = "server_lib",
srcs = ["server.cc"],
hdrs = ["server.h"],
external_deps = ["envoy_bootstrap"],
deps = [
":api_lib",
":cluster_manager_lib",
Expand All @@ -74,6 +75,7 @@ envoy_cc_library(
"//include/envoy/tracing:http_tracer_interface",
"//source/common/access_log:access_log_manager_lib",
"//source/common/common:assert_lib",
"//source/common/protobuf:utility_lib",
"//source/common/runtime:runtime_lib",
"//source/common/ssl:context_lib",
"//source/common/stats:stats_lib",
Expand Down
16 changes: 9 additions & 7 deletions source/server/config_validation/cluster_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ ValidationClusterManagerFactory::ValidationClusterManagerFactory(
primary_dispatcher, local_info) {}

ClusterManagerPtr ValidationClusterManagerFactory::clusterManagerFromJson(
const Json::Object& config, Stats::Store& stats, ThreadLocal::Instance& tls,
Runtime::Loader& runtime, Runtime::RandomGenerator& random,
const Json::Object& config, const envoy::api::v2::Bootstrap& bootstrap, Stats::Store& stats,
ThreadLocal::Instance& tls, Runtime::Loader& runtime, Runtime::RandomGenerator& random,
const LocalInfo::LocalInfo& local_info, AccessLog::AccessLogManager& log_manager) {
return ClusterManagerPtr{new ValidationClusterManager(config, *this, stats, tls, runtime, random,
local_info, log_manager)};
return ClusterManagerPtr{new ValidationClusterManager(config, bootstrap, *this, stats, tls,
runtime, random, local_info, log_manager)};
}

CdsApiPtr ValidationClusterManagerFactory::createCds(const Json::Object& config,
Expand All @@ -29,10 +29,12 @@ CdsApiPtr ValidationClusterManagerFactory::createCds(const Json::Object& config,
}

ValidationClusterManager::ValidationClusterManager(
const Json::Object& config, ClusterManagerFactory& factory, Stats::Store& stats,
ThreadLocal::Instance& tls, Runtime::Loader& runtime, Runtime::RandomGenerator& random,
const Json::Object& config, const envoy::api::v2::Bootstrap& bootstrap,
ClusterManagerFactory& factory, Stats::Store& stats, ThreadLocal::Instance& tls,
Runtime::Loader& runtime, Runtime::RandomGenerator& random,
const LocalInfo::LocalInfo& local_info, AccessLog::AccessLogManager& log_manager)
: ClusterManagerImpl(config, factory, stats, tls, runtime, random, local_info, log_manager) {}
: ClusterManagerImpl(config, bootstrap, factory, stats, tls, runtime, random, local_info,
log_manager) {}

Http::ConnectionPool::Instance*
ValidationClusterManager::httpConnPoolForCluster(const std::string&, ResourcePriority,
Expand Down
18 changes: 9 additions & 9 deletions source/server/config_validation/cluster_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ class ValidationClusterManagerFactory : public ProdClusterManagerFactory {
Event::Dispatcher& primary_dispatcher,
const LocalInfo::LocalInfo& local_info);

ClusterManagerPtr clusterManagerFromJson(const Json::Object& config, Stats::Store& stats,
ThreadLocal::Instance& tls, Runtime::Loader& runtime,
Runtime::RandomGenerator& random,
const LocalInfo::LocalInfo& local_info,
AccessLog::AccessLogManager& log_manager) override;
ClusterManagerPtr
clusterManagerFromJson(const Json::Object& config, const envoy::api::v2::Bootstrap& bootstrap,
Stats::Store& stats, ThreadLocal::Instance& tls, Runtime::Loader& runtime,
Runtime::RandomGenerator& random, const LocalInfo::LocalInfo& local_info,
AccessLog::AccessLogManager& log_manager) override;

// Delegates to ProdClusterManagerFactory::createCds, but discards the result and returns nullptr
// unconditionally.
Expand All @@ -39,10 +39,10 @@ class ValidationClusterManagerFactory : public ProdClusterManagerFactory {
*/
class ValidationClusterManager : public ClusterManagerImpl {
public:
ValidationClusterManager(const Json::Object& config, ClusterManagerFactory& factory,
Stats::Store& stats, ThreadLocal::Instance& tls,
Runtime::Loader& runtime, Runtime::RandomGenerator& random,
const LocalInfo::LocalInfo& local_info,
ValidationClusterManager(const Json::Object& config, const envoy::api::v2::Bootstrap& bootstrap,
ClusterManagerFactory& factory, Stats::Store& stats,
ThreadLocal::Instance& tls, Runtime::Loader& runtime,
Runtime::RandomGenerator& random, const LocalInfo::LocalInfo& local_info,
AccessLog::AccessLogManager& log_manager);

Http::ConnectionPool::Instance* httpConnPoolForCluster(const std::string&, ResourcePriority,
Expand Down
11 changes: 10 additions & 1 deletion source/server/config_validation/server.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#include "server/config_validation/server.h"

#include "common/protobuf/utility.h"

#include "server/configuration_impl.h"

#include "api/bootstrap.pb.h"

namespace Envoy {
namespace Server {

Expand Down Expand Up @@ -50,6 +54,11 @@ void ValidationInstance::initialize(Options& options, ComponentFactory& componen
// If we get all the way through that stripped-down initialization flow, to the point where we'd
// be ready to serve, then the config has passed validation.
Json::ObjectSharedPtr config_json = Json::Factory::loadFromFile(options.configPath());
envoy::api::v2::Bootstrap bootstrap;
if (!options.bootstrapPath().empty()) {
MessageUtil::loadFromFile(options.bootstrapPath(), bootstrap);
}

Configuration::InitialImpl initial_config(*config_json);
thread_local_.registerThread(*dispatcher_, true);
runtime_loader_ = component_factory.createRuntime(*this, initial_config);
Expand All @@ -60,7 +69,7 @@ void ValidationInstance::initialize(Options& options, ComponentFactory& componen

Configuration::MainImpl* main_config = new Configuration::MainImpl();
config_.reset(main_config);
main_config->initialize(*config_json, *this, *cluster_manager_factory_);
main_config->initialize(*config_json, bootstrap, *this, *cluster_manager_factory_);

clusterManager().setInitializedCb(
[this]() -> void { init_manager_.initialize([]() -> void {}); });
Expand Down
7 changes: 4 additions & 3 deletions source/server/configuration_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@ bool FilterChainUtility::buildFilterChain(Network::FilterManager& filter_manager
return filter_manager.initializeReadFilters();
}

void MainImpl::initialize(const Json::Object& json, Instance& server,
void MainImpl::initialize(const Json::Object& json, const envoy::api::v2::Bootstrap& bootstrap,
Instance& server,
Upstream::ClusterManagerFactory& cluster_manager_factory) {
cluster_manager_ = cluster_manager_factory.clusterManagerFromJson(
*json.getObject("cluster_manager"), server.stats(), server.threadLocal(), server.runtime(),
server.random(), server.localInfo(), server.accessLogManager());
*json.getObject("cluster_manager"), bootstrap, server.stats(), server.threadLocal(),
server.runtime(), server.random(), server.localInfo(), server.accessLogManager());

std::vector<Json::ObjectSharedPtr> listeners = json.getObjectArray("listeners");
ENVOY_LOG(info, "loading {} listener(s)", listeners.size());
Expand Down
7 changes: 5 additions & 2 deletions source/server/configuration_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

#include "server/lds_api.h"

#include "api/bootstrap.pb.h"

namespace Envoy {
namespace Server {
namespace Configuration {
Expand Down Expand Up @@ -106,11 +108,12 @@ class MainImpl : Logger::Loggable<Logger::Id::config>, public Main {
* will call through the server into the config to get the cluster manager so the config object
* must be created already.
* @param json supplies the configuration JSON.
* @param bootstrap v2 bootstrap proto.
* @param server supplies the owning server.
* @param cluster_manager_factory supplies the cluster manager creation factory.
*/
void initialize(const Json::Object& json, Instance& server,
Upstream::ClusterManagerFactory& cluster_manager_factory);
void initialize(const Json::Object& json, const envoy::api::v2::Bootstrap& bootstrap,
Instance& server, Upstream::ClusterManagerFactory& cluster_manager_factory);

// Server::Configuration::Main
Upstream::ClusterManager& clusterManager() override { return *cluster_manager_; }
Expand Down
Loading