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
16 changes: 15 additions & 1 deletion api/envoy/api/v2/core/config_source.proto
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,19 @@ message RateLimitSettings {
// <arch_overview_service_discovery>` etc. may either be sourced from the
// filesystem or from an xDS API source. Filesystem configs are watched with
// inotify for updates.
// [#next-free-field: 6]
// [#next-free-field: 7]
message ConfigSource {
enum XdsApiVersion {
// set api version automatically, default version is set as v2.

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.

I'm wondering whether this should be match the version of ConfigSource, i.e. if the type is v3alpha.ConfigSource, use v3alpha. WDYT @htuch?

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.

Making it explicit (as done in this PR) has the advantage that we can support mixed v2/v3 configurations, e.g. LDS loads from a v3 server but RDS comes from v2. We may get into a situation where a v3 Listener one day is expecting to have some v3-related route table delivered, but I think we can enforce these through consistency checking at config ingestion, the general case is that we support mixed.

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.

To be clear, I meant this for AUTO, we should definitely keep the rest of options explicit.

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.

Yeah, I think that would be reasonable semantics.

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.

I think let's just say that it's V2 for now, it would be ideal to have folks specifically exactly what they are after going forward, and this will encourage that.

AUTO = 0;

// use xDS v2 API
V2 = 1;

// use xDS v3alpha API
V3ALPHA = 2;
}

oneof config_source_specifier {
option (validate.required) = true;

Expand Down Expand Up @@ -149,4 +160,7 @@ message ConfigSource {
// means no timeout - Envoy will wait indefinitely for the first xDS config (unless another
// timeout applies). The default is 15s.
google.protobuf.Duration initial_fetch_timeout = 4;

// API version for xDS endpoint
XdsApiVersion version = 6;
}
16 changes: 15 additions & 1 deletion api/envoy/api/v3alpha/core/config_source.proto
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,21 @@ message RateLimitSettings {
// <arch_overview_service_discovery>` etc. may either be sourced from the
// filesystem or from an xDS API source. Filesystem configs are watched with
// inotify for updates.
// [#next-free-field: 6]
// [#next-free-field: 7]
message ConfigSource {
option (udpa.annotations.versioning).previous_message_type = "envoy.api.v2.core.ConfigSource";

enum XdsApiVersion {
// set api version automatically, default version is set as v2.
AUTO = 0;

// use xDS v2 API
V2 = 1;

// use xDS v3alpha API
V3ALPHA = 2;
}

oneof config_source_specifier {
option (validate.required) = true;

Expand Down Expand Up @@ -161,4 +172,7 @@ message ConfigSource {
// means no timeout - Envoy will wait indefinitely for the first xDS config (unless another
// timeout applies). The default is 15s.
google.protobuf.Duration initial_fetch_timeout = 4;

// API version for xDS endpoint
XdsApiVersion version = 6;
Comment thread
Shikugawa marked this conversation as resolved.
Outdated
}
4 changes: 4 additions & 0 deletions source/common/router/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ envoy_cc_library(
"@envoy_api//envoy/api/v2:pkg_cc_proto",
"@envoy_api//envoy/api/v2/core:pkg_cc_proto",
"@envoy_api//envoy/api/v2/route:pkg_cc_proto",
"@envoy_api//envoy/api/v3alpha/route:pkg_cc_proto",
],
)

Expand Down Expand Up @@ -170,6 +171,8 @@ envoy_cc_library(
"//source/common/router:vhds_lib",
"@envoy_api//envoy/admin/v2alpha:pkg_cc_proto",
"@envoy_api//envoy/api/v2:pkg_cc_proto",
"@envoy_api//envoy/api/v2/core:pkg_cc_proto",
"@envoy_api//envoy/api/v3alpha:pkg_cc_proto",
"@envoy_api//envoy/config/filter/network/http_connection_manager/v2:pkg_cc_proto",
],
)
Expand Down Expand Up @@ -211,6 +214,7 @@ envoy_cc_library(
"@envoy_api//envoy/admin/v2alpha:pkg_cc_proto",
"@envoy_api//envoy/api/v2:pkg_cc_proto",
"@envoy_api//envoy/api/v2/core:pkg_cc_proto",
"@envoy_api//envoy/api/v3alpha:pkg_cc_proto",
"@envoy_api//envoy/config/filter/network/http_connection_manager/v2:pkg_cc_proto",
],
)
Expand Down
24 changes: 19 additions & 5 deletions source/common/router/rds_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "envoy/api/v2/discovery.pb.h"
#include "envoy/api/v2/rds.pb.h"
#include "envoy/api/v2/rds.pb.validate.h"
#include "envoy/api/v3alpha/rds.pb.h"
#include "envoy/config/filter/network/http_connection_manager/v2/http_connection_manager.pb.h"

#include "common/common/assert.h"
Expand Down Expand Up @@ -60,21 +61,20 @@ RdsRouteConfigSubscription::RdsRouteConfigSubscription(
const uint64_t manager_identifier, Server::Configuration::ServerFactoryContext& factory_context,
ProtobufMessage::ValidationVisitor& validator, Init::Manager& init_manager,
const std::string& stat_prefix,
Envoy::Router::RouteConfigProviderManagerImpl& route_config_provider_manager)
Envoy::Router::RouteConfigProviderManagerImpl& route_config_provider_manager,
const envoy::api::v2::core::ConfigSource::XdsApiVersion xds_api_version)
: route_config_name_(rds.route_config_name()), factory_context_(factory_context),
validator_(validator), init_manager_(init_manager),
init_target_(fmt::format("RdsRouteConfigSubscription {}", route_config_name_),
[this]() { subscription_->start({route_config_name_}); }),
scope_(factory_context.scope().createScope(stat_prefix + "rds." + route_config_name_ + ".")),
stat_prefix_(stat_prefix), stats_({ALL_RDS_STATS(POOL_COUNTER(*scope_))}),
route_config_provider_manager_(route_config_provider_manager),
manager_identifier_(manager_identifier) {
manager_identifier_(manager_identifier), xds_api_version_(xds_api_version) {

subscription_ =
factory_context.clusterManager().subscriptionFactory().subscriptionFromConfigSource(
rds.config_source(),
Grpc::Common::typeUrl(envoy::api::v2::RouteConfiguration().GetDescriptor()->full_name()),
*scope_, *this);
rds.config_source(), loadTypeUrl(), *scope_, *this);
config_update_info_ =
std::make_unique<RouteConfigUpdateReceiverImpl>(factory_context.timeSource(), validator);
}
Expand Down Expand Up @@ -199,6 +199,20 @@ bool RdsRouteConfigSubscription::validateUpdateSize(int num_resources) {
return true;
}

std::string RdsRouteConfigSubscription::loadTypeUrl() {
switch (xds_api_version_) {
// automatically set api version as V2
case envoy::api::v2::core::ConfigSource::AUTO:
case envoy::api::v2::core::ConfigSource::V2:
return Grpc::Common::typeUrl(envoy::api::v2::RouteConfiguration().GetDescriptor()->full_name());
case envoy::api::v2::core::ConfigSource::V3ALPHA:
return Grpc::Common::typeUrl(
envoy::api::v3alpha::RouteConfiguration().GetDescriptor()->full_name());
default:
throw EnvoyException(fmt::format("type {} is not supported", xds_api_version_));
}
}

RdsRouteConfigProviderImpl::RdsRouteConfigProviderImpl(
RdsRouteConfigSubscriptionSharedPtr&& subscription,
Server::Configuration::FactoryContext& factory_context)
Expand Down
8 changes: 6 additions & 2 deletions source/common/router/rds_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <unordered_set>

#include "envoy/admin/v2alpha/config_dump.pb.h"
#include "envoy/api/v2/core/config_source.pb.h"
#include "envoy/api/v2/discovery.pb.h"
#include "envoy/api/v2/rds.pb.h"
#include "envoy/config/filter/network/http_connection_manager/v2/http_connection_manager.pb.h"
Expand Down Expand Up @@ -139,10 +140,12 @@ class RdsRouteConfigSubscription : Envoy::Config::SubscriptionCallbacks,
const uint64_t manager_identifier,
Server::Configuration::ServerFactoryContext& factory_context,
ProtobufMessage::ValidationVisitor& validator, Init::Manager& init_manager,
const std::string& stat_prefix,
RouteConfigProviderManagerImpl& route_config_provider_manager);
const std::string& stat_prefix, RouteConfigProviderManagerImpl& route_config_provider_manager,
const envoy::api::v2::core::ConfigSource::XdsApiVersion xds_api_version =
envoy::api::v2::core::ConfigSource::AUTO);

