Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 0 additions & 3 deletions include/envoy/config/grpc_mux.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,6 @@ class GrpcMux {

virtual void requestOnDemandUpdate(const std::string& type_url,
const absl::flat_hash_set<std::string>& for_update) PURE;

using TypeUrlMap = absl::flat_hash_map<std::string, std::string>;
static TypeUrlMap& typeUrlMap() { MUTABLE_CONSTRUCT_ON_FIRST_USE(TypeUrlMap, {}); }
};

using GrpcMuxPtr = std::unique_ptr<GrpcMux>;
Expand Down
1 change: 0 additions & 1 deletion source/common/config/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
)
Expand Down
9 changes: 0 additions & 9 deletions source/common/config/api_type_oracle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,5 @@ ApiTypeOracle::getEarlierVersionMessageTypeName(const std::string& message_type)
return absl::nullopt;
}

const absl::optional<std::string> ApiTypeOracle::getEarlierTypeUrl(const std::string& type_url) {
const std::string type{TypeUtil::typeUrlToDescriptorFullName(type_url)};
absl::optional<std::string> old_type = ApiTypeOracle::getEarlierVersionMessageTypeName(type);
if (old_type.has_value()) {
return TypeUtil::descriptorFullNameToTypeUrl(old_type.value());
}
return {};
}

} // namespace Config
} // namespace Envoy
3 changes: 0 additions & 3 deletions source/common/config/api_type_oracle.h
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -24,8 +23,6 @@ class ApiTypeOracle {

static const absl::optional<std::string>
getEarlierVersionMessageTypeName(const std::string& message_type);

static const absl::optional<std::string> getEarlierTypeUrl(const std::string& type_url);
};

} // namespace Config
Expand Down
34 changes: 4 additions & 30 deletions source/common/config/grpc_mux_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -137,36 +132,15 @@ ScopedResume GrpcMuxImpl::pause(const std::vector<std::string> 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<std::string> 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<envoy::service::discovery::v3::DiscoveryResponse>&& 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
Expand Down Expand Up @@ -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<envoy::service::discovery::v3::Resource>() &&
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 =
Expand Down
3 changes: 0 additions & 3 deletions source/common/config/grpc_mux_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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<envoy::service::discovery::v3::DiscoveryResponse>&& message,
ControlPlaneStats& control_plane_stats) override;
Expand Down Expand Up @@ -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_;
};

Expand Down
1 change: 0 additions & 1 deletion source/common/config/grpc_subscription_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
31 changes: 1 addition & 30 deletions source/common/config/new_grpc_mux_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -62,20 +60,6 @@ ScopedResume NewGrpcMuxImpl::pause(const std::vector<std::string> 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<std::string> 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<envoy::service::discovery::v3::DeltaDiscoveryResponse>&& message,
ControlPlaneStats& control_plane_stats) {
Expand All @@ -85,15 +69,6 @@ void NewGrpcMuxImpl::onDiscoveryResponse(
control_plane_stats.identifier_.set(message->control_plane().identifier());
}
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 "
Expand Down Expand Up @@ -153,10 +128,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);
}
// No resources implies that this is a wildcard request subscription.
addSubscription(type_url, options.use_namespace_matching_, resources.empty());
return addWatch(type_url, resources, callbacks, resource_decoder, options);
}
Expand Down
4 changes: 0 additions & 4 deletions source/common/config/new_grpc_mux_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ class NewGrpcMuxImpl
ScopedResume pause(const std::string& type_url) override;
ScopedResume pause(const std::vector<std::string> type_urls) override;

void registerVersionedTypeUrl(const std::string& type_url);

void onDiscoveryResponse(
std::unique_ptr<envoy::service::discovery::v3::DeltaDiscoveryResponse>&& message,
ControlPlaneStats& control_plane_stats) override;
Expand Down Expand Up @@ -171,8 +169,6 @@ class NewGrpcMuxImpl
Common::CallbackHandlePtr dynamic_update_callback_handle_;
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<NewGrpcMuxImpl>;
Expand Down
1 change: 1 addition & 0 deletions source/common/config/subscription_factory_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
11 changes: 0 additions & 11 deletions source/common/protobuf/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -81,16 +80,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"],
Expand Down
17 changes: 0 additions & 17 deletions source/common/protobuf/type_util.cc

This file was deleted.

17 changes: 0 additions & 17 deletions source/common/protobuf/type_util.h

This file was deleted.

13 changes: 13 additions & 0 deletions source/common/protobuf/utility.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1043,4 +1043,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
7 changes: 7 additions & 0 deletions source/common/protobuf/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,13 @@ 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);

static std::string descriptorFullNameToTypeUrl(absl::string_view type);
};

class RepeatedPtrUtil {
public:
static std::string join(const Protobuf::RepeatedPtrField<std::string>& source,
Expand Down
3 changes: 0 additions & 3 deletions source/common/runtime/runtime_features.cc
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,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.
Expand Down
3 changes: 0 additions & 3 deletions test/common/config/api_type_oracle_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading