diff --git a/include/envoy/config/grpc_mux.h b/include/envoy/config/grpc_mux.h index 6e19534619bb3..2d16c66270dd6 100644 --- a/include/envoy/config/grpc_mux.h +++ b/include/envoy/config/grpc_mux.h @@ -1,5 +1,7 @@ #pragma once +#include + #include "envoy/common/exception.h" #include "envoy/common/pure.h" #include "envoy/config/subscription.h" @@ -119,6 +121,7 @@ class GrpcMux { using GrpcMuxPtr = std::unique_ptr; using GrpcMuxSharedPtr = std::shared_ptr; +template using ResponseProtoPtr = std::unique_ptr; /** * A grouping of callbacks that a GrpcMux should provide to its GrpcStream. */ @@ -141,7 +144,7 @@ template class GrpcStreamCallbacks { /** * For the GrpcStream to pass received protos to the context. */ - virtual void onDiscoveryResponse(std::unique_ptr&& message, + virtual void onDiscoveryResponse(ResponseProtoPtr&& message, ControlPlaneStats& control_plane_stats) PURE; /** diff --git a/source/common/config/grpc_mux_impl.h b/source/common/config/grpc_mux_impl.h index a623bed2a08a2..f2dfc95297147 100644 --- a/source/common/config/grpc_mux_impl.h +++ b/source/common/config/grpc_mux_impl.h @@ -1,5 +1,6 @@ #pragma once +#include #include #include @@ -141,6 +142,9 @@ class GrpcMuxImpl : public GrpcMux, const envoy::config::core::v3::ApiVersion transport_api_version_; }; +using GrpcMuxImplPtr = std::unique_ptr; +using GrpcMuxImplSharedPtr = std::shared_ptr; + class NullGrpcMuxImpl : public GrpcMux, GrpcStreamCallbacks { public: diff --git a/source/common/config/grpc_stream.h b/source/common/config/grpc_stream.h index 2b4187aac3132..5ac368deea0d1 100644 --- a/source/common/config/grpc_stream.h +++ b/source/common/config/grpc_stream.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include "envoy/common/random_generator.h" #include "envoy/config/grpc_mux.h" @@ -14,6 +15,8 @@ namespace Envoy { namespace Config { +template using ResponseProtoPtr = std::unique_ptr; + // Oversees communication for gRPC xDS implementations (parent to both regular xDS and delta // xDS variants). Reestablishes the gRPC channel when necessary, and provides rate limiting of // requests. @@ -75,7 +78,7 @@ class GrpcStream : public Grpc::AsyncStreamCallbacks, UNREFERENCED_PARAMETER(metadata); } - void onReceiveMessage(std::unique_ptr&& message) override { + void onReceiveMessage(ResponseProtoPtr&& message) override { // Reset here so that it starts with fresh backoff interval on next disconnect. backoff_strategy_->reset(); // Sometimes during hot restarts this stat's value becomes inconsistent and will continue to diff --git a/source/common/config/grpc_subscription_impl.h b/source/common/config/grpc_subscription_impl.h index b53da3c6e254d..a5102055a08ce 100644 --- a/source/common/config/grpc_subscription_impl.h +++ b/source/common/config/grpc_subscription_impl.h @@ -1,5 +1,7 @@ #pragma once +#include + #include "envoy/config/grpc_mux.h" #include "envoy/config/subscription.h" #include "envoy/event/dispatcher.h" @@ -54,5 +56,8 @@ class GrpcSubscriptionImpl : public Subscription, const bool is_aggregated_; }; +using GrpcSubscriptionImplPtr = std::unique_ptr; +using GrpcSubscriptionImplSharedPtr = std::shared_ptr; + } // 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 5eb226992f78c..6c3198f94cc11 100644 --- a/source/common/config/new_grpc_mux_impl.h +++ b/source/common/config/new_grpc_mux_impl.h @@ -1,5 +1,7 @@ #pragma once +#include + #include "envoy/api/v2/discovery.pb.h" #include "envoy/common/random_generator.h" #include "envoy/common/token_bucket.h" @@ -70,8 +72,10 @@ class NewGrpcMuxImpl SubscriptionStuff& operator=(const SubscriptionStuff&) = delete; }; + using SubscriptionStuffPtr = std::unique_ptr; + // for use in tests only - const absl::flat_hash_map>& subscriptions() { + const absl::flat_hash_map& subscriptions() { return subscriptions_; } @@ -130,7 +134,7 @@ class NewGrpcMuxImpl PausableAckQueue pausable_ack_queue_; // Map key is type_url. - absl::flat_hash_map> subscriptions_; + absl::flat_hash_map subscriptions_; // Determines the order of initial discovery requests. (Assumes that subscriptions are added in // the order of Envoy's dependency ordering). @@ -145,6 +149,7 @@ class NewGrpcMuxImpl const envoy::config::core::v3::ApiVersion transport_api_version_; }; +using NewGrpcMuxImplPtr = std::unique_ptr; using NewGrpcMuxImplSharedPtr = std::shared_ptr; } // namespace Config diff --git a/source/common/grpc/async_client_impl.cc b/source/common/grpc/async_client_impl.cc index ecb5709288f71..c35a5fb600335 100644 --- a/source/common/grpc/async_client_impl.cc +++ b/source/common/grpc/async_client_impl.cc @@ -31,7 +31,7 @@ AsyncRequest* AsyncClientImpl::sendRaw(absl::string_view service_full_name, const Http::AsyncClient::RequestOptions& options) { auto* const async_request = new AsyncRequestImpl( *this, service_full_name, method_name, std::move(request), callbacks, parent_span, options); - std::unique_ptr grpc_stream{async_request}; + AsyncStreamImplPtr grpc_stream{async_request}; grpc_stream->initialize(true); if (grpc_stream->hasResetStream()) { diff --git a/source/common/grpc/async_client_impl.h b/source/common/grpc/async_client_impl.h index 750183afd4f5e..9b49826eb6927 100644 --- a/source/common/grpc/async_client_impl.h +++ b/source/common/grpc/async_client_impl.h @@ -1,5 +1,7 @@ #pragma once +#include + #include "envoy/config/core/v3/base.pb.h" #include "envoy/config/core/v3/grpc_service.pb.h" #include "envoy/grpc/async_client.h" @@ -13,7 +15,9 @@ namespace Envoy { namespace Grpc { class AsyncRequestImpl; + class AsyncStreamImpl; +using AsyncStreamImplPtr = std::unique_ptr; class AsyncClientImpl final : public RawAsyncClient { public: @@ -34,7 +38,7 @@ class AsyncClientImpl final : public RawAsyncClient { Upstream::ClusterManager& cm_; const std::string remote_cluster_name_; const Protobuf::RepeatedPtrField initial_metadata_; - std::list> active_streams_; + std::list active_streams_; TimeSource& time_source_; friend class AsyncRequestImpl; diff --git a/source/common/grpc/google_async_client_impl.cc b/source/common/grpc/google_async_client_impl.cc index d22903da723e1..be37dcc28d911 100644 --- a/source/common/grpc/google_async_client_impl.cc +++ b/source/common/grpc/google_async_client_impl.cc @@ -112,7 +112,7 @@ AsyncRequest* GoogleAsyncClientImpl::sendRaw(absl::string_view service_full_name const Http::AsyncClient::RequestOptions& options) { auto* const async_request = new GoogleAsyncRequestImpl( *this, service_full_name, method_name, std::move(request), callbacks, parent_span, options); - std::unique_ptr grpc_stream{async_request}; + GoogleAsyncStreamImplPtr grpc_stream{async_request}; grpc_stream->initialize(true); if (grpc_stream->callFailed()) { @@ -381,7 +381,7 @@ void GoogleAsyncStreamImpl::deferredDelete() { // Hence, it is safe here to create a unique_ptr to this and transfer // ownership to dispatcher_.deferredDelete(). After this call, no further // methods may be invoked on this object. - dispatcher_.deferredDelete(std::unique_ptr(this)); + dispatcher_.deferredDelete(GoogleAsyncStreamImplPtr(this)); } void GoogleAsyncStreamImpl::cleanup() { diff --git a/source/common/grpc/google_async_client_impl.h b/source/common/grpc/google_async_client_impl.h index 75229bd5905fb..6a576df3497af 100644 --- a/source/common/grpc/google_async_client_impl.h +++ b/source/common/grpc/google_async_client_impl.h @@ -29,6 +29,9 @@ namespace Envoy { namespace Grpc { class GoogleAsyncStreamImpl; + +using GoogleAsyncStreamImplPtr = std::unique_ptr; + class GoogleAsyncRequestImpl; struct GoogleAsyncTag { @@ -109,6 +112,8 @@ class GoogleAsyncClientThreadLocal : public ThreadLocal::ThreadLocalObject, std::unordered_set streams_; }; +using GoogleAsyncClientThreadLocalPtr = std::unique_ptr; + // Google gRPC client stats. TODO(htuch): consider how a wider set of stats collected by the // library, such as the census related ones, can be externalized as needed. struct GoogleAsyncClientStats { @@ -189,7 +194,7 @@ class GoogleAsyncClientImpl final : public RawAsyncClient, Logger::Loggable> active_streams_; + std::list active_streams_; const std::string stat_prefix_; const Protobuf::RepeatedPtrField initial_metadata_; Stats::ScopeSharedPtr scope_; diff --git a/source/common/grpc/typed_async_client.h b/source/common/grpc/typed_async_client.h index 1de73ff6e8d97..241926ee4ed70 100644 --- a/source/common/grpc/typed_async_client.h +++ b/source/common/grpc/typed_async_client.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include "envoy/grpc/async_client.h" @@ -62,17 +63,19 @@ template class AsyncStream /* : public RawAsyncStream */ { RawAsyncStream* stream_{}; }; +template using ResponsePtr = std::unique_ptr; + /** * Convenience subclasses for AsyncRequestCallbacks. */ template class AsyncRequestCallbacks : public RawAsyncRequestCallbacks { public: ~AsyncRequestCallbacks() override = default; - virtual void onSuccess(std::unique_ptr&& response, Tracing::Span& span) PURE; + virtual void onSuccess(ResponsePtr&& response, Tracing::Span& span) PURE; private: void onSuccessRaw(Buffer::InstancePtr&& response, Tracing::Span& span) override { - auto message = std::unique_ptr(dynamic_cast( + auto message = ResponsePtr(dynamic_cast( Internal::parseMessageUntyped(std::make_unique(), std::move(response)) .release())); if (!message) { @@ -138,11 +141,11 @@ class VersionedMethods { template class AsyncStreamCallbacks : public RawAsyncStreamCallbacks { public: ~AsyncStreamCallbacks() override = default; - virtual void onReceiveMessage(std::unique_ptr&& message) PURE; + virtual void onReceiveMessage(ResponsePtr&& message) PURE; private: bool onReceiveMessageRaw(Buffer::InstancePtr&& response) override { - auto message = std::unique_ptr(dynamic_cast( + auto message = ResponsePtr(dynamic_cast( Internal::parseMessageUntyped(std::make_unique(), std::move(response)) .release())); if (!message) { diff --git a/source/extensions/access_loggers/grpc/config_utils.cc b/source/extensions/access_loggers/grpc/config_utils.cc index e950aea731fbb..aa59f2f28018c 100644 --- a/source/extensions/access_loggers/grpc/config_utils.cc +++ b/source/extensions/access_loggers/grpc/config_utils.cc @@ -10,7 +10,7 @@ namespace GrpcCommon { // Singleton registration via macro defined in envoy/singleton/manager.h SINGLETON_MANAGER_REGISTRATION(grpc_access_logger_cache); -std::shared_ptr +GrpcCommon::GrpcAccessLoggerCacheSharedPtr getGrpcAccessLoggerCacheSingleton(Server::Configuration::FactoryContext& context) { return context.singletonManager().getTyped( SINGLETON_MANAGER_REGISTERED_NAME(grpc_access_logger_cache), [&context] { diff --git a/source/extensions/access_loggers/grpc/grpc_access_log_impl.h b/source/extensions/access_loggers/grpc/grpc_access_log_impl.h index b79a7ad1b8d56..5cf04837c49b0 100644 --- a/source/extensions/access_loggers/grpc/grpc_access_log_impl.h +++ b/source/extensions/access_loggers/grpc/grpc_access_log_impl.h @@ -1,5 +1,6 @@ #pragma once +#include #include #include @@ -129,6 +130,8 @@ class GrpcAccessLoggerImpl : public GrpcAccessLogger { const envoy::config::core::v3::ApiVersion transport_api_version_; }; +using GrpcAccessLoggerImplPtr = std::unique_ptr; + class GrpcAccessLoggerCacheImpl : public Singleton::Instance, public GrpcAccessLoggerCache { public: GrpcAccessLoggerCacheImpl(Grpc::AsyncClientManager& async_client_manager, Stats::Scope& scope, @@ -158,6 +161,8 @@ class GrpcAccessLoggerCacheImpl : public Singleton::Instance, public GrpcAccessL const LocalInfo::LocalInfo& local_info_; }; +using GrpcAccessLoggerCacheImplPtr = std::unique_ptr; + } // namespace GrpcCommon } // namespace AccessLoggers } // namespace Extensions diff --git a/source/extensions/access_loggers/grpc/http_grpc_access_log_impl.h b/source/extensions/access_loggers/grpc/http_grpc_access_log_impl.h index 0c1a80180fa93..0d6ec73ac0fde 100644 --- a/source/extensions/access_loggers/grpc/http_grpc_access_log_impl.h +++ b/source/extensions/access_loggers/grpc/http_grpc_access_log_impl.h @@ -1,5 +1,6 @@ #pragma once +#include #include #include @@ -59,6 +60,8 @@ class HttpGrpcAccessLog : public Common::ImplBase { std::vector filter_states_to_log_; }; +using HttpGrpcAccessLogPtr = std::unique_ptr; + } // namespace HttpGrpc } // namespace AccessLoggers } // namespace Extensions diff --git a/source/extensions/common/aws/region_provider.h b/source/extensions/common/aws/region_provider.h index aa87f90c173db..33a4fa2803b2c 100644 --- a/source/extensions/common/aws/region_provider.h +++ b/source/extensions/common/aws/region_provider.h @@ -1,5 +1,7 @@ #pragma once +#include + #include "envoy/common/pure.h" #include "absl/types/optional.h" @@ -23,6 +25,7 @@ class RegionProvider { virtual absl::optional getRegion() PURE; }; +using RegionProviderPtr = std::unique_ptr; using RegionProviderSharedPtr = std::shared_ptr; } // namespace Aws diff --git a/source/extensions/filters/common/ext_authz/ext_authz_grpc_impl.h b/source/extensions/filters/common/ext_authz/ext_authz_grpc_impl.h index ad9799940e9fb..da1ed1d2ebf1e 100644 --- a/source/extensions/filters/common/ext_authz/ext_authz_grpc_impl.h +++ b/source/extensions/filters/common/ext_authz/ext_authz_grpc_impl.h @@ -2,6 +2,7 @@ #include #include +#include #include #include @@ -73,6 +74,8 @@ class GrpcClientImpl : public Client, const envoy::config::core::v3::ApiVersion transport_api_version_; }; +using GrpcClientImplPtr = std::unique_ptr; + } // namespace ExtAuthz } // namespace Common } // namespace Filters diff --git a/source/extensions/filters/http/grpc_http1_reverse_bridge/filter.h b/source/extensions/filters/http/grpc_http1_reverse_bridge/filter.h index 8a518783bf5d6..12707aac9f6c4 100644 --- a/source/extensions/filters/http/grpc_http1_reverse_bridge/filter.h +++ b/source/extensions/filters/http/grpc_http1_reverse_bridge/filter.h @@ -1,5 +1,6 @@ #pragma once +#include #include #include "envoy/extensions/filters/http/grpc_http1_reverse_bridge/v3/config.pb.h" @@ -48,6 +49,8 @@ class Filter : public Envoy::Http::PassThroughFilter { Buffer::OwnedImpl buffer_{}; }; +using FilterPtr = std::unique_ptr; + class FilterConfigPerRoute : public Router::RouteSpecificFilterConfig { public: FilterConfigPerRoute( diff --git a/source/extensions/filters/http/grpc_json_transcoder/json_transcoder_filter.cc b/source/extensions/filters/http/grpc_json_transcoder/json_transcoder_filter.cc index 15b65e026d6db..222b9dbf00fbc 100644 --- a/source/extensions/filters/http/grpc_json_transcoder/json_transcoder_filter.cc +++ b/source/extensions/filters/http/grpc_json_transcoder/json_transcoder_filter.cc @@ -31,14 +31,19 @@ using Envoy::ProtobufUtil::Status; using Envoy::ProtobufUtil::error::Code; using google::api::HttpRule; using google::grpc::transcoding::JsonRequestTranslator; +using JsonRequestTranslatorPtr = std::unique_ptr; using google::grpc::transcoding::MessageStream; using google::grpc::transcoding::PathMatcherBuilder; using google::grpc::transcoding::PathMatcherUtility; using google::grpc::transcoding::RequestInfo; using google::grpc::transcoding::RequestMessageTranslator; +using RequestMessageTranslatorPtr = std::unique_ptr; using google::grpc::transcoding::ResponseToJsonTranslator; +using ResponseToJsonTranslatorPtr = std::unique_ptr; using google::grpc::transcoding::Transcoder; +using TranscoderPtr = std::unique_ptr; using google::grpc::transcoding::TranscoderInputStream; +using TranscoderInputStreamPtr = std::unique_ptr; namespace Envoy { namespace Extensions { @@ -71,9 +76,9 @@ class TranscoderImpl : public Transcoder { * @param request_translator a JsonRequestTranslator that does the request translation * @param response_translator a ResponseToJsonTranslator that does the response translation */ - TranscoderImpl(std::unique_ptr request_translator, - std::unique_ptr json_request_translator, - std::unique_ptr response_translator) + TranscoderImpl(RequestMessageTranslatorPtr request_translator, + JsonRequestTranslatorPtr json_request_translator, + ResponseToJsonTranslatorPtr response_translator) : request_translator_(std::move(request_translator)), json_request_translator_(std::move(json_request_translator)), request_message_stream_(request_translator_ ? *request_translator_ @@ -92,12 +97,12 @@ class TranscoderImpl : public Transcoder { ProtobufUtil::Status ResponseStatus() override { return response_translator_->Status(); } private: - std::unique_ptr request_translator_; - std::unique_ptr json_request_translator_; + RequestMessageTranslatorPtr request_translator_; + JsonRequestTranslatorPtr json_request_translator_; MessageStream& request_message_stream_; - std::unique_ptr response_translator_; - std::unique_ptr request_stream_; - std::unique_ptr response_stream_; + ResponseToJsonTranslatorPtr response_translator_; + TranscoderInputStreamPtr request_stream_; + TranscoderInputStreamPtr response_stream_; }; } // namespace @@ -279,8 +284,8 @@ bool JsonTranscoderConfig::convertGrpcStatus() const { return convert_grpc_statu ProtobufUtil::Status JsonTranscoderConfig::createTranscoder( const Http::RequestHeaderMap& headers, ZeroCopyInputStream& request_input, - google::grpc::transcoding::TranscoderInputStream& response_input, - std::unique_ptr& transcoder, MethodInfoSharedPtr& method_info) { + google::grpc::transcoding::TranscoderInputStream& response_input, TranscoderPtr& transcoder, + MethodInfoSharedPtr& method_info) { if (Grpc::Common::isGrpcRequestHeaders(headers)) { return ProtobufUtil::Status(Code::INVALID_ARGUMENT, "Request headers has application/grpc content-type"); @@ -324,8 +329,8 @@ ProtobufUtil::Status JsonTranscoderConfig::createTranscoder( request_info.variable_bindings.emplace_back(std::move(resolved_binding)); } - std::unique_ptr request_translator; - std::unique_ptr json_request_translator; + RequestMessageTranslatorPtr request_translator; + JsonRequestTranslatorPtr json_request_translator; if (method_info->request_type_is_http_body_) { request_translator = std::make_unique(*type_helper_->Resolver(), false, std::move(request_info)); @@ -338,7 +343,7 @@ ProtobufUtil::Status JsonTranscoderConfig::createTranscoder( const auto response_type_url = Grpc::Common::typeUrl(method_info->descriptor_->output_type()->full_name()); - std::unique_ptr response_translator{new ResponseToJsonTranslator( + ResponseToJsonTranslatorPtr response_translator{new ResponseToJsonTranslator( type_helper_->Resolver(), response_type_url, method_info->descriptor_->server_streaming(), &response_input, print_options_)}; diff --git a/source/extensions/grpc_credentials/aws_iam/config.cc b/source/extensions/grpc_credentials/aws_iam/config.cc index 5f60eab1464f2..6254cbb4ba970 100644 --- a/source/extensions/grpc_credentials/aws_iam/config.cc +++ b/source/extensions/grpc_credentials/aws_iam/config.cc @@ -74,7 +74,7 @@ std::shared_ptr AwsIamGrpcCredentialsFactory::getChann std::string AwsIamGrpcCredentialsFactory::getRegion( const envoy::config::grpc_credential::v3::AwsIamConfig& config) { - std::unique_ptr region_provider; + Common::Aws::RegionProviderPtr region_provider; if (!config.region().empty()) { region_provider = std::make_unique(config.region()); } else { diff --git a/source/extensions/stat_sinks/metrics_service/grpc_metrics_service_impl.h b/source/extensions/stat_sinks/metrics_service/grpc_metrics_service_impl.h index 0e35d3b063048..d65bae27f9bb8 100644 --- a/source/extensions/stat_sinks/metrics_service/grpc_metrics_service_impl.h +++ b/source/extensions/stat_sinks/metrics_service/grpc_metrics_service_impl.h @@ -1,5 +1,7 @@ #pragma once +#include + #include "envoy/grpc/async_client.h" #include "envoy/local_info/local_info.h" #include "envoy/network/connection.h" @@ -69,6 +71,8 @@ class GrpcMetricsStreamerImpl : public Singleton::Instance, public GrpcMetricsSt const envoy::config::core::v3::ApiVersion transport_api_version_; }; +using GrpcMetricsStreamerImplPtr = std::unique_ptr; + /** * Stat Sink implementation of Metrics Service. */ diff --git a/test/common/config/delta_subscription_impl_test.cc b/test/common/config/delta_subscription_impl_test.cc index 0368e630d7730..29c46f5d8096d 100644 --- a/test/common/config/delta_subscription_impl_test.cc +++ b/test/common/config/delta_subscription_impl_test.cc @@ -139,12 +139,12 @@ TEST(DeltaSubscriptionImplFixturelessTest, NoGrpcStream) { const Protobuf::MethodDescriptor* method_descriptor = Protobuf::DescriptorPool::generated_pool()->FindMethodByName( "envoy.api.v2.EndpointDiscoveryService.StreamEndpoints"); - std::shared_ptr xds_context = std::make_shared( + NewGrpcMuxImplSharedPtr xds_context = std::make_shared( std::unique_ptr(async_client), dispatcher, *method_descriptor, envoy::config::core::v3::ApiVersion::AUTO, random, stats_store, rate_limit_settings, local_info); - std::unique_ptr subscription = std::make_unique( + GrpcSubscriptionImplPtr subscription = std::make_unique( xds_context, callbacks, resource_decoder, stats, Config::TypeUrl::get().ClusterLoadAssignment, dispatcher, std::chrono::milliseconds(12345), false); diff --git a/test/common/config/delta_subscription_test_harness.h b/test/common/config/delta_subscription_test_harness.h index d030e7d46288c..04fca753ab056 100644 --- a/test/common/config/delta_subscription_test_harness.h +++ b/test/common/config/delta_subscription_test_harness.h @@ -197,8 +197,8 @@ class DeltaSubscriptionTestHarness : public SubscriptionTestHarness { NiceMock random_; NiceMock local_info_; Grpc::MockAsyncStream async_stream_; - std::shared_ptr xds_context_; - std::unique_ptr subscription_; + NewGrpcMuxImplSharedPtr xds_context_; + GrpcSubscriptionImplPtr subscription_; std::string last_response_nonce_; std::set last_cluster_names_; Envoy::Config::RateLimitSettings rate_limit_settings_; diff --git a/test/common/config/grpc_mux_impl_test.cc b/test/common/config/grpc_mux_impl_test.cc index bf18620b8a355..04938ce6adc13 100644 --- a/test/common/config/grpc_mux_impl_test.cc +++ b/test/common/config/grpc_mux_impl_test.cc @@ -98,7 +98,7 @@ class GrpcMuxImplTestBase : public testing::Test { NiceMock random_; Grpc::MockAsyncClient* async_client_; Grpc::MockAsyncStream async_stream_; - std::unique_ptr grpc_mux_; + GrpcMuxImplPtr grpc_mux_; NiceMock callbacks_; NiceMock resource_decoder_; NiceMock local_info_; diff --git a/test/common/config/grpc_subscription_test_harness.h b/test/common/config/grpc_subscription_test_harness.h index 0cc685486a29c..8649dcb01afea 100644 --- a/test/common/config/grpc_subscription_test_harness.h +++ b/test/common/config/grpc_subscription_test_harness.h @@ -186,8 +186,8 @@ class GrpcSubscriptionTestHarness : public SubscriptionTestHarness { TestUtility::TestOpaqueResourceDecoderImpl resource_decoder_{"cluster_name"}; NiceMock async_stream_; - std::shared_ptr mux_; - std::unique_ptr subscription_; + GrpcMuxImplSharedPtr mux_; + GrpcSubscriptionImplPtr subscription_; std::string last_response_nonce_; std::set last_cluster_names_; NiceMock local_info_; diff --git a/test/common/config/new_grpc_mux_impl_test.cc b/test/common/config/new_grpc_mux_impl_test.cc index 86d88dcfd4aa8..a35a38d577256 100644 --- a/test/common/config/new_grpc_mux_impl_test.cc +++ b/test/common/config/new_grpc_mux_impl_test.cc @@ -59,7 +59,7 @@ class NewGrpcMuxImplTestBase : public testing::Test { NiceMock random_; Grpc::MockAsyncClient* async_client_; NiceMock async_stream_; - std::unique_ptr grpc_mux_; + NewGrpcMuxImplPtr grpc_mux_; NiceMock callbacks_; TestUtility::TestOpaqueResourceDecoderImpl resource_decoder_{"cluster_name"}; diff --git a/test/common/grpc/google_async_client_impl_test.cc b/test/common/grpc/google_async_client_impl_test.cc index 1fa083234e1dc..1474899621f10 100644 --- a/test/common/grpc/google_async_client_impl_test.cc +++ b/test/common/grpc/google_async_client_impl_test.cc @@ -72,7 +72,7 @@ class EnvoyGoogleAsyncClientImplTest : public testing::Test { Api::ApiPtr api_; Event::DispatcherPtr dispatcher_; Stats::ScopeSharedPtr scope_; - std::unique_ptr tls_; + GoogleAsyncClientThreadLocalPtr tls_; MockStubFactory stub_factory_; const Protobuf::MethodDescriptor* method_descriptor_; StatNames stat_names_; diff --git a/test/common/grpc/grpc_client_integration_test_harness.h b/test/common/grpc/grpc_client_integration_test_harness.h index 7ab7facc976fd..0ae1ad97d11ff 100644 --- a/test/common/grpc/grpc_client_integration_test_harness.h +++ b/test/common/grpc/grpc_client_integration_test_harness.h @@ -1,5 +1,7 @@ #pragma once +#include + #include "envoy/config/core/v3/base.pb.h" #include "envoy/config/core/v3/grpc_service.pb.h" #include "envoy/extensions/transport_sockets/tls/v3/cert.pb.h" @@ -199,6 +201,8 @@ class HelloworldStream : public MockAsyncStreamCallbacks const TestMetadata empty_metadata_; }; +using HelloworldStreamPtr = std::unique_ptr; + // Request related test utilities. class HelloworldRequest : public MockAsyncRequestCallbacks { public: @@ -222,6 +226,8 @@ class HelloworldRequest : public MockAsyncRequestCallbacks; + class GrpcClientIntegrationTest : public GrpcClientIntegrationParamTest { public: GrpcClientIntegrationTest() @@ -346,7 +352,7 @@ class GrpcClientIntegrationTest : public GrpcClientIntegrationParamTest { virtual void expectExtraHeaders(FakeStream&) {} - std::unique_ptr createRequest(const TestMetadata& initial_metadata) { + HelloworldRequestPtr createRequest(const TestMetadata& initial_metadata) { auto request = std::make_unique(dispatcher_helper_); EXPECT_CALL(*request, onCreateInitialMetadata(_)) .WillOnce(Invoke([&initial_metadata](Http::HeaderMap& headers) { @@ -392,7 +398,7 @@ class GrpcClientIntegrationTest : public GrpcClientIntegrationParamTest { return request; } - std::unique_ptr createStream(const TestMetadata& initial_metadata) { + HelloworldStreamPtr createStream(const TestMetadata& initial_metadata) { auto stream = std::make_unique(dispatcher_helper_); EXPECT_CALL(*stream, onCreateInitialMetadata(_)) .WillOnce(Invoke([&initial_metadata](Http::HeaderMap& headers) { @@ -438,7 +444,7 @@ class GrpcClientIntegrationTest : public GrpcClientIntegrationParamTest { std::unique_ptr stream_headers_; std::vector> channel_args_; #ifdef ENVOY_GOOGLE_GRPC - std::unique_ptr google_tls_; + GoogleAsyncClientThreadLocalPtr google_tls_; #endif AsyncClient grpc_client_; Event::TimerPtr timeout_timer_; diff --git a/test/common/upstream/eds_speed_test.cc b/test/common/upstream/eds_speed_test.cc index 6f82390c95148..ef5e295467e71 100644 --- a/test/common/upstream/eds_speed_test.cc +++ b/test/common/upstream/eds_speed_test.cc @@ -162,8 +162,8 @@ class EdsSpeedTest { Api::ApiPtr api_; Grpc::MockAsyncClient* async_client_; NiceMock async_stream_; - std::shared_ptr grpc_mux_; - std::unique_ptr subscription_; + Config::GrpcMuxImplSharedPtr grpc_mux_; + Config::GrpcSubscriptionImplPtr subscription_; }; } // namespace Upstream diff --git a/test/extensions/access_loggers/grpc/grpc_access_log_impl_test.cc b/test/extensions/access_loggers/grpc/grpc_access_log_impl_test.cc index 4cb7054017b8a..6ea00508fc7fb 100644 --- a/test/extensions/access_loggers/grpc/grpc_access_log_impl_test.cc +++ b/test/extensions/access_loggers/grpc/grpc_access_log_impl_test.cc @@ -77,7 +77,7 @@ class GrpcAccessLoggerImplTest : public testing::Test { Event::MockTimer* timer_ = nullptr; Event::MockDispatcher dispatcher_; Grpc::MockAsyncClient* async_client_{new Grpc::MockAsyncClient}; - std::unique_ptr logger_; + GrpcAccessLoggerImplPtr logger_; }; // Test basic stream logging flow. @@ -372,7 +372,7 @@ class GrpcAccessLoggerCacheImplTest : public testing::Test { Grpc::MockAsyncClientManager async_client_manager_; Grpc::MockAsyncClient* async_client_ = nullptr; Grpc::MockAsyncClientFactory* factory_ = nullptr; - std::unique_ptr logger_cache_; + GrpcAccessLoggerCacheImplPtr logger_cache_; NiceMock scope_; }; diff --git a/test/extensions/access_loggers/grpc/http_grpc_access_log_impl_test.cc b/test/extensions/access_loggers/grpc/http_grpc_access_log_impl_test.cc index c39fb81655454..d6cf63b113953 100644 --- a/test/extensions/access_loggers/grpc/http_grpc_access_log_impl_test.cc +++ b/test/extensions/access_loggers/grpc/http_grpc_access_log_impl_test.cc @@ -122,7 +122,7 @@ response: {{}} envoy::extensions::access_loggers::grpc::v3::HttpGrpcAccessLogConfig config_; std::shared_ptr logger_{new MockGrpcAccessLogger()}; std::shared_ptr logger_cache_{new MockGrpcAccessLoggerCache()}; - std::unique_ptr access_log_; + HttpGrpcAccessLogPtr access_log_; }; class TestSerializedFilterState : public StreamInfo::FilterState::Object { diff --git a/test/extensions/filters/common/ext_authz/ext_authz_grpc_impl_test.cc b/test/extensions/filters/common/ext_authz/ext_authz_grpc_impl_test.cc index 711680fa6394a..ab0f7b37d6fd2 100644 --- a/test/extensions/filters/common/ext_authz/ext_authz_grpc_impl_test.cc +++ b/test/extensions/filters/common/ext_authz/ext_authz_grpc_impl_test.cc @@ -63,7 +63,7 @@ class ExtAuthzGrpcClientTest : public testing::TestWithParam { Grpc::MockAsyncClient* async_client_; absl::optional timeout_; Grpc::MockAsyncRequest async_request_; - std::unique_ptr client_; + GrpcClientImplPtr client_; MockRequestCallbacks request_callbacks_; Tracing::MockSpan span_; bool use_alpha_{}; diff --git a/test/extensions/filters/http/grpc_http1_reverse_bridge/reverse_bridge_test.cc b/test/extensions/filters/http/grpc_http1_reverse_bridge/reverse_bridge_test.cc index 15f5bf70687f8..54ee07792c480 100644 --- a/test/extensions/filters/http/grpc_http1_reverse_bridge/reverse_bridge_test.cc +++ b/test/extensions/filters/http/grpc_http1_reverse_bridge/reverse_bridge_test.cc @@ -38,7 +38,7 @@ class ReverseBridgeTest : public testing::Test { filter_->setEncoderFilterCallbacks(encoder_callbacks_); } - std::unique_ptr filter_; + FilterPtr filter_; std::shared_ptr route_ = std::make_shared(); Router::RouteSpecificFilterConfig filter_config_; Http::MockStreamDecoderFilterCallbacks decoder_callbacks_; diff --git a/test/extensions/filters/http/grpc_json_transcoder/json_transcoder_filter_test.cc b/test/extensions/filters/http/grpc_json_transcoder/json_transcoder_filter_test.cc index 19f5ef8f9b394..c0fbd516472d4 100644 --- a/test/extensions/filters/http/grpc_json_transcoder/json_transcoder_filter_test.cc +++ b/test/extensions/filters/http/grpc_json_transcoder/json_transcoder_filter_test.cc @@ -1,5 +1,6 @@ #include #include +#include #include "envoy/extensions/filters/http/grpc_json_transcoder/v3/transcoder.pb.h" @@ -31,6 +32,7 @@ using Envoy::Protobuf::util::MessageDifferencer; using Envoy::ProtobufUtil::error::Code; using google::api::HttpRule; using google::grpc::transcoding::Transcoder; +using TranscoderPtr = std::unique_ptr; namespace Envoy { namespace Extensions { @@ -222,7 +224,7 @@ TEST_F(GrpcJsonTranscoderConfigTest, CreateTranscoder) { Http::TestRequestHeaderMapImpl headers{{":method", "GET"}, {":path", "/shelves"}}; TranscoderInputStreamImpl request_in, response_in; - std::unique_ptr transcoder; + TranscoderPtr transcoder; MethodInfoSharedPtr method_info; const auto status = config.createTranscoder(headers, request_in, response_in, transcoder, method_info); @@ -243,7 +245,7 @@ TEST_F(GrpcJsonTranscoderConfigTest, CreateTranscoderAutoMap) { {":path", "/bookstore.Bookstore/DeleteShelf"}}; TranscoderInputStreamImpl request_in, response_in; - std::unique_ptr transcoder; + TranscoderPtr transcoder; MethodInfoSharedPtr method_info; const auto status = config.createTranscoder(headers, request_in, response_in, transcoder, method_info); @@ -262,7 +264,7 @@ TEST_F(GrpcJsonTranscoderConfigTest, InvalidQueryParameter) { Http::TestRequestHeaderMapImpl headers{{":method", "GET"}, {":path", "/shelves?foo=bar"}}; TranscoderInputStreamImpl request_in, response_in; - std::unique_ptr transcoder; + TranscoderPtr transcoder; MethodInfoSharedPtr method_info; const auto status = config.createTranscoder(headers, request_in, response_in, transcoder, method_info); @@ -282,7 +284,7 @@ TEST_F(GrpcJsonTranscoderConfigTest, UnknownQueryParameterIsIgnored) { Http::TestRequestHeaderMapImpl headers{{":method", "GET"}, {":path", "/shelves?foo=bar"}}; TranscoderInputStreamImpl request_in, response_in; - std::unique_ptr transcoder; + TranscoderPtr transcoder; MethodInfoSharedPtr method_info; const auto status = config.createTranscoder(headers, request_in, response_in, transcoder, method_info); @@ -301,7 +303,7 @@ TEST_F(GrpcJsonTranscoderConfigTest, IgnoredQueryParameter) { Http::TestRequestHeaderMapImpl headers{{":method", "GET"}, {":path", "/shelves?key=API_KEY"}}; TranscoderInputStreamImpl request_in, response_in; - std::unique_ptr transcoder; + TranscoderPtr transcoder; MethodInfoSharedPtr method_info; const auto status = config.createTranscoder(headers, request_in, response_in, transcoder, method_info); @@ -323,7 +325,7 @@ TEST_F(GrpcJsonTranscoderConfigTest, InvalidVariableBinding) { Http::TestRequestHeaderMapImpl headers{{":method", "GET"}, {":path", "/book/1"}}; TranscoderInputStreamImpl request_in, response_in; - std::unique_ptr transcoder; + TranscoderPtr transcoder; MethodInfoSharedPtr method_info; const auto status = config.createTranscoder(headers, request_in, response_in, transcoder, method_info); diff --git a/test/extensions/filters/http/grpc_stats/config_test.cc b/test/extensions/filters/http/grpc_stats/config_test.cc index 6c4d71292800a..68bf0bde27f0c 100644 --- a/test/extensions/filters/http/grpc_stats/config_test.cc +++ b/test/extensions/filters/http/grpc_stats/config_test.cc @@ -64,7 +64,7 @@ class GrpcStatsFilterConfigTest : public testing::Test { envoy::extensions::filters::http::grpc_stats::v3::FilterConfig config_; NiceMock context_; - std::shared_ptr filter_; + Http::StreamFilterSharedPtr filter_; NiceMock decoder_callbacks_; NiceMock stream_info_; NiceMock stats_store_; diff --git a/test/extensions/stats_sinks/metrics_service/grpc_metrics_service_impl_test.cc b/test/extensions/stats_sinks/metrics_service/grpc_metrics_service_impl_test.cc index 649b383496b65..ce940b650136d 100644 --- a/test/extensions/stats_sinks/metrics_service/grpc_metrics_service_impl_test.cc +++ b/test/extensions/stats_sinks/metrics_service/grpc_metrics_service_impl_test.cc @@ -49,7 +49,7 @@ class GrpcMetricsStreamerImplTest : public testing::Test { LocalInfo::MockLocalInfo local_info_; Grpc::MockAsyncClient* async_client_{new NiceMock}; Grpc::MockAsyncClientFactory* factory_{new Grpc::MockAsyncClientFactory}; - std::unique_ptr streamer_; + GrpcMetricsStreamerImplPtr streamer_; }; // Test basic metrics streaming flow. diff --git a/test/mocks/grpc/mocks.h b/test/mocks/grpc/mocks.h index 0a13f5a5fb082..476ba677f9453 100644 --- a/test/mocks/grpc/mocks.h +++ b/test/mocks/grpc/mocks.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include "envoy/config/core/v3/grpc_service.pb.h" @@ -39,10 +40,12 @@ class MockAsyncStream : public RawAsyncStream { MOCK_METHOD(bool, isAboveWriteBufferHighWatermark, (), (const)); }; +template using ResponseTypePtr = std::unique_ptr; + template class MockAsyncRequestCallbacks : public AsyncRequestCallbacks { public: - void onSuccess(std::unique_ptr&& response, Tracing::Span& span) { + void onSuccess(ResponseTypePtr&& response, Tracing::Span& span) { onSuccess_(*response, span); } @@ -59,7 +62,7 @@ class MockAsyncStreamCallbacks : public AsyncStreamCallbacks { onReceiveInitialMetadata_(*metadata); } - void onReceiveMessage(std::unique_ptr&& message) { onReceiveMessage_(*message); } + void onReceiveMessage(ResponseTypePtr&& message) { onReceiveMessage_(*message); } void onReceiveTrailingMetadata(Http::ResponseTrailerMapPtr&& metadata) { onReceiveTrailingMetadata_(*metadata);