bool validateUpdateSize(int num_resources);
std::string loadTypeUrl();

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

Expand All @@ -162,6 +165,7 @@ class RdsRouteConfigSubscription : Envoy::Config::SubscriptionCallbacks,
VhdsSubscriptionPtr vhds_subscription_;
RouteConfigUpdatePtr config_update_info_;
Common::CallbackManager<> update_callback_manager_;
const envoy::api::v2::core::ConfigSource::XdsApiVersion xds_api_version_;

friend class RouteConfigProviderManagerImpl;
// Access to addUpdateCallback
Expand Down
24 changes: 19 additions & 5 deletions source/common/router/scoped_rds.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "envoy/api/v2/discovery.pb.h"
#include "envoy/api/v2/srds.pb.h"
#include "envoy/api/v2/srds.pb.validate.h"
#include "envoy/api/v3alpha/srds.pb.h"
#include "envoy/config/filter/network/http_connection_manager/v2/http_connection_manager.pb.h"

#include "common/common/assert.h"
Expand Down Expand Up @@ -98,13 +99,11 @@ ScopedRdsConfigSubscription::ScopedRdsConfigSubscription(
stats_({ALL_SCOPED_RDS_STATS(POOL_COUNTER(*scope_))}),
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) {
route_config_provider_manager_(route_config_provider_manager),
xds_api_version_(rds_config_source.version()) {
subscription_ =
factory_context.clusterManager().subscriptionFactory().subscriptionFromConfigSource(
scoped_rds.scoped_rds_config_source(),
Grpc::Common::typeUrl(
envoy::api::v2::ScopedRouteConfiguration().GetDescriptor()->full_name()),
*scope_, *this);
scoped_rds.scoped_rds_config_source(), loadTypeUrl(), *scope_, *this);

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

std::string ScopedRdsConfigSubscription::loadTypeUrl() {
switch (xds_api_version_) {
// automatically set api version as V2
case envoy::api::v2::core::ConfigSource::AUTO:
case envoy::api::v2::core::ConfigSource::V2:
return Grpc::Common::typeUrl(
envoy::api::v2::ScopedRouteConfiguration().GetDescriptor()->full_name());
case envoy::api::v2::core::ConfigSource::V3ALPHA:
return Grpc::Common::typeUrl(
envoy::api::v3alpha::ScopedRouteConfiguration().GetDescriptor()->full_name());
default:
throw EnvoyException(fmt::format("type {} is not supported", xds_api_version_));
}
}

ScopedRdsConfigProvider::ScopedRdsConfigProvider(
ScopedRdsConfigSubscriptionSharedPtr&& subscription)
: MutableConfigProviderCommonBase(std::move(subscription), ConfigProvider::ApiType::Delta) {}
Expand Down
2 changes: 2 additions & 0 deletions source/common/router/scoped_rds.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ class ScopedRdsConfigSubscription : public Envoy::Config::DeltaConfigSubscriptio
std::string resourceName(const ProtobufWkt::Any& resource) override {
return MessageUtil::anyConvert<envoy::api::v2::ScopedRouteConfiguration>(resource).name();
}
std::string loadTypeUrl();
// Propagate RDS updates to ScopeConfigImpl in workers.
void onRdsConfigUpdate(const std::string& scope_name,
RdsRouteConfigSubscription& rds_subscription);
Expand All @@ -183,6 +184,7 @@ class ScopedRdsConfigSubscription : public Envoy::Config::DeltaConfigSubscriptio
ProtobufMessage::ValidationVisitor& validation_visitor_;
const std::string stat_prefix_;
RouteConfigProviderManager& route_config_provider_manager_;
const envoy::api::v2::core::ConfigSource::XdsApiVersion xds_api_version_;
};

