From 3f7555521056219c4d8ab58bc3955ead6438b4bd Mon Sep 17 00:00:00 2001 From: chaoqin-li1123 Date: Wed, 5 May 2021 22:06:37 +0000 Subject: [PATCH 1/5] initial Signed-off-by: chaoqin-li1123 --- docs/root/version_history/v1.16.0.rst | 1 - include/envoy/config/grpc_mux.h | 3 -- source/common/config/BUILD | 1 - source/common/config/api_type_oracle.cc | 8 ----- source/common/config/api_type_oracle.h | 3 -- source/common/config/grpc_mux_impl.cc | 34 +++---------------- source/common/config/grpc_mux_impl.h | 3 -- .../common/config/grpc_subscription_impl.cc | 1 - source/common/config/new_grpc_mux_impl.cc | 30 +--------------- source/common/config/new_grpc_mux_impl.h | 3 -- .../config/subscription_factory_impl.cc | 1 + source/common/protobuf/BUILD | 11 ------ source/common/protobuf/type_util.cc | 17 ---------- source/common/protobuf/type_util.h | 17 ---------- source/common/protobuf/utility.cc | 13 +++++++ source/common/protobuf/utility.h | 5 +++ test/common/protobuf/type_util_test.cc | 18 ---------- 17 files changed, 24 insertions(+), 145 deletions(-) delete mode 100644 source/common/protobuf/type_util.cc delete mode 100644 source/common/protobuf/type_util.h delete mode 100644 test/common/protobuf/type_util_test.cc diff --git a/docs/root/version_history/v1.16.0.rst b/docs/root/version_history/v1.16.0.rst index d9c2d97d7f25a..122a74a2e4fd5 100644 --- a/docs/root/version_history/v1.16.0.rst +++ b/docs/root/version_history/v1.16.0.rst @@ -161,7 +161,6 @@ New Features * watchdog: watchdog action extension that does cpu profiling. See :ref:`Profile Action `. * watchdog: watchdog action extension that sends SIGABRT to the stuck thread to terminate the process. See :ref:`Abort Action `. * xds: added :ref:`extension config discovery` support for HTTP filters. -* xds: added support for mixed v2/v3 discovery response, which enable type url downgrade and upgrade. This feature is disabled by default and is controlled by runtime guard `envoy.reloadable_features.enable_type_url_downgrade_and_upgrade`. * zlib: added option to use `zlib-ng `_ as zlib library. Deprecated diff --git a/include/envoy/config/grpc_mux.h b/include/envoy/config/grpc_mux.h index 620b217b2216f..57befc93e01ca 100644 --- a/include/envoy/config/grpc_mux.h +++ b/include/envoy/config/grpc_mux.h @@ -105,9 +105,6 @@ class GrpcMux { virtual void requestOnDemandUpdate(const std::string& type_url, const absl::flat_hash_set& for_update) PURE; - - using TypeUrlMap = absl::flat_hash_map; - static TypeUrlMap& typeUrlMap() { MUTABLE_CONSTRUCT_ON_FIRST_USE(TypeUrlMap, {}); } }; using GrpcMuxPtr = std::unique_ptr; diff --git a/source/common/config/BUILD b/source/common/config/BUILD index de123c9f86c5b..e5e73d9e9d4da 100644 --- a/source/common/config/BUILD +++ b/source/common/config/BUILD @@ -14,7 +14,6 @@ envoy_cc_library( hdrs = ["api_type_oracle.h"], deps = [ "//source/common/protobuf", - "//source/common/protobuf:type_util_lib", "@com_github_cncf_udpa//udpa/annotations:pkg_cc_proto", ], ) diff --git a/source/common/config/api_type_oracle.cc b/source/common/config/api_type_oracle.cc index f6feba09828a1..467622dabd3ea 100644 --- a/source/common/config/api_type_oracle.cc +++ b/source/common/config/api_type_oracle.cc @@ -32,14 +32,6 @@ ApiTypeOracle::getEarlierVersionMessageTypeName(const std::string& message_type) return absl::nullopt; } -const absl::optional ApiTypeOracle::getEarlierTypeUrl(const std::string& type_url) { - const std::string type{TypeUtil::typeUrlToDescriptorFullName(type_url)}; - absl::optional old_type = ApiTypeOracle::getEarlierVersionMessageTypeName(type); - if (old_type.has_value()) { - return TypeUtil::descriptorFullNameToTypeUrl(old_type.value()); - } - return {}; -} } // namespace Config } // namespace Envoy diff --git a/source/common/config/api_type_oracle.h b/source/common/config/api_type_oracle.h index ab5e75b113d78..bde8186fa555c 100644 --- a/source/common/config/api_type_oracle.h +++ b/source/common/config/api_type_oracle.h @@ -1,7 +1,6 @@ #pragma once #include "common/protobuf/protobuf.h" -#include "common/protobuf/type_util.h" #include "absl/strings/string_view.h" #include "absl/types/optional.h" @@ -24,8 +23,6 @@ class ApiTypeOracle { static const absl::optional getEarlierVersionMessageTypeName(const std::string& message_type); - - static const absl::optional getEarlierTypeUrl(const std::string& type_url); }; } // namespace Config diff --git a/source/common/config/grpc_mux_impl.cc b/source/common/config/grpc_mux_impl.cc index 927e73b4218a9..5c7633eaa61ff 100644 --- a/source/common/config/grpc_mux_impl.cc +++ b/source/common/config/grpc_mux_impl.cc @@ -25,8 +25,6 @@ GrpcMuxImpl::GrpcMuxImpl(const LocalInfo::LocalInfo& local_info, local_info_(local_info), skip_subsequent_node_(skip_subsequent_node), first_stream_request_(true), transport_api_version_(transport_api_version), dispatcher_(dispatcher), - enable_type_url_downgrade_and_upgrade_(Runtime::runtimeFeatureEnabled( - "envoy.reloadable_features.enable_type_url_downgrade_and_upgrade")), dynamic_update_callback_handle_(local_info.contextProvider().addDynamicContextUpdateCallback( [this](absl::string_view resource_type_url) { onDynamicContextUpdate(resource_type_url); @@ -97,9 +95,6 @@ GrpcMuxWatchPtr GrpcMuxImpl::addWatch(const std::string& type_url, apiStateFor(type_url).request_.mutable_node()->MergeFrom(local_info_.node()); apiStateFor(type_url).subscribed_ = true; subscriptions_.emplace_back(type_url); - if (enable_type_url_downgrade_and_upgrade_) { - registerVersionedTypeUrl(type_url); - } } // This will send an updated request on each subscription. @@ -137,36 +132,15 @@ ScopedResume GrpcMuxImpl::pause(const std::vector type_urls) { }); } -void GrpcMuxImpl::registerVersionedTypeUrl(const std::string& type_url) { - TypeUrlMap& type_url_map = typeUrlMap(); - if (type_url_map.find(type_url) != type_url_map.end()) { - return; - } - // If type_url is v3, earlier_type_url will contain v2 type url. - const absl::optional earlier_type_url = ApiTypeOracle::getEarlierTypeUrl(type_url); - // Register v2 to v3 and v3 to v2 type_url mapping in the hash map. - if (earlier_type_url.has_value()) { - type_url_map[earlier_type_url.value()] = type_url; - type_url_map[type_url] = earlier_type_url.value(); - } -} - void GrpcMuxImpl::onDiscoveryResponse( std::unique_ptr&& message, ControlPlaneStats& control_plane_stats) { - std::string type_url = message->type_url(); + const std::string type_url = message->type_url(); ENVOY_LOG(debug, "Received gRPC message for {} at version {}", type_url, message->version_info()); if (message->has_control_plane()) { control_plane_stats.identifier_.set(message->control_plane().identifier()); } - // If this type url is not watched(no subscriber or no watcher), try another version of type url. - if (enable_type_url_downgrade_and_upgrade_ && api_state_.count(type_url) == 0) { - registerVersionedTypeUrl(type_url); - TypeUrlMap& type_url_map = typeUrlMap(); - if (type_url_map.find(type_url) != type_url_map.end()) { - type_url = type_url_map[type_url]; - } - } + if (api_state_.count(type_url) == 0) { // TODO(yuval-k): This should never happen. consider dropping the stream as this is a // protocol violation @@ -216,10 +190,10 @@ void GrpcMuxImpl::onDiscoveryResponse( for (const auto& resource : message->resources()) { // TODO(snowp): Check the underlying type when the resource is a Resource. if (!resource.Is() && - message->type_url() != resource.type_url()) { + type_url != resource.type_url()) { throw EnvoyException( fmt::format("{} does not match the message-wide type URL {} in DiscoveryResponse {}", - resource.type_url(), message->type_url(), message->DebugString())); + resource.type_url(), type_url, message->DebugString())); } auto decoded_resource = diff --git a/source/common/config/grpc_mux_impl.h b/source/common/config/grpc_mux_impl.h index 3600e78111aeb..3c4b973b8d9d1 100644 --- a/source/common/config/grpc_mux_impl.h +++ b/source/common/config/grpc_mux_impl.h @@ -21,7 +21,6 @@ #include "common/config/grpc_stream.h" #include "common/config/ttl.h" #include "common/config/utility.h" -#include "common/runtime/runtime_features.h" #include "absl/container/node_hash_map.h" @@ -62,7 +61,6 @@ class GrpcMuxImpl : public GrpcMux, // Config::GrpcStreamCallbacks void onStreamEstablished() override; void onEstablishmentFailure() override; - void registerVersionedTypeUrl(const std::string& type_url); void onDiscoveryResponse(std::unique_ptr&& message, ControlPlaneStats& control_plane_stats) override; @@ -177,7 +175,6 @@ class GrpcMuxImpl : public GrpcMux, const envoy::config::core::v3::ApiVersion transport_api_version_; Event::Dispatcher& dispatcher_; - bool enable_type_url_downgrade_and_upgrade_; Common::CallbackHandlePtr dynamic_update_callback_handle_; }; diff --git a/source/common/config/grpc_subscription_impl.cc b/source/common/config/grpc_subscription_impl.cc index 602b5df7dc91a..3b6412d111dc3 100644 --- a/source/common/config/grpc_subscription_impl.cc +++ b/source/common/config/grpc_subscription_impl.cc @@ -8,7 +8,6 @@ #include "common/config/xds_resource.h" #include "common/grpc/common.h" #include "common/protobuf/protobuf.h" -#include "common/protobuf/type_util.h" #include "common/protobuf/utility.h" namespace Envoy { diff --git a/source/common/config/new_grpc_mux_impl.cc b/source/common/config/new_grpc_mux_impl.cc index 58890dfbdf08e..d875f92bff5fe 100644 --- a/source/common/config/new_grpc_mux_impl.cc +++ b/source/common/config/new_grpc_mux_impl.cc @@ -30,9 +30,7 @@ NewGrpcMuxImpl::NewGrpcMuxImpl(Grpc::RawAsyncClientPtr&& async_client, [this](absl::string_view resource_type_url) { onDynamicContextUpdate(resource_type_url); })), - transport_api_version_(transport_api_version), dispatcher_(dispatcher), - enable_type_url_downgrade_and_upgrade_(Runtime::runtimeFeatureEnabled( - "envoy.reloadable_features.enable_type_url_downgrade_and_upgrade")) {} + transport_api_version_(transport_api_version), dispatcher_(dispatcher) {} void NewGrpcMuxImpl::onDynamicContextUpdate(absl::string_view resource_type_url) { auto sub = subscriptions_.find(resource_type_url); @@ -62,35 +60,12 @@ ScopedResume NewGrpcMuxImpl::pause(const std::vector type_urls) { }); } -void NewGrpcMuxImpl::registerVersionedTypeUrl(const std::string& type_url) { - TypeUrlMap& type_url_map = typeUrlMap(); - if (type_url_map.find(type_url) != type_url_map.end()) { - return; - } - // If type_url is v3, earlier_type_url will contain v2 type url. - absl::optional earlier_type_url = ApiTypeOracle::getEarlierTypeUrl(type_url); - // Register v2 to v3 and v3 to v2 type_url mapping in the hash map. - if (earlier_type_url.has_value()) { - type_url_map[earlier_type_url.value()] = type_url; - type_url_map[type_url] = earlier_type_url.value(); - } -} - void NewGrpcMuxImpl::onDiscoveryResponse( std::unique_ptr&& message, ControlPlaneStats&) { ENVOY_LOG(debug, "Received DeltaDiscoveryResponse for {} at version {}", message->type_url(), message->system_version_info()); auto sub = subscriptions_.find(message->type_url()); - // If this type url is not watched, try another version type url. - if (enable_type_url_downgrade_and_upgrade_ && sub == subscriptions_.end()) { - const std::string& type_url = message->type_url(); - registerVersionedTypeUrl(type_url); - TypeUrlMap& type_url_map = typeUrlMap(); - if (type_url_map.find(type_url) != type_url_map.end()) { - sub = subscriptions_.find(type_url_map[type_url]); - } - } if (sub == subscriptions_.end()) { ENVOY_LOG(warn, "Dropping received DeltaDiscoveryResponse (with version {}) for non-existent " @@ -149,9 +124,6 @@ GrpcMuxWatchPtr NewGrpcMuxImpl::addWatch(const std::string& type_url, auto entry = subscriptions_.find(type_url); if (entry == subscriptions_.end()) { // We don't yet have a subscription for type_url! Make one! - if (enable_type_url_downgrade_and_upgrade_) { - registerVersionedTypeUrl(type_url); - } addSubscription(type_url, options.use_namespace_matching_); return addWatch(type_url, resources, callbacks, resource_decoder, options); } diff --git a/source/common/config/new_grpc_mux_impl.h b/source/common/config/new_grpc_mux_impl.h index 8c10e477da3bb..cfd1e122a1777 100644 --- a/source/common/config/new_grpc_mux_impl.h +++ b/source/common/config/new_grpc_mux_impl.h @@ -50,8 +50,6 @@ class NewGrpcMuxImpl ScopedResume pause(const std::string& type_url) override; ScopedResume pause(const std::vector type_urls) override; - void registerVersionedTypeUrl(const std::string& type_url); - void onDiscoveryResponse( std::unique_ptr&& message, ControlPlaneStats& control_plane_stats) override; @@ -163,7 +161,6 @@ class NewGrpcMuxImpl const envoy::config::core::v3::ApiVersion transport_api_version_; Event::Dispatcher& dispatcher_; - const bool enable_type_url_downgrade_and_upgrade_; }; using NewGrpcMuxImplPtr = std::unique_ptr; diff --git a/source/common/config/subscription_factory_impl.cc b/source/common/config/subscription_factory_impl.cc index cf53c93cfd53e..277a3524e7282 100644 --- a/source/common/config/subscription_factory_impl.cc +++ b/source/common/config/subscription_factory_impl.cc @@ -12,6 +12,7 @@ #include "common/config/xds_resource.h" #include "common/http/utility.h" #include "common/protobuf/protobuf.h" +#include "common/protobuf/utility.h" namespace Envoy { namespace Config { diff --git a/source/common/protobuf/BUILD b/source/common/protobuf/BUILD index 12d2e4e424f9c..09bb9cb3bc837 100644 --- a/source/common/protobuf/BUILD +++ b/source/common/protobuf/BUILD @@ -61,7 +61,6 @@ envoy_cc_library( deps = [ ":message_validator_lib", ":protobuf", - ":type_util_lib", ":well_known_lib", "//include/envoy/api:api_interface", "//include/envoy/protobuf:message_validator_interface", @@ -80,16 +79,6 @@ envoy_cc_library( ], ) -envoy_cc_library( - name = "type_util_lib", - srcs = ["type_util.cc"], - hdrs = ["type_util.h"], - deps = [ - "//source/common/protobuf", - "@com_github_cncf_udpa//udpa/annotations:pkg_cc_proto", - ], -) - envoy_cc_library( name = "visitor_lib", srcs = ["visitor.cc"], diff --git a/source/common/protobuf/type_util.cc b/source/common/protobuf/type_util.cc deleted file mode 100644 index 03b5c1f01b343..0000000000000 --- a/source/common/protobuf/type_util.cc +++ /dev/null @@ -1,17 +0,0 @@ -#include "common/protobuf/type_util.h" - -namespace Envoy { - -absl::string_view TypeUtil::typeUrlToDescriptorFullName(absl::string_view type_url) { - const size_t pos = type_url.rfind('/'); - if (pos != absl::string_view::npos) { - type_url = type_url.substr(pos + 1); - } - return type_url; -} - -std::string TypeUtil::descriptorFullNameToTypeUrl(absl::string_view type) { - return "type.googleapis.com/" + std::string(type); -} - -} // namespace Envoy diff --git a/source/common/protobuf/type_util.h b/source/common/protobuf/type_util.h deleted file mode 100644 index 9bcfa0f8c2f62..0000000000000 --- a/source/common/protobuf/type_util.h +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once - -#include "common/protobuf/protobuf.h" - -#include "absl/strings/string_view.h" -#include "absl/types/optional.h" - -namespace Envoy { - -class TypeUtil { -public: - static absl::string_view typeUrlToDescriptorFullName(absl::string_view type_url); - - static std::string descriptorFullNameToTypeUrl(absl::string_view type); -}; - -} // namespace Envoy diff --git a/source/common/protobuf/utility.cc b/source/common/protobuf/utility.cc index 650c6006e4092..1090be0649716 100644 --- a/source/common/protobuf/utility.cc +++ b/source/common/protobuf/utility.cc @@ -1038,4 +1038,17 @@ void TimestampUtil::systemClockToTimestamp(const SystemTime system_clock_time, .time_since_epoch() .count())); } + +absl::string_view TypeUtil::typeUrlToDescriptorFullName(absl::string_view type_url) { + const size_t pos = type_url.rfind('/'); + if (pos != absl::string_view::npos) { + type_url = type_url.substr(pos + 1); + } + return type_url; +} + +std::string TypeUtil::descriptorFullNameToTypeUrl(absl::string_view type) { + return "type.googleapis.com/" + std::string(type); +} + } // namespace Envoy diff --git a/source/common/protobuf/utility.h b/source/common/protobuf/utility.h index 70b182bb1cd39..2d8e64aba980f 100644 --- a/source/common/protobuf/utility.h +++ b/source/common/protobuf/utility.h @@ -144,6 +144,11 @@ class MissingFieldException : public EnvoyException { MissingFieldException(const std::string& field_name, const Protobuf::Message& message); }; +class TypeUtil { +public: + static absl::string_view typeUrlToDescriptorFullName(absl::string_view type_url); +}; + class RepeatedPtrUtil { public: static std::string join(const Protobuf::RepeatedPtrField& source, diff --git a/test/common/protobuf/type_util_test.cc b/test/common/protobuf/type_util_test.cc deleted file mode 100644 index d783951636377..0000000000000 --- a/test/common/protobuf/type_util_test.cc +++ /dev/null @@ -1,18 +0,0 @@ -#include "common/protobuf/type_util.h" - -#include "gtest/gtest.h" - -namespace Envoy { -namespace Config { -namespace { -TEST(TypeUtilTest, TypeUrlHelperFunction) { - EXPECT_EQ("envoy.config.filter.http.ip_tagging.v2.IPTagging", - TypeUtil::typeUrlToDescriptorFullName( - "type.googleapis.com/envoy.config.filter.http.ip_tagging.v2.IPTagging")); - EXPECT_EQ( - "type.googleapis.com/envoy.config.filter.http.ip_tagging.v2.IPTagging", - TypeUtil::descriptorFullNameToTypeUrl("envoy.config.filter.http.ip_tagging.v2.IPTagging")); -} -} // namespace -} // namespace Config -} // namespace Envoy \ No newline at end of file From e2398053ccc3098944d9961762e16784a8a108cc Mon Sep 17 00:00:00 2001 From: chaoqin-li1123 Date: Thu, 6 May 2021 13:48:24 +0000 Subject: [PATCH 2/5] clean up runtime Signed-off-by: chaoqin-li1123 --- source/common/protobuf/utility.h | 2 + source/common/runtime/runtime_features.cc | 3 - test/common/config/api_type_oracle_test.cc | 3 - test/common/config/grpc_mux_impl_test.cc | 83 ----------------- test/common/config/new_grpc_mux_impl_test.cc | 98 -------------------- test/common/protobuf/BUILD | 8 -- test/common/protobuf/utility_test.cc | 9 ++ test/integration/ads_integration_test.cc | 31 ------- 8 files changed, 11 insertions(+), 226 deletions(-) diff --git a/source/common/protobuf/utility.h b/source/common/protobuf/utility.h index 2d8e64aba980f..63fea90572f3f 100644 --- a/source/common/protobuf/utility.h +++ b/source/common/protobuf/utility.h @@ -147,6 +147,8 @@ class MissingFieldException : public EnvoyException { class TypeUtil { public: static absl::string_view typeUrlToDescriptorFullName(absl::string_view type_url); + + static std::string descriptorFullNameToTypeUrl(absl::string_view type); }; class RepeatedPtrUtil { diff --git a/source/common/runtime/runtime_features.cc b/source/common/runtime/runtime_features.cc index 1503e70f21953..2d0836bdb90be 100644 --- a/source/common/runtime/runtime_features.cc +++ b/source/common/runtime/runtime_features.cc @@ -109,9 +109,6 @@ constexpr const char* runtime_features[] = { constexpr const char* disabled_runtime_features[] = { // v2 is fatal-by-default. "envoy.test_only.broken_in_production.enable_deprecated_v2_api", - // Allow Envoy to upgrade or downgrade version of type url, should be removed when support for - // v2 url is removed from codebase. - "envoy.reloadable_features.enable_type_url_downgrade_and_upgrade", // TODO(alyssawilk) flip true after the release. "envoy.reloadable_features.new_tcp_connection_pool", // TODO(asraa) flip to true in a separate PR to enable the new JSON by default. diff --git a/test/common/config/api_type_oracle_test.cc b/test/common/config/api_type_oracle_test.cc index a2454953c3bb8..327d4dc32e541 100644 --- a/test/common/config/api_type_oracle_test.cc +++ b/test/common/config/api_type_oracle_test.cc @@ -27,9 +27,6 @@ TEST(ApiTypeOracleTest, All) { EXPECT_EQ(envoy::config::filter::http::ip_tagging::v2::IPTagging::descriptor()->full_name(), ApiTypeOracle::getEarlierVersionMessageTypeName(v3_config.GetDescriptor()->full_name()) .value()); - EXPECT_EQ("envoy.config.filter.http.ip_tagging.v2.IPTagging", - TypeUtil::typeUrlToDescriptorFullName( - "type.googleapis.com/envoy.config.filter.http.ip_tagging.v2.IPTagging")); } } // namespace diff --git a/test/common/config/grpc_mux_impl_test.cc b/test/common/config/grpc_mux_impl_test.cc index a3701c919fcca..ea455d917645f 100644 --- a/test/common/config/grpc_mux_impl_test.cc +++ b/test/common/config/grpc_mux_impl_test.cc @@ -870,89 +870,6 @@ TEST_F(GrpcMuxImplTest, BadLocalInfoEmptyNodeName) { "--service-node and --service-cluster options."); } -// Send discovery request with v2 resource type_url, receive discovery response with v3 resource -// type_url. -TEST_F(GrpcMuxImplTest, WatchV2ResourceV3) { - TestScopedRuntime scoped_runtime; - Runtime::LoaderSingleton::getExisting()->mergeValues( - {{"envoy.reloadable_features.enable_type_url_downgrade_and_upgrade", "true"}}); - setup(); - - InSequence s; - const std::string& v2_type_url = Config::TypeUrl::get().ClusterLoadAssignment; - const std::string& v3_type_url = - Config::getTypeUrl( - envoy::config::core::v3::ApiVersion::V3); - TestUtility::TestOpaqueResourceDecoderImpl - resource_decoder("cluster_name"); - auto foo_sub = grpc_mux_->addWatch(v2_type_url, {}, callbacks_, resource_decoder, {}); - EXPECT_CALL(*async_client_, startRaw(_, _, _, _)).WillOnce(Return(&async_stream_)); - expectSendMessage(v2_type_url, {}, "", true); - grpc_mux_->start(); - - { - auto response = std::make_unique(); - response->set_type_url(v3_type_url); - response->set_version_info("1"); - envoy::config::endpoint::v3::ClusterLoadAssignment load_assignment; - load_assignment.set_cluster_name("x"); - response->add_resources()->PackFrom(load_assignment); - EXPECT_CALL(callbacks_, onConfigUpdate(_, "1")) - .WillOnce(Invoke([&load_assignment](const std::vector& resources, - const std::string&) { - EXPECT_EQ(1, resources.size()); - const auto& expected_assignment = - dynamic_cast( - resources[0].get().resource()); - EXPECT_TRUE(TestUtility::protoEqual(expected_assignment, load_assignment)); - })); - expectSendMessage(v2_type_url, {}, "1"); - grpc_mux_->grpcStreamForTest().onReceiveMessage(std::move(response)); - } -} - -// Send discovery request with v3 resource type_url, receive discovery response with v2 resource -// type_url. -TEST_F(GrpcMuxImplTest, WatchV3ResourceV2) { - TestScopedRuntime scoped_runtime; - Runtime::LoaderSingleton::getExisting()->mergeValues( - {{"envoy.reloadable_features.enable_type_url_downgrade_and_upgrade", "true"}}); - setup(); - - InSequence s; - const std::string& v2_type_url = Config::TypeUrl::get().ClusterLoadAssignment; - const std::string& v3_type_url = - Config::getTypeUrl( - envoy::config::core::v3::ApiVersion::V3); - TestUtility::TestOpaqueResourceDecoderImpl - resource_decoder("cluster_name"); - auto foo_sub = grpc_mux_->addWatch(v3_type_url, {}, callbacks_, resource_decoder, {}); - EXPECT_CALL(*async_client_, startRaw(_, _, _, _)).WillOnce(Return(&async_stream_)); - expectSendMessage(v3_type_url, {}, "", true); - grpc_mux_->start(); - - { - - auto response = std::make_unique(); - response->set_type_url(v2_type_url); - response->set_version_info("1"); - envoy::config::endpoint::v3::ClusterLoadAssignment load_assignment; - load_assignment.set_cluster_name("x"); - response->add_resources()->PackFrom(load_assignment); - EXPECT_CALL(callbacks_, onConfigUpdate(_, "1")) - .WillOnce(Invoke([&load_assignment](const std::vector& resources, - const std::string&) { - EXPECT_EQ(1, resources.size()); - const auto& expected_assignment = - dynamic_cast( - resources[0].get().resource()); - EXPECT_TRUE(TestUtility::protoEqual(expected_assignment, load_assignment)); - })); - expectSendMessage(v3_type_url, {}, "1"); - grpc_mux_->grpcStreamForTest().onReceiveMessage(std::move(response)); - } -} - } // namespace } // namespace Config } // namespace Envoy diff --git a/test/common/config/new_grpc_mux_impl_test.cc b/test/common/config/new_grpc_mux_impl_test.cc index b4962a3f8af41..b84cff6af5c91 100644 --- a/test/common/config/new_grpc_mux_impl_test.cc +++ b/test/common/config/new_grpc_mux_impl_test.cc @@ -220,104 +220,6 @@ TEST_F(NewGrpcMuxImplTest, ConfigUpdateWithNotFoundResponse) { response->mutable_resources()->at(0).add_aliases("prefix/domain1.test"); } -// Watch v2 resource type_url, receive discovery response with v3 resource type_url. -TEST_F(NewGrpcMuxImplTest, V3ResourceResponseV2ResourceWatch) { - TestScopedRuntime scoped_runtime; - Runtime::LoaderSingleton::getExisting()->mergeValues( - {{"envoy.reloadable_features.enable_type_url_downgrade_and_upgrade", "true"}}); - setup(); - - // Watch for v2 resource type_url. - const std::string& v2_type_url = Config::TypeUrl::get().ClusterLoadAssignment; - const std::string& v3_type_url = - Config::getTypeUrl( - envoy::config::core::v3::ApiVersion::V3); - auto watch = grpc_mux_->addWatch(v2_type_url, {}, callbacks_, resource_decoder_, {}); - - EXPECT_CALL(*async_client_, startRaw(_, _, _, _)).WillOnce(Return(&async_stream_)); - // Cluster is not watched, v3 resource is rejected. - grpc_mux_->start(); - { - auto unexpected_response = - std::make_unique(); - envoy::config::cluster::v3::Cluster cluster; - unexpected_response->set_type_url(Config::getTypeUrl( - envoy::config::core::v3::ApiVersion::V3)); - unexpected_response->set_system_version_info("0"); - unexpected_response->add_resources()->mutable_resource()->PackFrom(cluster); - EXPECT_CALL(callbacks_, onConfigUpdate(_, _, "0")).Times(0); - grpc_mux_->onDiscoveryResponse(std::move(unexpected_response), control_plane_stats_); - } - // Cluster is not watched, v2 resource is rejected. - { - auto unexpected_response = - std::make_unique(); - envoy::config::cluster::v3::Cluster cluster; - unexpected_response->set_type_url(Config::TypeUrl::get().Cluster); - unexpected_response->set_system_version_info("0"); - unexpected_response->add_resources()->mutable_resource()->PackFrom(cluster); - EXPECT_CALL(callbacks_, onConfigUpdate(_, _, "0")).Times(0); - grpc_mux_->onDiscoveryResponse(std::move(unexpected_response), control_plane_stats_); - } - // ClusterLoadAssignment v2 is watched, v3 resource will be accepted. - { - auto response = std::make_unique(); - response->set_system_version_info("1"); - envoy::config::endpoint::v3::ClusterLoadAssignment load_assignment; - load_assignment.set_cluster_name("x"); - response->add_resources()->mutable_resource()->PackFrom(load_assignment); - // Send response that contains resource with v3 type url. - response->set_type_url(v3_type_url); - EXPECT_CALL(callbacks_, onConfigUpdate(_, _, "1")) - .WillOnce(Invoke([&load_assignment](const std::vector& added_resources, - const Protobuf::RepeatedPtrField&, - const std::string&) { - EXPECT_EQ(1, added_resources.size()); - EXPECT_TRUE( - TestUtility::protoEqual(added_resources[0].get().resource(), load_assignment)); - })); - grpc_mux_->onDiscoveryResponse(std::move(response), control_plane_stats_); - } -} - -// Watch v3 resource type_url, receive discovery response with v2 resource type_url. -TEST_F(NewGrpcMuxImplTest, V2ResourceResponseV3ResourceWatch) { - TestScopedRuntime scoped_runtime; - Runtime::LoaderSingleton::getExisting()->mergeValues( - {{"envoy.reloadable_features.enable_type_url_downgrade_and_upgrade", "true"}}); - setup(); - - // Watch for v3 resource type_url. - const std::string& v3_type_url = - Config::getTypeUrl( - envoy::config::core::v3::ApiVersion::V3); - const std::string& v2_type_url = Config::TypeUrl::get().ClusterLoadAssignment; - auto watch = grpc_mux_->addWatch(v3_type_url, {}, callbacks_, resource_decoder_, {}); - - EXPECT_CALL(*async_client_, startRaw(_, _, _, _)).WillOnce(Return(&async_stream_)); - - grpc_mux_->start(); - // ClusterLoadAssignment v3 is watched, v2 resource will be accepted. - { - auto response = std::make_unique(); - response->set_system_version_info("1"); - envoy::config::endpoint::v3::ClusterLoadAssignment load_assignment; - load_assignment.set_cluster_name("x"); - response->add_resources()->mutable_resource()->PackFrom(load_assignment); - // Send response that contains resource with v3 type url. - response->set_type_url(v2_type_url); - EXPECT_CALL(callbacks_, onConfigUpdate(_, _, "1")) - .WillOnce(Invoke([&load_assignment](const std::vector& added_resources, - const Protobuf::RepeatedPtrField&, - const std::string&) { - EXPECT_EQ(1, added_resources.size()); - EXPECT_TRUE( - TestUtility::protoEqual(added_resources[0].get().resource(), load_assignment)); - })); - grpc_mux_->onDiscoveryResponse(std::move(response), control_plane_stats_); - } -} - // Validate basic gRPC mux subscriptions to xdstp:// glob collections. TEST_F(NewGrpcMuxImplTest, XdsTpGlobCollection) { setup(); diff --git a/test/common/protobuf/BUILD b/test/common/protobuf/BUILD index e022b00f52b01..1118273fdbac0 100644 --- a/test/common/protobuf/BUILD +++ b/test/common/protobuf/BUILD @@ -49,14 +49,6 @@ envoy_cc_test( ], ) -envoy_cc_test( - name = "type_util_test", - srcs = ["type_util_test.cc"], - deps = [ - "//source/common/protobuf:type_util_lib", - ], -) - envoy_cc_fuzz_test( name = "value_util_fuzz_test", srcs = ["value_util_fuzz_test.cc"], diff --git a/test/common/protobuf/utility_test.cc b/test/common/protobuf/utility_test.cc index dd4fdda8587e6..990e019285f19 100644 --- a/test/common/protobuf/utility_test.cc +++ b/test/common/protobuf/utility_test.cc @@ -2009,4 +2009,13 @@ TEST(StatusCode, Strings) { ASSERT_EQ("OK", MessageUtil::CodeEnumToString(ProtobufUtil::error::OK)); } +TEST(TypeUtilTest, TypeUrlHelperFunction) { + EXPECT_EQ("envoy.config.filter.http.ip_tagging.v2.IPTagging", + TypeUtil::typeUrlToDescriptorFullName( + "type.googleapis.com/envoy.config.filter.http.ip_tagging.v2.IPTagging")); + EXPECT_EQ( + "type.googleapis.com/envoy.config.filter.http.ip_tagging.v2.IPTagging", + TypeUtil::descriptorFullNameToTypeUrl("envoy.config.filter.http.ip_tagging.v2.IPTagging")); +} + } // namespace Envoy diff --git a/test/integration/ads_integration_test.cc b/test/integration/ads_integration_test.cc index 84e69912c209a..8a0bfc7b78e81 100644 --- a/test/integration/ads_integration_test.cc +++ b/test/integration/ads_integration_test.cc @@ -333,37 +333,6 @@ TEST_P(AdsIntegrationTest, ResendNodeOnStreamReset) { {"cluster_0"}, {}, true)); } -// Validate that xds can support a mix of v2 and v3 type url. -TEST_P(AdsIntegrationTest, MixV2V3TypeUrlInDiscoveryResponse) { - config_helper_.addRuntimeOverride( - "envoy.reloadable_features.enable_type_url_downgrade_and_upgrade", "true"); - initialize(); - - // Send initial configuration. - // Discovery response with v3 type url. - sendDiscoveryResponse( - Config::getTypeUrl( - envoy::config::core::v3::ApiVersion::V3), - {buildCluster("cluster_0")}, {buildCluster("cluster_0")}, {}, "1", false); - // Discovery response with v2 type url. - sendDiscoveryResponse( - Config::TypeUrl::get().ClusterLoadAssignment, {buildClusterLoadAssignment("cluster_0")}, - {buildClusterLoadAssignment("cluster_0")}, {}, "1"); - // Discovery response with v3 type url. - sendDiscoveryResponse( - Config::getTypeUrl( - envoy::config::core::v3::ApiVersion::V3), - {buildListener("listener_0", "route_config_0")}, - {buildListener("listener_0", "route_config_0")}, {}, "1", false); - // Discovery response with v2 type url. - sendDiscoveryResponse( - Config::TypeUrl::get().RouteConfiguration, {buildRouteConfig("route_config_0", "cluster_0")}, - {buildRouteConfig("route_config_0", "cluster_0")}, {}, "1"); - test_server_->waitForCounterGe("listener_manager.listener_create_success", 1); - - // Validate that we can process a request. - makeSingleRequest(); -} // Validate that the request with duplicate listeners is rejected. TEST_P(AdsIntegrationTest, DuplicateWarmingListeners) { From 42a6469a0b983e51370d0677eff46727aa1aa9a9 Mon Sep 17 00:00:00 2001 From: chaoqin-li1123 Date: Thu, 6 May 2021 13:55:13 +0000 Subject: [PATCH 3/5] format Signed-off-by: chaoqin-li1123 --- source/common/config/api_type_oracle.cc | 1 - source/common/config/new_grpc_mux_impl.h | 1 - test/integration/ads_integration_test.cc | 1 - 3 files changed, 3 deletions(-) diff --git a/source/common/config/api_type_oracle.cc b/source/common/config/api_type_oracle.cc index 467622dabd3ea..8762392af5cbd 100644 --- a/source/common/config/api_type_oracle.cc +++ b/source/common/config/api_type_oracle.cc @@ -32,6 +32,5 @@ ApiTypeOracle::getEarlierVersionMessageTypeName(const std::string& message_type) return absl::nullopt; } - } // namespace Config } // namespace Envoy diff --git a/source/common/config/new_grpc_mux_impl.h b/source/common/config/new_grpc_mux_impl.h index cfd1e122a1777..fd5bcb2e9d69d 100644 --- a/source/common/config/new_grpc_mux_impl.h +++ b/source/common/config/new_grpc_mux_impl.h @@ -160,7 +160,6 @@ class NewGrpcMuxImpl Common::CallbackHandlePtr dynamic_update_callback_handle_; const envoy::config::core::v3::ApiVersion transport_api_version_; Event::Dispatcher& dispatcher_; - }; using NewGrpcMuxImplPtr = std::unique_ptr; diff --git a/test/integration/ads_integration_test.cc b/test/integration/ads_integration_test.cc index 8a0bfc7b78e81..4102c8d84637c 100644 --- a/test/integration/ads_integration_test.cc +++ b/test/integration/ads_integration_test.cc @@ -333,7 +333,6 @@ TEST_P(AdsIntegrationTest, ResendNodeOnStreamReset) { {"cluster_0"}, {}, true)); } - // Validate that the request with duplicate listeners is rejected. TEST_P(AdsIntegrationTest, DuplicateWarmingListeners) { initialize(); From f03802f397788b8e712bf674accfba9e22447f32 Mon Sep 17 00:00:00 2001 From: chaoqin-li1123 Date: Thu, 6 May 2021 15:13:23 +0000 Subject: [PATCH 4/5] clean redundant include Signed-off-by: chaoqin-li1123 --- test/common/config/grpc_mux_impl_test.cc | 1 - test/common/config/new_grpc_mux_impl_test.cc | 1 - 2 files changed, 2 deletions(-) diff --git a/test/common/config/grpc_mux_impl_test.cc b/test/common/config/grpc_mux_impl_test.cc index ea455d917645f..8e1ac0945f698 100644 --- a/test/common/config/grpc_mux_impl_test.cc +++ b/test/common/config/grpc_mux_impl_test.cc @@ -24,7 +24,6 @@ #include "test/test_common/logging.h" #include "test/test_common/resources.h" #include "test/test_common/simulated_time_system.h" -#include "test/test_common/test_runtime.h" #include "test/test_common/test_time.h" #include "test/test_common/utility.h" diff --git a/test/common/config/new_grpc_mux_impl_test.cc b/test/common/config/new_grpc_mux_impl_test.cc index b84cff6af5c91..b8c9166f8c0d1 100644 --- a/test/common/config/new_grpc_mux_impl_test.cc +++ b/test/common/config/new_grpc_mux_impl_test.cc @@ -21,7 +21,6 @@ #include "test/test_common/logging.h" #include "test/test_common/resources.h" #include "test/test_common/simulated_time_system.h" -#include "test/test_common/test_runtime.h" #include "test/test_common/test_time.h" #include "test/test_common/utility.h" From 38b90b108c9fbbbd6f49aec8a916ceb57431ab12 Mon Sep 17 00:00:00 2001 From: chaoqin-li1123 Date: Thu, 6 May 2021 19:48:32 +0000 Subject: [PATCH 5/5] fix docs Signed-off-by: chaoqin-li1123 --- docs/root/version_history/v1.16.0.rst | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/docs/root/version_history/v1.16.0.rst b/docs/root/version_history/v1.16.0.rst index df8c03ab42f0b..32cb2a70dd236 100644 --- a/docs/root/version_history/v1.16.0.rst +++ b/docs/root/version_history/v1.16.0.rst @@ -150,19 +150,6 @@ New Features * tap: added :ref:`generic body matcher ` to scan http requests and responses for text or hex patterns. * tcp_proxy: added :ref:`max_downstream_connection_duration ` for downstream connection. When max duration is reached the connection will be closed. * tcp_proxy: allow earlier network filters to set metadataMatchCriteria on the connection StreamInfo to influence load balancing. -<<<<<<< HEAD -* tls: added OCSP stapling support through the :ref:`ocsp_staple ` and :ref:`ocsp_staple_policy ` configuration options. See :ref:`OCSP Stapling ` for usage and runtime flags. -* tls: introduce new :ref:`extension point` for overriding :ref:`TLS handshaker ` behavior. -* tls: switched from using socket BIOs to using custom BIOs that know how to interact with IoHandles. The feature can be disabled by setting runtime feature `envoy.reloadable_features.tls_use_io_handle_bio` to false. -* tracing: added ability to set some :ref:`optional segment fields` in the AWS X-Ray tracer. -* udp_proxy: added :ref:`hash_policies ` to support hash based routing. -* udp_proxy: added :ref:`use_original_src_ip ` option to replicate the downstream remote address of the packets on the upstream side of Envoy. It is similar to :ref:`original source filter `. -* watchdog: support randomizing the watchdog's kill timeout to prevent synchronized kills via a maximium jitter parameter :ref:`max_kill_timeout_jitter`. -* watchdog: supports an extension point where actions can be registered to fire on watchdog events such as miss, megamiss, kill and multikill. See :ref:`watchdog actions`. -* watchdog: watchdog action extension that does cpu profiling. See :ref:`Profile Action `. -* watchdog: watchdog action extension that sends SIGABRT to the stuck thread to terminate the process. See :ref:`Abort Action `. -* xds: added :ref:`extension config discovery` support for HTTP filters. -======= * tls: added OCSP stapling support through the :ref:`ocsp_staple ` and :ref:`ocsp_staple_policy ` configuration options. See :ref:`OCSP Stapling ` for usage and runtime flags. * tls: introduce new :ref:`extension point ` for overriding :ref:`TLS handshaker ` behavior. * tls: switched from using socket BIOs to using custom BIOs that know how to interact with IoHandles. The feature can be disabled by setting runtime feature ``envoy.reloadable_features.tls_use_io_handle_bio`` to false. @@ -175,7 +162,6 @@ New Features * watchdog: watchdog action extension that sends SIGABRT to the stuck thread to terminate the process. See :ref:`Abort Action `. * xds: added :ref:`extension config discovery ` support for HTTP filters. * xds: added support for mixed v2/v3 discovery response, which enable type url downgrade and upgrade. This feature is disabled by default and is controlled by runtime guard ``envoy.reloadable_features.enable_type_url_downgrade_and_upgrade``. ->>>>>>> 4c078edb82e4956a1717cf841c095d2dd63cccca * zlib: added option to use `zlib-ng `_ as zlib library. Deprecated