/
subscription_factory_impl.cc
161 lines (151 loc) · 8.37 KB
/
subscription_factory_impl.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#include "source/common/config/subscription_factory_impl.h"
#include "envoy/config/core/v3/config_source.pb.h"
#include "source/common/config/filesystem_subscription_impl.h"
#include "source/common/config/grpc_mux_impl.h"
#include "source/common/config/grpc_subscription_impl.h"
#include "source/common/config/http_subscription_impl.h"
#include "source/common/config/new_grpc_mux_impl.h"
#include "source/common/config/type_to_endpoint.h"
#include "source/common/config/utility.h"
#include "source/common/config/xds_resource.h"
#include "source/common/http/utility.h"
#include "source/common/protobuf/protobuf.h"
#include "source/common/protobuf/utility.h"
namespace Envoy {
namespace Config {
SubscriptionFactoryImpl::SubscriptionFactoryImpl(
const LocalInfo::LocalInfo& local_info, Event::Dispatcher& dispatcher,
Upstream::ClusterManager& cm, ProtobufMessage::ValidationVisitor& validation_visitor,
Api::Api& api)
: local_info_(local_info), dispatcher_(dispatcher), cm_(cm),
validation_visitor_(validation_visitor), api_(api) {}
SubscriptionPtr SubscriptionFactoryImpl::subscriptionFromConfigSource(
const envoy::config::core::v3::ConfigSource& config, absl::string_view type_url,
Stats::Scope& scope, SubscriptionCallbacks& callbacks, OpaqueResourceDecoder& resource_decoder,
const SubscriptionOptions& options) {
Config::Utility::checkLocalInfo(type_url, local_info_);
SubscriptionStats stats = Utility::generateStats(scope);
switch (config.config_source_specifier_case()) {
case envoy::config::core::v3::ConfigSource::ConfigSourceSpecifierCase::kPath: {
Utility::checkFilesystemSubscriptionBackingPath(config.path(), api_);
return std::make_unique<Config::FilesystemSubscriptionImpl>(
dispatcher_, config.path(), callbacks, resource_decoder, stats, validation_visitor_, api_);
}
case envoy::config::core::v3::ConfigSource::ConfigSourceSpecifierCase::kApiConfigSource: {
const envoy::config::core::v3::ApiConfigSource& api_config_source = config.api_config_source();
Utility::checkApiConfigSourceSubscriptionBackingCluster(cm_.primaryClusters(),
api_config_source);
const auto transport_api_version = Utility::getAndCheckTransportVersion(api_config_source);
switch (api_config_source.api_type()) {
case envoy::config::core::v3::ApiConfigSource::hidden_envoy_deprecated_UNSUPPORTED_REST_LEGACY:
throw EnvoyException(
"REST_LEGACY no longer a supported ApiConfigSource. "
"Please specify an explicit supported api_type in the following config:\n" +
config.DebugString());
case envoy::config::core::v3::ApiConfigSource::REST:
return std::make_unique<HttpSubscriptionImpl>(
local_info_, cm_, api_config_source.cluster_names()[0], dispatcher_,
api_.randomGenerator(), Utility::apiConfigSourceRefreshDelay(api_config_source),
Utility::apiConfigSourceRequestTimeout(api_config_source),
restMethod(type_url, transport_api_version), type_url, transport_api_version, callbacks,
resource_decoder, stats, Utility::configSourceInitialFetchTimeout(config),
validation_visitor_);
case envoy::config::core::v3::ApiConfigSource::GRPC:
return std::make_unique<GrpcSubscriptionImpl>(
std::make_shared<Config::GrpcMuxImpl>(
local_info_,
Utility::factoryForGrpcApiConfigSource(cm_.grpcAsyncClientManager(),
api_config_source, scope, true)
->create(),
dispatcher_, sotwGrpcMethod(type_url, transport_api_version), transport_api_version,
api_.randomGenerator(), scope, Utility::parseRateLimitSettings(api_config_source),
api_config_source.set_node_on_first_message_only()),
callbacks, resource_decoder, stats, type_url, dispatcher_,
Utility::configSourceInitialFetchTimeout(config),
/*is_aggregated*/ false, options);
case envoy::config::core::v3::ApiConfigSource::DELTA_GRPC: {
return std::make_unique<GrpcSubscriptionImpl>(
std::make_shared<Config::NewGrpcMuxImpl>(
Config::Utility::factoryForGrpcApiConfigSource(cm_.grpcAsyncClientManager(),
api_config_source, scope, true)
->create(),
dispatcher_, deltaGrpcMethod(type_url, transport_api_version), transport_api_version,
api_.randomGenerator(), scope, Utility::parseRateLimitSettings(api_config_source),
local_info_),
callbacks, resource_decoder, stats, type_url, dispatcher_,
Utility::configSourceInitialFetchTimeout(config), /*is_aggregated*/ false, options);
}
default:
NOT_REACHED_GCOVR_EXCL_LINE;
}
}
case envoy::config::core::v3::ConfigSource::ConfigSourceSpecifierCase::kAds: {
return std::make_unique<GrpcSubscriptionImpl>(
cm_.adsMux(), callbacks, resource_decoder, stats, type_url, dispatcher_,
Utility::configSourceInitialFetchTimeout(config), true, options);
}
default:
throw EnvoyException(
"Missing config source specifier in envoy::config::core::v3::ConfigSource");
}
NOT_REACHED_GCOVR_EXCL_LINE;
}
SubscriptionPtr SubscriptionFactoryImpl::collectionSubscriptionFromUrl(
const xds::core::v3::ResourceLocator& collection_locator,
const envoy::config::core::v3::ConfigSource& config, absl::string_view resource_type,
Stats::Scope& scope, SubscriptionCallbacks& callbacks,
OpaqueResourceDecoder& resource_decoder) {
SubscriptionStats stats = Utility::generateStats(scope);
switch (collection_locator.scheme()) {
case xds::core::v3::ResourceLocator::FILE: {
const std::string path = Http::Utility::localPathFromFilePath(collection_locator.id());
Utility::checkFilesystemSubscriptionBackingPath(path, api_);
return std::make_unique<Config::FilesystemCollectionSubscriptionImpl>(
dispatcher_, path, callbacks, resource_decoder, stats, validation_visitor_, api_);
}
case xds::core::v3::ResourceLocator::XDSTP: {
if (resource_type != collection_locator.resource_type()) {
throw EnvoyException(
fmt::format("xdstp:// type does not match {} in {}", resource_type,
Config::XdsResourceIdentifier::encodeUrl(collection_locator)));
}
const envoy::config::core::v3::ApiConfigSource& api_config_source = config.api_config_source();
Utility::checkApiConfigSourceSubscriptionBackingCluster(cm_.primaryClusters(),
api_config_source);
SubscriptionOptions options;
// All Envoy collections currently are xDS resource graph roots and require node context
// parameters.
options.add_xdstp_node_context_params_ = true;
switch (api_config_source.api_type()) {
case envoy::config::core::v3::ApiConfigSource::DELTA_GRPC: {
const std::string type_url = TypeUtil::descriptorFullNameToTypeUrl(resource_type);
return std::make_unique<GrpcCollectionSubscriptionImpl>(
collection_locator,
std::make_shared<Config::NewGrpcMuxImpl>(
Config::Utility::factoryForGrpcApiConfigSource(cm_.grpcAsyncClientManager(),
api_config_source, scope, true)
->create(),
dispatcher_, deltaGrpcMethod(type_url, envoy::config::core::v3::ApiVersion::V3),
envoy::config::core::v3::ApiVersion::V3, api_.randomGenerator(), scope,
Utility::parseRateLimitSettings(api_config_source), local_info_),
callbacks, resource_decoder, stats, dispatcher_,
Utility::configSourceInitialFetchTimeout(config), false, options);
}
case envoy::config::core::v3::ApiConfigSource::AGGREGATED_DELTA_GRPC: {
return std::make_unique<GrpcCollectionSubscriptionImpl>(
collection_locator, cm_.adsMux(), callbacks, resource_decoder, stats, dispatcher_,
Utility::configSourceInitialFetchTimeout(config), false, options);
}
default:
throw EnvoyException(fmt::format("Unknown xdstp:// transport API type in {}",
api_config_source.DebugString()));
}
}
default:
// TODO(htuch): Implement HTTP semantics for collection ResourceLocators.
NOT_IMPLEMENTED_GCOVR_EXCL_LINE;
}
NOT_REACHED_GCOVR_EXCL_LINE;
}
} // namespace Config
} // namespace Envoy