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

Use local_info.node() instead of bootstrap.node() whenever possible #4120

Merged
merged 7 commits into from
Aug 20, 2018
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
9 changes: 5 additions & 4 deletions source/common/config/grpc_mux_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
namespace Envoy {
namespace Config {

GrpcMuxImpl::GrpcMuxImpl(const envoy::api::v2::core::Node& node, Grpc::AsyncClientPtr async_client,
GrpcMuxImpl::GrpcMuxImpl(const LocalInfo::LocalInfo& local_info, Grpc::AsyncClientPtr async_client,
Event::Dispatcher& dispatcher,
const Protobuf::MethodDescriptor& service_method,
Runtime::RandomGenerator& random, MonotonicTimeSource& time_source)
: node_(node), async_client_(std::move(async_client)), service_method_(service_method),
random_(random), time_source_(time_source) {
: local_info_(local_info), async_client_(std::move(async_client)),
service_method_(service_method), random_(random), time_source_(time_source) {
Config::Utility::checkLocalInfo("ads", local_info);
retry_timer_ = dispatcher.createTimer([this]() -> void { establishNewStream(); });
backoff_strategy_ = std::make_unique<JitteredBackOffStrategy>(RETRY_INITIAL_DELAY_MS,
RETRY_MAX_DELAY_MS, random_);
Expand Down Expand Up @@ -114,7 +115,7 @@ GrpcMuxWatchPtr GrpcMuxImpl::subscribe(const std::string& type_url,
// Bucket contains 1 token maximum and refills 1 token on every ~5 seconds.
api_state_[type_url].limit_log_ = std::make_unique<TokenBucketImpl>(1, 0.2, time_source_);
api_state_[type_url].request_.set_type_url(type_url);
api_state_[type_url].request_.mutable_node()->MergeFrom(node_);
api_state_[type_url].request_.mutable_node()->MergeFrom(local_info_.node());
api_state_[type_url].subscribed_ = true;
subscriptions_.emplace_back(type_url);
}
Expand Down
4 changes: 2 additions & 2 deletions source/common/config/grpc_mux_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class GrpcMuxImpl : public GrpcMux,
Grpc::TypedAsyncStreamCallbacks<envoy::api::v2::DiscoveryResponse>,
Logger::Loggable<Logger::Id::upstream> {
public:
GrpcMuxImpl(const envoy::api::v2::core::Node& node, Grpc::AsyncClientPtr async_client,
GrpcMuxImpl(const LocalInfo::LocalInfo& local_info, Grpc::AsyncClientPtr async_client,
Event::Dispatcher& dispatcher, const Protobuf::MethodDescriptor& service_method,
Runtime::RandomGenerator& random,
MonotonicTimeSource& time_source = ProdMonotonicTimeSource::instance_);
Expand Down Expand Up @@ -95,7 +95,7 @@ class GrpcMuxImpl : public GrpcMux,
TokenBucketPtr limit_log_;
};

envoy::api::v2::core::Node node_;
const LocalInfo::LocalInfo& local_info_;
Grpc::AsyncClientPtr async_client_;
Grpc::AsyncStream* stream_{};
const Protobuf::MethodDescriptor& service_method_;
Expand Down
4 changes: 2 additions & 2 deletions source/common/config/grpc_subscription_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ namespace Config {
template <class ResourceType>
class GrpcSubscriptionImpl : public Config::Subscription<ResourceType> {
public:
GrpcSubscriptionImpl(const envoy::api::v2::core::Node& node, Grpc::AsyncClientPtr async_client,
GrpcSubscriptionImpl(const LocalInfo::LocalInfo& local_info, Grpc::AsyncClientPtr async_client,
Event::Dispatcher& dispatcher, Runtime::RandomGenerator& random,
const Protobuf::MethodDescriptor& service_method, SubscriptionStats stats)
: grpc_mux_(node, std::move(async_client), dispatcher, service_method, random),
: grpc_mux_(local_info, std::move(async_client), dispatcher, service_method, random),
grpc_mux_subscription_(grpc_mux_, stats) {}

// Config::Subscription
Expand Down
4 changes: 2 additions & 2 deletions source/common/config/http_subscription_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ class HttpSubscriptionImpl : public Http::RestApiFetcher,
public Config::Subscription<ResourceType>,
Logger::Loggable<Logger::Id::config> {
public:
HttpSubscriptionImpl(const envoy::api::v2::core::Node& node, Upstream::ClusterManager& cm,
HttpSubscriptionImpl(const LocalInfo::LocalInfo& local_info, Upstream::ClusterManager& cm,
const std::string& remote_cluster_name, Event::Dispatcher& dispatcher,
Runtime::RandomGenerator& random, std::chrono::milliseconds refresh_interval,
std::chrono::milliseconds request_timeout,
const Protobuf::MethodDescriptor& service_method, SubscriptionStats stats)
: Http::RestApiFetcher(cm, remote_cluster_name, dispatcher, random, refresh_interval,
request_timeout),
stats_(stats) {
request_.mutable_node()->CopyFrom(node);
request_.mutable_node()->CopyFrom(local_info.node());
ASSERT(service_method.options().HasExtension(google::api::http));
const auto& http_rule = service_method.options().GetExtension(google::api::http);
path_ = http_rule.post();
Expand Down
8 changes: 4 additions & 4 deletions source/common/config/subscription_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class SubscriptionFactory {
/**
* Subscription factory.
* @param config envoy::api::v2::core::ConfigSource to construct from.
* @param node envoy::api::v2::core::Node identifier.
* @param local_info LocalInfo::LocalInfo local info.
* @param dispatcher event dispatcher.
* @param cm cluster manager for async clients (when REST/gRPC).
* @param random random generator for jittering polling delays (when REST).
Expand All @@ -37,7 +37,7 @@ class SubscriptionFactory {
*/
template <class ResourceType>
static std::unique_ptr<Subscription<ResourceType>> subscriptionFromConfigSource(
const envoy::api::v2::core::ConfigSource& config, const envoy::api::v2::core::Node& node,
const envoy::api::v2::core::ConfigSource& config, const LocalInfo::LocalInfo& local_info,
Event::Dispatcher& dispatcher, Upstream::ClusterManager& cm, Runtime::RandomGenerator& random,
Stats::Scope& scope, std::function<Subscription<ResourceType>*()> rest_legacy_constructor,
const std::string& rest_method, const std::string& grpc_method) {
Expand All @@ -59,14 +59,14 @@ class SubscriptionFactory {
break;
case envoy::api::v2::core::ApiConfigSource::REST:
result.reset(new HttpSubscriptionImpl<ResourceType>(
node, cm, api_config_source.cluster_names()[0], dispatcher, random,
local_info, cm, api_config_source.cluster_names()[0], dispatcher, random,
Utility::apiConfigSourceRefreshDelay(api_config_source),
Utility::apiConfigSourceRequestTimeout(api_config_source),
*Protobuf::DescriptorPool::generated_pool()->FindMethodByName(rest_method), stats));
break;
case envoy::api::v2::core::ApiConfigSource::GRPC: {
result.reset(new GrpcSubscriptionImpl<ResourceType>(
node,
local_info,
Config::Utility::factoryForGrpcApiConfigSource(cm.grpcAsyncClientManager(),
config.api_config_source(), scope)
->create(),
Expand Down
4 changes: 3 additions & 1 deletion source/common/config/utility.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ void Utility::checkLocalInfo(const std::string& error_prefix,
const LocalInfo::LocalInfo& local_info) {
if (local_info.clusterName().empty() || local_info.nodeName().empty()) {
throw EnvoyException(
fmt::format("{}: setting --service-cluster and --service-node is required", error_prefix));
fmt::format("{}: node 'id' and 'cluster' are required. Set it either in 'node' config or "
"via --service-node and --service-cluster options.",
error_prefix, local_info.node().DebugString()));
}
}

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 @@ -70,7 +70,7 @@ RdsRouteConfigSubscription::RdsRouteConfigSubscription(

subscription_ = Envoy::Config::SubscriptionFactory::subscriptionFromConfigSource<
envoy::api::v2::RouteConfiguration>(
rds.config_source(), factory_context.localInfo().node(), factory_context.dispatcher(),
rds.config_source(), factory_context.localInfo(), factory_context.dispatcher(),
factory_context.clusterManager(), factory_context.random(), *scope_,
[this, &rds,
&factory_context]() -> Envoy::Config::Subscription<envoy::api::v2::RouteConfiguration>* {
Expand Down
2 changes: 1 addition & 1 deletion source/common/upstream/cds_api_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ CdsApiImpl::CdsApiImpl(const envoy::api::v2::core::ConfigSource& cds_config,

subscription_ =
Config::SubscriptionFactory::subscriptionFromConfigSource<envoy::api::v2::Cluster>(
cds_config, local_info.node(), dispatcher, cm, random, *scope_,
cds_config, local_info, dispatcher, cm, random, *scope_,
[this, &cds_config, &eds_config, &cm, &dispatcher, &random, &local_info,
&scope]() -> Config::Subscription<envoy::api::v2::Cluster>* {
return new CdsSubscription(Config::Utility::generateStats(*scope_), cds_config,
Expand Down
4 changes: 2 additions & 2 deletions source/common/upstream/cluster_manager_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ ClusterManagerImpl::ClusterManagerImpl(const envoy::config::bootstrap::v2::Boots
// Now setup ADS if needed, this might rely on a primary cluster.
if (bootstrap.dynamic_resources().has_ads_config()) {
ads_mux_.reset(new Config::GrpcMuxImpl(
bootstrap.node(),
local_info,
Copy link
Member

Choose a reason for hiding this comment

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

I have mixed opinions on this change. On the one hand, we make it more full proof, by forcing the LocalInfo type. On the other, we are now passing a strict superset of what we were passing before, and the new information is not used. My main thoughts on making LocalInfo canonical would be to just delete the node info from bootstrap very early in server init. But, this approach also works..

Copy link
Member Author

Choose a reason for hiding this comment

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

Interesting POV, will try to explore that too.

Copy link
Member

Choose a reason for hiding this comment

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

It's not necessarily the correct PoV; just sharing where my thinking was originally :)

Config::Utility::factoryForGrpcApiConfigSource(
*async_client_manager_, bootstrap.dynamic_resources().ads_config(), stats)
->create(),
Expand Down Expand Up @@ -301,7 +301,7 @@ ClusterManagerImpl::ClusterManagerImpl(const envoy::config::bootstrap::v2::Boots
if (cm_config.has_load_stats_config()) {
const auto& load_stats_config = cm_config.load_stats_config();
load_stats_reporter_.reset(
new LoadStatsReporter(bootstrap.node(), *this, stats,
new LoadStatsReporter(local_info, *this, stats,
Config::Utility::factoryForGrpcApiConfigSource(
*async_client_manager_, load_stats_config, stats)
->create(),
Expand Down
2 changes: 1 addition & 1 deletion source/common/upstream/eds.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ EdsClusterImpl::EdsClusterImpl(
Upstream::ClusterManager& cm = factory_context.clusterManager();
subscription_ = Config::SubscriptionFactory::subscriptionFromConfigSource<
envoy::api::v2::ClusterLoadAssignment>(
eds_config, local_info_.node(), dispatcher, cm, random, info_->statsScope(),
eds_config, local_info_, dispatcher, cm, random, info_->statsScope(),
[this, &eds_config, &cm, &dispatcher,
&random]() -> Config::Subscription<envoy::api::v2::ClusterLoadAssignment>* {
return new SdsSubscription(info_->stats(), eds_config, cm, dispatcher, random);
Expand Down
4 changes: 2 additions & 2 deletions source/common/upstream/load_stats_reporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace Envoy {
namespace Upstream {

LoadStatsReporter::LoadStatsReporter(const envoy::api::v2::core::Node& node,
LoadStatsReporter::LoadStatsReporter(const LocalInfo::LocalInfo& local_info,
ClusterManager& cluster_manager, Stats::Scope& scope,
Grpc::AsyncClientPtr async_client,
Event::Dispatcher& dispatcher,
Expand All @@ -18,7 +18,7 @@ LoadStatsReporter::LoadStatsReporter(const envoy::api::v2::core::Node& node,
service_method_(*Protobuf::DescriptorPool::generated_pool()->FindMethodByName(
"envoy.service.load_stats.v2.LoadReportingService.StreamLoadStats")),
time_source_(time_source) {
request_.mutable_node()->MergeFrom(node);
request_.mutable_node()->MergeFrom(local_info.node());
retry_timer_ = dispatcher.createTimer([this]() -> void { establishNewStream(); });
response_timer_ = dispatcher.createTimer([this]() -> void { sendLoadStatsRequest(); });
establishNewStream();
Expand Down
2 changes: 1 addition & 1 deletion source/common/upstream/load_stats_reporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class LoadStatsReporter
: Grpc::TypedAsyncStreamCallbacks<envoy::service::load_stats::v2::LoadStatsResponse>,
Logger::Loggable<Logger::Id::upstream> {
public:
LoadStatsReporter(const envoy::api::v2::core::Node& node, ClusterManager& cluster_manager,
LoadStatsReporter(const LocalInfo::LocalInfo& local_info, ClusterManager& cluster_manager,
Stats::Scope& scope, Grpc::AsyncClientPtr async_client,
Event::Dispatcher& dispatcher, MonotonicTimeSource& time_source);

Expand Down
2 changes: 1 addition & 1 deletion source/server/lds_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ LdsApiImpl::LdsApiImpl(const envoy::api::v2::core::ConfigSource& lds_config,
: listener_manager_(lm), scope_(scope.createScope("listener_manager.lds.")), cm_(cm) {
subscription_ =
Envoy::Config::SubscriptionFactory::subscriptionFromConfigSource<envoy::api::v2::Listener>(
lds_config, local_info.node(), dispatcher, cm, random, *scope_,
lds_config, local_info, dispatcher, cm, random, *scope_,
[this, &lds_config, &cm, &dispatcher, &random, &local_info,
&scope]() -> Config::Subscription<envoy::api::v2::Listener>* {
return new LdsSubscription(Config::Utility::generateStats(*scope_), lds_config, cm,
Expand Down
4 changes: 4 additions & 0 deletions test/common/config/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ envoy_cc_test(
"//test/mocks/config:config_mocks",
"//test/mocks/event:event_mocks",
"//test/mocks/grpc:grpc_mocks",
"//test/mocks/local_info:local_info_mocks",
"//test/mocks/runtime:runtime_mocks",
"//test/test_common:logging_lib",
"//test/test_common:utility_lib",
Expand Down Expand Up @@ -75,6 +76,7 @@ envoy_cc_test_library(
"//test/mocks/config:config_mocks",
"//test/mocks/event:event_mocks",
"//test/mocks/grpc:grpc_mocks",
"//test/mocks/local_info:local_info_mocks",
"//test/mocks/upstream:upstream_mocks",
"//test/test_common:utility_lib",
"@envoy_api//envoy/api/v2:eds_cc",
Expand All @@ -101,6 +103,7 @@ envoy_cc_test_library(
"//source/common/http:message_lib",
"//test/mocks/config:config_mocks",
"//test/mocks/event:event_mocks",
"//test/mocks/local_info:local_info_mocks",
"//test/mocks/runtime:runtime_mocks",
"//test/mocks/upstream:upstream_mocks",
"//test/test_common:utility_lib",
Expand All @@ -116,6 +119,7 @@ envoy_cc_test(
"//test/mocks/config:config_mocks",
"//test/mocks/event:event_mocks",
"//test/mocks/filesystem:filesystem_mocks",
"//test/mocks/local_info:local_info_mocks",
"//test/mocks/runtime:runtime_mocks",
"//test/mocks/stats:stats_mocks",
"//test/mocks/upstream:upstream_mocks",
Expand Down
Loading