using ScopedRdsConfigSubscriptionSharedPtr = std::shared_ptr<ScopedRdsConfigSubscription>;
Expand Down
29 changes: 21 additions & 8 deletions source/common/router/vhds.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "envoy/api/v2/core/config_source.pb.h"
#include "envoy/api/v2/discovery.pb.h"
#include "envoy/api/v2/route/route.pb.h"
#include "envoy/api/v3alpha/route/route.pb.h"

#include "common/common/assert.h"
#include "common/common/fmt.h"
Expand All @@ -19,17 +20,18 @@ namespace Envoy {
namespace Router {

// Implements callbacks to handle DeltaDiscovery protocol for VirtualHostDiscoveryService
VhdsSubscription::VhdsSubscription(RouteConfigUpdatePtr& config_update_info,
Server::Configuration::ServerFactoryContext& factory_context,
const std::string& stat_prefix,
std::unordered_set<RouteConfigProvider*>& route_config_providers)
VhdsSubscription::VhdsSubscription(
RouteConfigUpdatePtr& config_update_info,
Server::Configuration::ServerFactoryContext& factory_context, const std::string& stat_prefix,
std::unordered_set<RouteConfigProvider*>& route_config_providers,
const envoy::api::v2::core::ConfigSource::XdsApiVersion xds_api_version)
Comment thread
Shikugawa marked this conversation as resolved.
Outdated
: config_update_info_(config_update_info),
scope_(factory_context.scope().createScope(stat_prefix + "vhds." +
config_update_info_->routeConfigName() + ".")),
stats_({ALL_VHDS_STATS(POOL_COUNTER(*scope_))}),
init_target_(fmt::format("VhdsConfigSubscription {}", config_update_info_->routeConfigName()),
[this]() { subscription_->start({}); }),
route_config_providers_(route_config_providers) {
route_config_providers_(route_config_providers), xds_api_version_(xds_api_version) {
const auto& config_source = config_update_info_->routeConfiguration()
.vhds()
.config_source()
Expand All @@ -41,9 +43,8 @@ VhdsSubscription::VhdsSubscription(RouteConfigUpdatePtr& config_update_info,

subscription_ =
factory_context.clusterManager().subscriptionFactory().subscriptionFromConfigSource(
config_update_info_->routeConfiguration().vhds().config_source(),
Grpc::Common::typeUrl(envoy::api::v2::route::VirtualHost().GetDescriptor()->full_name()),
*scope_, *this);
config_update_info_->routeConfiguration().vhds().config_source(), loadTypeUrl(), *scope_,
*this);
}

void VhdsSubscription::onConfigUpdateFailed(Envoy::Config::ConfigUpdateFailureReason reason,
Expand All @@ -70,5 +71,17 @@ void VhdsSubscription::onConfigUpdate(
init_target_.ready();
}

std::string VhdsSubscription::loadTypeUrl() {
switch (xds_api_version_) {
// automatically set api version as V2
case envoy::api::v2::core::ConfigSource::AUTO:
case envoy::api::v2::core::ConfigSource::V2:
return Grpc::Common::typeUrl(envoy::api::v2::route::VirtualHost().GetDescriptor()->full_name());
case envoy::api::v2::core::ConfigSource::V3ALPHA:
return Grpc::Common::typeUrl(envoy::api::v2::route::VirtualHost().GetDescriptor()->full_name());
default:
throw EnvoyException(fmt::format("type {} is not supported", xds_api_version_));
}
}
} // namespace Router
} // namespace Envoy
7 changes: 6 additions & 1 deletion source/common/router/vhds.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <unordered_map>
#include <unordered_set>

#include "envoy/api/v2/core/config_source.pb.h"
#include "envoy/api/v2/discovery.pb.h"
#include "envoy/api/v2/route/route.pb.h"
#include "envoy/config/subscription.h"
Expand Down Expand Up @@ -39,7 +40,9 @@ class VhdsSubscription : Envoy::Config::SubscriptionCallbacks,
VhdsSubscription(RouteConfigUpdatePtr& config_update_info,
Server::Configuration::ServerFactoryContext& factory_context,
const std::string& stat_prefix,
std::unordered_set<RouteConfigProvider*>& route_config_providers);
std::unordered_set<RouteConfigProvider*>& route_config_providers,
const envoy::api::v2::core::ConfigSource::XdsApiVersion xds_api_version =
envoy::api::v2::core::ConfigSource::AUTO);
~VhdsSubscription() override { init_target_.ready(); }

void registerInitTargetWithInitManager(Init::Manager& m) { m.add(init_target_); }
Expand All @@ -57,13 +60,15 @@ class VhdsSubscription : Envoy::Config::SubscriptionCallbacks,
std::string resourceName(const ProtobufWkt::Any& resource) override {
return MessageUtil::anyConvert<envoy::api::v2::route::VirtualHost>(resource).name();
}
std::string loadTypeUrl();

RouteConfigUpdatePtr& config_update_info_;
Stats::ScopePtr scope_;
VhdsStats stats_;
std::unique_ptr<Envoy::Config::Subscription> subscription_;
Init::TargetImpl init_target_;
std::unordered_set<RouteConfigProvider*>& route_config_providers_;
const envoy::api::v2::core::ConfigSource::XdsApiVersion xds_api_version_;
};

