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

api: remove hardcoded type urls part.1 #10479

Merged
merged 9 commits into from
Apr 3, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
11 changes: 1 addition & 10 deletions include/envoy/config/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ envoy_cc_library(
hdrs = ["subscription.h"],
deps = [
"//include/envoy/stats:stats_macros",
"//source/common/config:api_type_oracle_lib",
"//source/common/protobuf",
"@envoy_api//envoy/service/discovery/v3:pkg_cc_proto",
],
Expand All @@ -75,13 +76,3 @@ envoy_cc_library(
"//source/common/protobuf",
],
)

envoy_cc_library(
name = "discovery_service_base_interface",
hdrs = ["discovery_service_base.h"],
deps = [
":subscription_interface",
"//source/common/config:api_type_oracle_lib",
"//source/common/protobuf",
],
)
28 changes: 0 additions & 28 deletions include/envoy/config/discovery_service_base.h

This file was deleted.

1 change: 0 additions & 1 deletion include/envoy/config/subscription.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,5 @@ using SubscriptionPtr = std::unique_ptr<Subscription>;
struct SubscriptionStats {
ALL_SUBSCRIPTION_STATS(GENERATE_COUNTER_STRUCT, GENERATE_GAUGE_STRUCT)
};

} // namespace Config
} // namespace Envoy
19 changes: 19 additions & 0 deletions source/common/config/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,16 @@ envoy_cc_library(
],
)

envoy_cc_library(
name = "resource_name_lib",
hdrs = ["resource_name.h"],
deps = [
":api_type_oracle_lib",
"//source/common/common:assert_lib",
"@envoy_api//envoy/config/core/v3:pkg_cc_proto",
],
)

envoy_cc_library(
name = "resources_lib",
hdrs = ["resources.h"],
Expand Down Expand Up @@ -361,6 +371,15 @@ envoy_cc_library(
],
)

envoy_cc_library(
name = "subscription_base_interface",
hdrs = ["subscription_base.h"],
deps = [
":resource_name_lib",
"//include/envoy/config:subscription_interface",
],
)

envoy_cc_library(
name = "well_known_names",
srcs = ["well_known_names.cc"],
Expand Down
2 changes: 1 addition & 1 deletion source/common/config/grpc_mux_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -244,4 +244,4 @@ void GrpcMuxImpl::drainRequests() {
}

} // namespace Config
} // namespace Envoy
} // namespace Envoy
61 changes: 61 additions & 0 deletions source/common/config/resource_name.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#pragma once

#include <string>
#include <vector>

#include "envoy/config/core/v3/config_source.pb.h"

#include "common/common/assert.h"
#include "common/config/api_type_oracle.h"

namespace Envoy {
namespace Config {

/**
* Get resource name from api type and version.
*/
template <typename Current>
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 ApiTypeOracle::getEarlierVersionMessageTypeName(Current().GetDescriptor()->full_name())
.value();
case envoy::config::core::v3::ApiVersion::V3:
return Current().GetDescriptor()->full_name();
default:
NOT_REACHED_GCOVR_EXCL_LINE;
}
}

/**
* Get type url from api type and version.
*/
template <typename Current>
std::string getTypeUrl(envoy::config::core::v3::ApiVersion resource_api_version) {
return "type.googleapis.com/" + getResourceName<Current>(resource_api_version);
}

/**
* get all version resource names.
*/
template <typename Current> std::vector<std::string> getAllVersionResourceNames() {
return std::vector<std::string>{
Current().GetDescriptor()->full_name(),
ApiTypeOracle::getEarlierVersionMessageTypeName(Current().GetDescriptor()->full_name())
.value()};
}

/**
* get all version type urls.
*/
template <typename Current> std::vector<std::string> getAllVersionTypeUrls() {
auto resource_names = getAllVersionResourceNames<Current>();
for (auto&& resource_name : resource_names) {
resource_name = "type.googleapis.com/" + resource_name;
}
return resource_names;
}

} // namespace Config
} // namespace Envoy
24 changes: 24 additions & 0 deletions source/common/config/subscription_base.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#pragma once

#include "envoy/config/subscription.h"

#include "common/config/resource_name.h"

