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

xDS: type url aggregation #9649

Merged
merged 15 commits into from
Mar 18, 2020
20 changes: 20 additions & 0 deletions include/envoy/config/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,23 @@ envoy_cc_library(
"//source/common/protobuf",
],
)

envoy_cc_library(
name = "discovery_service_base_interface",
hdrs = ["discovery_service_base.h"],
deps = [
":subscription_interface",
"//source/common/protobuf",
"@envoy_api//envoy/api/v2:pkg_cc_proto",
Shikugawa marked this conversation as resolved.
Show resolved Hide resolved
"@envoy_api//envoy/api/v2/auth:pkg_cc_proto",
"@envoy_api//envoy/api/v2/route:pkg_cc_proto",
"@envoy_api//envoy/config/cluster/v3:pkg_cc_proto",
"@envoy_api//envoy/config/core/v3:pkg_cc_proto",
"@envoy_api//envoy/config/endpoint/v3:pkg_cc_proto",
"@envoy_api//envoy/config/listener/v3:pkg_cc_proto",
"@envoy_api//envoy/config/route/v3:pkg_cc_proto",
"@envoy_api//envoy/extensions/transport_sockets/tls/v3:pkg_cc_proto",
"@envoy_api//envoy/service/discovery/v2:pkg_cc_proto",
"@envoy_api//envoy/service/runtime/v3:pkg_cc_proto",
],
)
60 changes: 60 additions & 0 deletions include/envoy/config/discovery_service_base.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#pragma once

#include <string>

#include "envoy/api/v2/auth/cert.pb.h"
#include "envoy/api/v2/cluster.pb.h"
#include "envoy/api/v2/endpoint.pb.h"
#include "envoy/api/v2/listener.pb.h"
#include "envoy/api/v2/rds.pb.h"
#include "envoy/api/v2/route/route_components.pb.h"
#include "envoy/api/v2/scoped_route.pb.h"
#include "envoy/config/cluster/v3/cluster.pb.h"
#include "envoy/config/core/v3/config_source.pb.h"
#include "envoy/config/discovery_service_base.h"
#include "envoy/config/endpoint/v3/endpoint.pb.h"
#include "envoy/config/listener/v3/listener.pb.h"
#include "envoy/config/route/v3/route.pb.h"
#include "envoy/config/route/v3/route_components.pb.h"
#include "envoy/config/route/v3/scoped_route.pb.h"
#include "envoy/config/subscription.h"
#include "envoy/extensions/transport_sockets/tls/v3/cert.pb.h"
#include "envoy/service/discovery/v2/rtds.pb.h"
#include "envoy/service/runtime/v3/rtds.pb.h"