using VhdsSubscriptionPtr = std::unique_ptr<VhdsSubscription>;
Expand Down
1 change: 1 addition & 0 deletions source/common/runtime/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ envoy_cc_library(
"@envoy_api//envoy/api/v2/core:pkg_cc_proto",
"@envoy_api//envoy/config/bootstrap/v2:pkg_cc_proto",
"@envoy_api//envoy/service/discovery/v2:pkg_cc_proto",
"@envoy_api//envoy/service/discovery/v3alpha:pkg_cc_proto",
"@envoy_api//envoy/type:pkg_cc_proto",
],
)
Expand Down
25 changes: 20 additions & 5 deletions source/common/runtime/runtime_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "envoy/event/dispatcher.h"
#include "envoy/service/discovery/v2/rtds.pb.h"
#include "envoy/service/discovery/v2/rtds.pb.validate.h"
#include "envoy/service/discovery/v3alpha/rtds.pb.h"
#include "envoy/thread_local/thread_local.h"
#include "envoy/type/percent.pb.h"
#include "envoy/type/percent.pb.validate.h"
Expand Down Expand Up @@ -546,11 +547,12 @@ void LoaderImpl::initialize(Upstream::ClusterManager& cm) { cm_ = &cm; }

RtdsSubscription::RtdsSubscription(
LoaderImpl& parent, const envoy::config::bootstrap::v2::RuntimeLayer::RtdsLayer& rtds_layer,
Stats::Store& store, ProtobufMessage::ValidationVisitor& validation_visitor)
Stats::Store& store, ProtobufMessage::ValidationVisitor& validation_visitor,
const envoy::api::v2::core::ConfigSource::XdsApiVersion xds_api_version)
: parent_(parent), config_source_(rtds_layer.rtds_config()), store_(store),
resource_name_(rtds_layer.name()),
init_target_("RTDS " + resource_name_, [this]() { start(); }),
validation_visitor_(validation_visitor) {}
validation_visitor_(validation_visitor), xds_api_version_(xds_api_version) {}