namespace Envoy {
namespace Config {

template <typename Current> struct SubscriptionBase : public Config::SubscriptionCallbacks {
public:
SubscriptionBase(const envoy::config::core::v3::ApiVersion api_version)
: api_version_(api_version) {}

std::string getResourceName() const {
return Envoy::Config::getResourceName<Current>(api_version_);
}

private:
const envoy::config::core::v3::ApiVersion api_version_;
};

} // namespace Config
} // namespace Envoy
1 change: 0 additions & 1 deletion source/common/config/utility.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#include "common/common/hex.h"
#include "common/common/utility.h"
#include "common/config/api_type_oracle.h"
#include "common/config/resources.h"
#include "common/config/version_converter.h"
#include "common/config/well_known_names.h"
#include "common/protobuf/protobuf.h"
Expand Down
6 changes: 3 additions & 3 deletions source/common/router/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ 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 All @@ -135,6 +134,7 @@ envoy_cc_library(
"//source/common/common:assert_lib",
"//source/common/common:minimal_logger_lib",
"//source/common/config:api_version_lib",
"//source/common/config:subscription_base_interface",
"//source/common/config:utility_lib",
"//source/common/init:target_lib",
"//source/common/protobuf:utility_lib",
Expand All @@ -152,7 +152,6 @@ 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 All @@ -167,6 +166,7 @@ envoy_cc_library(
"//source/common/common:cleanup_lib",
"//source/common/common:minimal_logger_lib",
"//source/common/config:api_version_lib",
"//source/common/config:subscription_base_interface",
"//source/common/config:subscription_factory_lib",
"//source/common/config:utility_lib",
"//source/common/config:version_converter_lib",
Expand Down Expand Up @@ -210,7 +210,6 @@ 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 All @@ -219,6 +218,7 @@ envoy_cc_library(
"//source/common/common:minimal_logger_lib",
"//source/common/config:api_version_lib",
"//source/common/config:config_provider_lib",
"//source/common/config:subscription_base_interface",
"//source/common/config:version_converter_lib",
"//source/common/init:manager_lib",
"//source/common/init:watcher_lib",
Expand Down
6 changes: 4 additions & 2 deletions source/common/router/rds_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ RdsRouteConfigSubscription::RdsRouteConfigSubscription(
const uint64_t manager_identifier, Server::Configuration::ServerFactoryContext& factory_context,
const std::string& stat_prefix,
Envoy::Router::RouteConfigProviderManagerImpl& route_config_provider_manager)
: route_config_name_(rds.route_config_name()), factory_context_(factory_context),
: Envoy::Config::SubscriptionBase<envoy::config::route::v3::RouteConfiguration>(
rds.config_source().resource_api_version()),
route_config_name_(rds.route_config_name()), factory_context_(factory_context),
validator_(factory_context.messageValidationContext().dynamicValidationVisitor()),
parent_init_target_(fmt::format("RdsRouteConfigSubscription init {}", route_config_name_),
[this]() { local_init_manager_.initialize(local_init_watcher_); }),
Expand All @@ -82,7 +84,7 @@ 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());
const auto resource_name = getResourceName();
subscription_ =
factory_context.clusterManager().subscriptionFactory().subscriptionFromConfigSource(
rds.config_source(), Grpc::Common::typeUrl(resource_name), *scope_, *this);
Expand Down
1 change: 0 additions & 1 deletion source/common/router/rds_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#include "common/common/callback_impl.h"
#include "common/common/cleanup.h"
#include "common/common/logger.h"
#include "common/config/resources.h"
#include "common/init/manager_impl.h"
#include "common/init/target_impl.h"
#include "common/init/watcher_impl.h"
Expand Down
11 changes: 5 additions & 6 deletions source/common/router/scoped_rds.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#include "common/common/logger.h"
#include "common/common/utility.h"
#include "common/config/api_version.h"
#include "common/config/resources.h"
#include "common/config/version_converter.h"
#include "common/init/manager_impl.h"
#include "common/init/watcher_impl.h"
Expand Down Expand Up @@ -99,13 +98,15 @@ ScopedRdsConfigSubscription::ScopedRdsConfigSubscription(
ScopedRoutesConfigProviderManager& config_provider_manager)
: DeltaConfigSubscriptionInstance("SRDS", manager_identifier, config_provider_manager,
factory_context),
Envoy::Config::SubscriptionBase<envoy::config::route::v3::ScopedRouteConfiguration>(
rds_config_source.resource_api_version()),
factory_context_(factory_context), name_(name), scope_key_builder_(scope_key_builder),
scope_(factory_context.scope().createScope(stat_prefix + "scoped_rds." + name + ".")),
stats_({ALL_SCOPED_RDS_STATS(POOL_COUNTER(*scope_))}),
rds_config_source_(std::move(rds_config_source)),
validation_visitor_(factory_context.messageValidationContext().dynamicValidationVisitor()),
stat_prefix_(stat_prefix), route_config_provider_manager_(route_config_provider_manager) {
const auto resource_name = getResourceName(rds_config_source_.resource_api_version());
const auto resource_name = getResourceName();
subscription_ =
factory_context.clusterManager().subscriptionFactory().subscriptionFromConfigSource(
scoped_rds.scoped_rds_config_source(), Grpc::Common::typeUrl(resource_name), *scope_,
Expand Down Expand Up @@ -240,8 +241,7 @@ void ScopedRdsConfigSubscription::onConfigUpdate(
// In the case if factory_context_.init_manager() is uninitialized, RDS is already paused
// either by Server init or LDS init.
if (factory_context_.clusterManager().adsMux()) {
factory_context_.clusterManager().adsMux()->pause(
Envoy::Config::TypeUrl::get().RouteConfiguration);
factory_context_.clusterManager().adsMux()->pause(getResourceName());
}
resume_rds = std::make_unique<Cleanup>([this, &noop_init_manager, version_info] {
// For new RDS subscriptions created after listener warming up, we don't wait for them to
Expand All @@ -255,8 +255,7 @@ void ScopedRdsConfigSubscription::onConfigUpdate(
// Note in the case of partial acceptance, accepted RDS subscriptions should be started
// despite of any error.
if (factory_context_.clusterManager().adsMux()) {
factory_context_.clusterManager().adsMux()->resume(
Envoy::Config::TypeUrl::get().RouteConfiguration);
factory_context_.clusterManager().adsMux()->resume(getResourceName());
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion source/common/router/scoped_rds.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

#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 All @@ -13,6 +12,7 @@
#include "envoy/stats/scope.h"

#include "common/config/config_provider_impl.h"
#include "common/config/subscription_base.h"
#include "common/init/manager_impl.h"
#include "common/router/rds_impl.h"
#include "common/router/scoped_config_impl.h"
Expand Down
5 changes: 3 additions & 2 deletions source/common/router/vhds.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ VhdsSubscription::VhdsSubscription(RouteConfigUpdatePtr& config_update_info,
const std::string& stat_prefix,
std::unordered_set<RouteConfigProvider*>& route_config_providers,
envoy::config::core::v3::ApiVersion resource_api_version)
: config_update_info_(config_update_info),
: Envoy::Config::SubscriptionBase<envoy::config::route::v3::VirtualHost>(resource_api_version),
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_))}),
Expand All @@ -40,7 +41,7 @@ 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);
const auto resource_name = getResourceName();
subscription_ =
factory_context.clusterManager().subscriptionFactory().subscriptionFromConfigSource(
config_update_info_->routeConfiguration().vhds().config_source(),
Expand Down
2 changes: 1 addition & 1 deletion source/common/router/vhds.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#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 All @@ -21,6 +20,7 @@
#include "envoy/thread_local/thread_local.h"

#include "common/common/logger.h"
#include "common/config/subscription_base.h"
#include "common/init/target_impl.h"
#include "common/protobuf/utility.h"

Expand Down
2 changes: 1 addition & 1 deletion source/common/runtime/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ 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 All @@ -48,6 +47,7 @@ envoy_cc_library(
"//source/common/common:thread_lib",
"//source/common/common:utility_lib",
"//source/common/config:api_version_lib",
"//source/common/config:subscription_base_interface",
"//source/common/filesystem:directory_lib",
"//source/common/grpc:common_lib",
"//source/common/init:target_lib",
Expand Down
Loading