namespace Envoy {
namespace Config {
template <typename Prev, typename Current>
struct SubscriptionBase : public Config::SubscriptionCallbacks {
static std::string getResourceName(envoy::config::core::v3::ApiVersion resource_api_version) {
switch (resource_api_version) {
case envoy::config::core::v3::ApiVersion::AUTO:
case envoy::config::core::v3::ApiVersion::V2:
return Prev().GetDescriptor()->full_name();
case envoy::config::core::v3::ApiVersion::V3:
return Current().GetDescriptor()->full_name();
default:
NOT_REACHED_GCOVR_EXCL_LINE;
}
}
};
using RdsRouteConfigSubscriptionBase =
SubscriptionBase<envoy::api::v2::RouteConfiguration,
Shikugawa marked this conversation as resolved.
Show resolved Hide resolved
envoy::config::route::v3::RouteConfiguration>;
using RtdsSubscriptionBase =
SubscriptionBase<envoy::service::discovery::v2::Runtime, envoy::service::runtime::v3::Runtime>;
using ScopedRdsConfigSubscriptionBase =
SubscriptionBase<envoy::api::v2::ScopedRouteConfiguration,
envoy::config::route::v3::ScopedRouteConfiguration>;
using VhdsSubscriptionBase =
SubscriptionBase<envoy::api::v2::route::VirtualHost, envoy::service::runtime::v3::Runtime>;
using SdsApiBase = SubscriptionBase<envoy::api::v2::auth::Secret,
envoy::extensions::transport_sockets::tls::v3::Secret>;
using CdsApiBase = SubscriptionBase<envoy::api::v2::Cluster, envoy::config::cluster::v3::Cluster>;
using EdsClusterBase = SubscriptionBase<envoy::api::v2::ClusterLoadAssignment,
envoy::config::endpoint::v3::ClusterLoadAssignment>;
using LdsApiBase =
SubscriptionBase<envoy::api::v2::Listener, envoy::config::listener::v3::Listener>;

} // namespace Config
} // namespace Envoy
1 change: 1 addition & 0 deletions include/envoy/upstream/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ envoy_cc_library(
":locality_lib",
":resource_manager_interface",
"//include/envoy/common:callback",
"//include/envoy/config:subscription_interface",
"//include/envoy/config:typed_metadata_interface",
"//include/envoy/http:codec_interface",
"//include/envoy/network:connection_interface",
Expand Down
3 changes: 3 additions & 0 deletions source/common/router/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ envoy_cc_library(
hdrs = ["vhds.h"],
deps = [
":config_lib",
"//include/envoy/config:discovery_service_base_interface",
"//include/envoy/config:subscription_interface",
"//include/envoy/http:codes_interface",
"//include/envoy/local_info:local_info_interface",
Expand Down Expand Up @@ -148,6 +149,7 @@ envoy_cc_library(
hdrs = ["rds_impl.h"],
deps = [
":config_lib",
"//include/envoy/config:discovery_service_base_interface",
"//include/envoy/config:subscription_interface",
"//include/envoy/http:codes_interface",
"//include/envoy/local_info:local_info_interface",
Expand Down Expand Up @@ -205,6 +207,7 @@ envoy_cc_library(
":rds_lib",
":scoped_config_lib",
"//include/envoy/config:config_provider_interface",
"//include/envoy/config:discovery_service_base_interface",
"//include/envoy/config:subscription_interface",
"//include/envoy/router:route_config_provider_manager_interface",
"//include/envoy/stats:stats_interface",
Expand Down
21 changes: 2 additions & 19 deletions source/common/router/rds_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,10 @@ RdsRouteConfigSubscription::RdsRouteConfigSubscription(
stat_prefix_(stat_prefix), stats_({ALL_RDS_STATS(POOL_COUNTER(*scope_))}),
route_config_provider_manager_(route_config_provider_manager),
manager_identifier_(manager_identifier) {

const auto resource_name = getResourceName(rds.config_source().resource_api_version());
subscription_ =
factory_context.clusterManager().subscriptionFactory().subscriptionFromConfigSource(
rds.config_source(), loadTypeUrl(rds.config_source().resource_api_version()), *scope_,
*this);
rds.config_source(), Grpc::Common::typeUrl(API_NO_BOOST(resource_name)), *scope_, *this);
Shikugawa marked this conversation as resolved.
Show resolved Hide resolved
config_update_info_ =
std::make_unique<RouteConfigUpdateReceiverImpl>(factory_context.timeSource(), validator);
}
Expand Down Expand Up @@ -217,22 +216,6 @@ bool RdsRouteConfigSubscription::validateUpdateSize(int num_resources) {
return true;
}

std::string
RdsRouteConfigSubscription::loadTypeUrl(envoy::config::core::v3::ApiVersion resource_api_version) {
switch (resource_api_version) {
// automatically set api version as V2
case envoy::config::core::v3::ApiVersion::AUTO:
case envoy::config::core::v3::ApiVersion::V2:
return Grpc::Common::typeUrl(
API_NO_BOOST(envoy::api::v2::RouteConfiguration().GetDescriptor()->full_name()));
case envoy::config::core::v3::ApiVersion::V3:
return Grpc::Common::typeUrl(
API_NO_BOOST(envoy::config::route::v3::RouteConfiguration().GetDescriptor()->full_name()));
default:
NOT_REACHED_GCOVR_EXCL_LINE;
}
}

RdsRouteConfigProviderImpl::RdsRouteConfigProviderImpl(
RdsRouteConfigSubscriptionSharedPtr&& subscription,
Server::Configuration::FactoryContext& factory_context)
Expand Down
4 changes: 1 addition & 3 deletions source/common/router/rds_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class RdsRouteConfigProviderImpl;
* A class that fetches the route configuration dynamically using the RDS API and updates them to
* RDS config providers.
*/
class RdsRouteConfigSubscription : Envoy::Config::SubscriptionCallbacks,
class RdsRouteConfigSubscription : Envoy::Config::RdsRouteConfigSubscriptionBase,
Logger::Loggable<Logger::Id::router> {
public:
~RdsRouteConfigSubscription() override;
Expand Down Expand Up @@ -151,8 +151,6 @@ class RdsRouteConfigSubscription : Envoy::Config::SubscriptionCallbacks,
RouteConfigProviderManagerImpl& route_config_provider_manager);

bool validateUpdateSize(int num_resources);
static std::string loadTypeUrl(envoy::config::core::v3::ApiVersion resource_api_version);

Init::Manager& getRdsConfigInitManager() { return init_manager_; }

std::unique_ptr<Envoy::Config::Subscription> subscription_;
Expand Down
22 changes: 4 additions & 18 deletions source/common/router/scoped_rds.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "common/config/version_converter.h"
#include "common/init/manager_impl.h"
#include "common/init/watcher_impl.h"
#include "common/router/rds_impl.h"

#include "absl/strings/str_join.h"

Expand Down Expand Up @@ -104,10 +105,11 @@ ScopedRdsConfigSubscription::ScopedRdsConfigSubscription(
rds_config_source_(std::move(rds_config_source)),
validation_visitor_(factory_context.messageValidationVisitor()), stat_prefix_(stat_prefix),
route_config_provider_manager_(route_config_provider_manager) {
const auto resource_name = getResourceName(rds_config_source_.resource_api_version());
subscription_ =
factory_context.clusterManager().subscriptionFactory().subscriptionFromConfigSource(
scoped_rds.scoped_rds_config_source(),
loadTypeUrl(rds_config_source_.resource_api_version()), *scope_, *this);
scoped_rds.scoped_rds_config_source(), Grpc::Common::typeUrl(API_NO_BOOST(resource_name)),
*scope_, *this);

initialize([scope_key_builder]() -> Envoy::Config::ConfigProvider::ConfigConstSharedPtr {
return std::make_shared<ScopedConfigImpl>(
Expand Down Expand Up @@ -347,22 +349,6 @@ void ScopedRdsConfigSubscription::onConfigUpdate(
onConfigUpdate(to_add_repeated, to_remove_repeated, version_info);
}

std::string
ScopedRdsConfigSubscription::loadTypeUrl(envoy::config::core::v3::ApiVersion resource_api_version) {
switch (resource_api_version) {
// automatically set api version as V2
case envoy::config::core::v3::ApiVersion::AUTO:
case envoy::config::core::v3::ApiVersion::V2:
return Grpc::Common::typeUrl(
API_NO_BOOST(envoy::api::v2::ScopedRouteConfiguration().GetDescriptor()->full_name()));
case envoy::config::core::v3::ApiVersion::V3:
return Grpc::Common::typeUrl(API_NO_BOOST(
envoy::config::route::v3::ScopedRouteConfiguration().GetDescriptor()->full_name()));
default:
NOT_REACHED_GCOVR_EXCL_LINE;
}
}

ScopedRdsConfigProvider::ScopedRdsConfigProvider(
ScopedRdsConfigSubscriptionSharedPtr&& subscription)
: MutableConfigProviderCommonBase(std::move(subscription), ConfigProvider::ApiType::Delta) {}
Expand Down
4 changes: 2 additions & 2 deletions source/common/router/scoped_rds.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "envoy/common/callback.h"
#include "envoy/config/core/v3/config_source.pb.h"
#include "envoy/config/discovery_service_base.h"
#include "envoy/config/route/v3/scoped_route.pb.h"
#include "envoy/config/subscription.h"
#include "envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.pb.h"
Expand Down Expand Up @@ -85,7 +86,7 @@ struct ScopedRdsStats {

// A scoped RDS subscription to be used with the dynamic scoped RDS ConfigProvider.
class ScopedRdsConfigSubscription : public Envoy::Config::DeltaConfigSubscriptionInstance,
Envoy::Config::SubscriptionCallbacks {
Envoy::Config::ScopedRdsConfigSubscriptionBase {
public:
using ScopedRouteConfigurationMap =
std::map<std::string, envoy::config::route::v3::ScopedRouteConfiguration>;
Expand Down Expand Up @@ -163,7 +164,6 @@ class ScopedRdsConfigSubscription : public Envoy::Config::DeltaConfigSubscriptio
return MessageUtil::anyConvert<envoy::config::route::v3::ScopedRouteConfiguration>(resource)
.name();
}
static std::string loadTypeUrl(envoy::config::core::v3::ApiVersion resource_api_version);
// Propagate RDS updates to ScopeConfigImpl in workers.
void onRdsConfigUpdate(const std::string& scope_name,
RdsRouteConfigSubscription& rds_subscription);
Expand Down
19 changes: 2 additions & 17 deletions source/common/router/vhds.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ VhdsSubscription::VhdsSubscription(RouteConfigUpdatePtr& config_update_info,
if (config_source != envoy::config::core::v3::ApiConfigSource::DELTA_GRPC) {
throw EnvoyException("vhds: only 'DELTA_GRPC' is supported as an api_type.");
}

const auto resource_name = getResourceName(resource_api_version);
subscription_ =
factory_context.clusterManager().subscriptionFactory().subscriptionFromConfigSource(
config_update_info_->routeConfiguration().vhds().config_source(),
loadTypeUrl(resource_api_version), *scope_, *this);
Grpc::Common::typeUrl(API_NO_BOOST(resource_name)), *scope_, *this);
}

void VhdsSubscription::updateOnDemand(const std::string& with_route_config_name_prefix) {
Expand Down Expand Up @@ -75,20 +75,5 @@ void VhdsSubscription::onConfigUpdate(
init_target_.ready();
}

std::string
VhdsSubscription::loadTypeUrl(envoy::config::core::v3::ApiVersion resource_api_version) {
switch (resource_api_version) {
// automatically set api version as V2
case envoy::config::core::v3::ApiVersion::AUTO:
case envoy::config::core::v3::ApiVersion::V2:
return Grpc::Common::typeUrl(
API_NO_BOOST(envoy::api::v2::route::VirtualHost().GetDescriptor()->full_name()));
case envoy::config::core::v3::ApiVersion::V3:
return Grpc::Common::typeUrl(
API_NO_BOOST(envoy::api::v2::route::VirtualHost().GetDescriptor()->full_name()));
default:
NOT_REACHED_GCOVR_EXCL_LINE;
}
}
} // namespace Router
} // namespace Envoy
5 changes: 2 additions & 3 deletions source/common/router/vhds.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <unordered_set>

#include "envoy/config/core/v3/config_source.pb.h"
#include "envoy/config/discovery_service_base.h"
#include "envoy/config/route/v3/route_components.pb.h"
#include "envoy/config/subscription.h"
#include "envoy/http/codes.h"
Expand Down Expand Up @@ -34,8 +35,7 @@ struct VhdsStats {
ALL_VHDS_STATS(GENERATE_COUNTER_STRUCT)
};

class VhdsSubscription : Envoy::Config::SubscriptionCallbacks,
Logger::Loggable<Logger::Id::router> {
class VhdsSubscription : Envoy::Config::VhdsSubscriptionBase, Logger::Loggable<Logger::Id::router> {
public:
VhdsSubscription(RouteConfigUpdatePtr& config_update_info,
Server::Configuration::ServerFactoryContext& factory_context,
Expand Down Expand Up @@ -69,7 +69,6 @@ class VhdsSubscription : Envoy::Config::SubscriptionCallbacks,
std::string resourceName(const ProtobufWkt::Any& resource) override {
return MessageUtil::anyConvert<envoy::config::route::v3::VirtualHost>(resource).name();
}
static std::string loadTypeUrl(envoy::config::core::v3::ApiVersion resource_api_version);

RouteConfigUpdatePtr& config_update_info_;
Stats::ScopePtr scope_;
Expand Down
1 change: 1 addition & 0 deletions source/common/runtime/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ envoy_cc_library(
external_deps = ["ssl"],
deps = [
":runtime_features_lib",
"//include/envoy/config:discovery_service_base_interface",
"//include/envoy/config:subscription_interface",
"//include/envoy/event:dispatcher_interface",
"//include/envoy/init:manager_interface",
Expand Down
19 changes: 2 additions & 17 deletions source/common/runtime/runtime_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -589,8 +589,9 @@ void RtdsSubscription::start() {
// We have to delay the subscription creation until init-time, since the
// cluster manager resources are not available in the constructor when
// instantiated in the server instance.
const auto resource_name = getResourceName(config_source_.resource_api_version());
subscription_ = parent_.cm_->subscriptionFactory().subscriptionFromConfigSource(
config_source_, loadTypeUrl(config_source_.resource_api_version()), store_, *this);
config_source_, Grpc::Common::typeUrl(API_NO_BOOST(resource_name)), store_, *this);
subscription_->start({resource_name_});
}

Expand All @@ -602,22 +603,6 @@ void RtdsSubscription::validateUpdateSize(uint32_t num_resources) {
}
}

std::string
RtdsSubscription::loadTypeUrl(envoy::config::core::v3::ApiVersion resource_api_version) {
switch (resource_api_version) {
// automatically set api version as V2
case envoy::config::core::v3::ApiVersion::AUTO:
case envoy::config::core::v3::ApiVersion::V2:
return Grpc::Common::typeUrl(
API_NO_BOOST(envoy::service::discovery::v2::Runtime().GetDescriptor()->full_name()));
case envoy::config::core::v3::ApiVersion::V3:
return Grpc::Common::typeUrl(
API_NO_BOOST(envoy::service::runtime::v3::Runtime().GetDescriptor()->full_name()));
default:
NOT_REACHED_GCOVR_EXCL_LINE;
}
}

void LoaderImpl::loadNewSnapshot() {
std::shared_ptr<SnapshotImpl> ptr = createNewSnapshot();
tls_->set([ptr](Event::Dispatcher&) -> ThreadLocal::ThreadLocalObjectSharedPtr {
Expand Down
4 changes: 2 additions & 2 deletions source/common/runtime/runtime_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "envoy/common/exception.h"
#include "envoy/config/bootstrap/v3/bootstrap.pb.h"
#include "envoy/config/core/v3/config_source.pb.h"
#include "envoy/config/discovery_service_base.h"
#include "envoy/config/subscription.h"
#include "envoy/init/manager.h"
#include "envoy/runtime/runtime.h"
Expand Down Expand Up @@ -201,7 +202,7 @@ class ProtoLayer : public OverrideLayerImpl, Logger::Loggable<Logger::Id::runtim

class LoaderImpl;

struct RtdsSubscription : Config::SubscriptionCallbacks, Logger::Loggable<Logger::Id::runtime> {
struct RtdsSubscription : Config::RtdsSubscriptionBase, Logger::Loggable<Logger::Id::runtime> {
RtdsSubscription(LoaderImpl& parent,
const envoy::config::bootstrap::v3::RuntimeLayer::RtdsLayer& rtds_layer,
Stats::Store& store, ProtobufMessage::ValidationVisitor& validation_visitor);
Expand All @@ -222,7 +223,6 @@ struct RtdsSubscription : Config::SubscriptionCallbacks, Logger::Loggable<Logger

void start();
void validateUpdateSize(uint32_t num_resources);
static std::string loadTypeUrl(envoy::config::core::v3::ApiVersion resource_api_version);

LoaderImpl& parent_;
const envoy::config::core::v3::ConfigSource config_source_;
Expand Down
1 change: 1 addition & 0 deletions source/common/secret/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ envoy_cc_library(
srcs = ["sds_api.cc"],
hdrs = ["sds_api.h"],
deps = [
"//include/envoy/config:discovery_service_base_interface",
"//include/envoy/config:subscription_factory_interface",
"//include/envoy/config:subscription_interface",
"//include/envoy/event:dispatcher_interface",
Expand Down
Loading