void RtdsSubscription::onConfigUpdate(const Protobuf::RepeatedPtrField<ProtobufWkt::Any>& resources,
const std::string&) {
Expand Down Expand Up @@ -589,9 +591,7 @@ void RtdsSubscription::start() {
// cluster manager resources are not available in the constructor when
// instantiated in the server instance.
subscription_ = parent_.cm_->subscriptionFactory().subscriptionFromConfigSource(
config_source_,
Grpc::Common::typeUrl(envoy::service::discovery::v2::Runtime().GetDescriptor()->full_name()),
store_, *this);
config_source_, loadTypeUrl(), store_, *this);
subscription_->start({resource_name_});
}

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

std::string RtdsSubscription::loadTypeUrl() {
switch (xds_api_version_) {
// automatically set api version as V2
case envoy::api::v2::core::ConfigSource::AUTO:
case envoy::api::v2::core::ConfigSource::V2:
return Grpc::Common::typeUrl(
envoy::service::discovery::v2::Runtime().GetDescriptor()->full_name());
case envoy::api::v2::core::ConfigSource::V3ALPHA:
return Grpc::Common::typeUrl(
envoy::service::discovery::v3alpha::Runtime().GetDescriptor()->full_name());
default:
throw EnvoyException(fmt::format("type {} is not supported", xds_api_version_));
}
}

void LoaderImpl::loadNewSnapshot() {
std::shared_ptr<SnapshotImpl> ptr = createNewSnapshot();
tls_->set([ptr](Event::Dispatcher&) -> ThreadLocal::ThreadLocalObjectSharedPtr {
Expand Down
Loading