diff --git a/source/common/grpc/BUILD b/source/common/grpc/BUILD index f0471c3568ee3..069f5d9af5690 100644 --- a/source/common/grpc/BUILD +++ b/source/common/grpc/BUILD @@ -28,6 +28,7 @@ envoy_cc_library( hdrs = ["async_client_manager_impl.h"], deps = [ ":async_client_lib", + ":common_lib", "//include/envoy/grpc:async_client_manager_interface", "//include/envoy/singleton:manager_interface", "//include/envoy/thread_local:thread_local_interface", @@ -82,6 +83,25 @@ envoy_cc_library( ], ) +envoy_cc_library( + name = "google_grpc_utils_lib", + srcs = ["google_grpc_utils.cc"], + hdrs = ["google_grpc_utils.h"], + external_deps = [ + "abseil_optional", + "grpc", + ], + deps = [ + "//source/common/buffer:buffer_lib", + "//source/common/common:assert_lib", + "//source/common/common:empty_string", + "//source/common/common:enum_to_int", + "//source/common/common:macros", + "//source/common/common:utility_lib", + "//source/common/grpc:status_lib", + ], +) + envoy_cc_library( name = "google_async_client_lib", srcs = ["google_async_client_impl.cc"], @@ -91,6 +111,7 @@ envoy_cc_library( "grpc", ], deps = [ + ":common_lib", ":google_grpc_creds_lib", "//include/envoy/api:api_interface", "//include/envoy/grpc:google_grpc_creds_interface", diff --git a/source/common/grpc/async_client_impl.cc b/source/common/grpc/async_client_impl.cc index c48a95a8771e9..443e5c943c248 100644 --- a/source/common/grpc/async_client_impl.cc +++ b/source/common/grpc/async_client_impl.cc @@ -177,7 +177,7 @@ void AsyncStreamImpl::onReset() { } void AsyncStreamImpl::sendMessage(const Protobuf::Message& request, bool end_stream) { - stream_->sendData(*Common::serializeBody(request), end_stream); + stream_->sendData(*Common::serializeToGrpcFrame(request), end_stream); } void AsyncStreamImpl::closeStream() { diff --git a/source/common/grpc/common.cc b/source/common/grpc/common.cc index d2d55bbe62f83..7248b0c7dceb4 100644 --- a/source/common/grpc/common.cc +++ b/source/common/grpc/common.cc @@ -2,6 +2,7 @@ #include +#include #include #include #include @@ -12,6 +13,7 @@ #include "common/common/enum_to_int.h" #include "common/common/fmt.h" #include "common/common/macros.h" +#include "common/common/stack_array.h" #include "common/common/utility.h" #include "common/http/headers.h" #include "common/http/message_impl.h" @@ -112,9 +114,11 @@ bool Common::resolveServiceAndMethod(const Http::HeaderEntry* path, std::string* return true; } -Buffer::InstancePtr Common::serializeBody(const Protobuf::Message& message) { +Buffer::InstancePtr Common::serializeToGrpcFrame(const Protobuf::Message& message) { // http://www.grpc.io/docs/guides/wire.html // Reserve enough space for the entire message and the 5 byte header. + // NB: we do not use prependGrpcFrameHeader because that would add another BufferFragment and this + // (using a single BufferFragment) is more efficient. Buffer::InstancePtr body(new Buffer::OwnedImpl()); const uint32_t size = message.ByteSize(); const uint32_t alloc_size = size + 5; @@ -134,6 +138,21 @@ Buffer::InstancePtr Common::serializeBody(const Protobuf::Message& message) { return body; } +Buffer::InstancePtr Common::serializeMessage(const Protobuf::Message& message) { + auto body = std::make_unique(); + const uint32_t size = message.ByteSize(); + Buffer::RawSlice iovec; + body->reserve(size, &iovec, 1); + ASSERT(iovec.len_ >= size); + iovec.len_ = size; + uint8_t* current = reinterpret_cast(iovec.mem_); + Protobuf::io::ArrayOutputStream stream(current, size, -1); + Protobuf::io::CodedOutputStream codec_stream(&stream); + message.SerializeWithCachedSizes(&codec_stream); + body->commit(&iovec, 1); + return body; +} + std::chrono::milliseconds Common::getGrpcTimeout(Http::HeaderMap& request_headers) { std::chrono::milliseconds timeout(0); Http::HeaderEntry* header_grpc_timeout_entry = request_headers.GrpcTimeout(); @@ -267,5 +286,13 @@ std::string Common::typeUrl(const std::string& qualified_name) { return typeUrlPrefix() + "/" + qualified_name; } +void Common::prependGrpcFrameHeader(Buffer::Instance& buffer) { + std::array header; + header[0] = 0; // flags + const uint32_t nsize = htonl(buffer.length()); + std::memcpy(&header[1], reinterpret_cast(&nsize), sizeof(uint32_t)); + buffer.prepend(absl::string_view(&header[0], 5)); +} + } // namespace Grpc } // namespace Envoy diff --git a/source/common/grpc/common.h b/source/common/grpc/common.h index 7a7399c1679c0..acec644e9e125 100644 --- a/source/common/grpc/common.h +++ b/source/common/grpc/common.h @@ -119,9 +119,14 @@ class Common { std::string* method); /** - * Serialize protobuf message. + * Serialize protobuf message with gRPC frame header. */ - static Buffer::InstancePtr serializeBody(const Protobuf::Message& message); + static Buffer::InstancePtr serializeToGrpcFrame(const Protobuf::Message& message); + + /** + * Serialize protobuf message. Without grpc header. + */ + static Buffer::InstancePtr serializeMessage(const Protobuf::Message& message); /** * Prepare headers for protobuf service. @@ -148,6 +153,12 @@ class Common { */ static std::string typeUrl(const std::string& qualified_name); + /** + * Prepend a gRPC frame header to a Buffer::Instance containing a single gRPC frame. + * @param buffer containing the frame data which will be modified. + */ + static void prependGrpcFrameHeader(Buffer::Instance& buffer); + private: static void checkForHeaderOnlyError(Http::Message& http_response); }; diff --git a/source/common/grpc/google_grpc_utils.cc b/source/common/grpc/google_grpc_utils.cc new file mode 100644 index 0000000000000..82325780a337c --- /dev/null +++ b/source/common/grpc/google_grpc_utils.cc @@ -0,0 +1,108 @@ +#include "common/grpc/google_grpc_utils.h" + +#include +#include +#include +#include + +#include "common/buffer/buffer_impl.h" +#include "common/common/assert.h" +#include "common/common/empty_string.h" +#include "common/common/enum_to_int.h" +#include "common/common/fmt.h" +#include "common/common/macros.h" +#include "common/common/stack_array.h" +#include "common/common/utility.h" + +#include "absl/strings/match.h" + +namespace Envoy { +namespace Grpc { + +struct BufferInstanceContainer { + BufferInstanceContainer(int ref_count, Buffer::InstancePtr&& buffer) + : ref_count_(ref_count), buffer_(std::move(buffer)) {} + std::atomic ref_count_; // In case gPRC dereferences in a different threads. + Buffer::InstancePtr buffer_; + + static void derefBufferInstanceContainer(void* container_ptr) { + auto container = static_cast(container_ptr); + container->ref_count_--; + // This is safe because the ref_count_ is never incremented. + if (container->ref_count_ <= 0) { + delete container; + } + } +}; + +grpc::ByteBuffer GoogleGrpcUtils::makeByteBuffer(Buffer::InstancePtr&& buffer_instance) { + if (!buffer_instance) { + return {}; + } + Buffer::RawSlice on_raw_slice; + // NB: we need to pass in >= 1 in order to get the real "n" (see Buffer::Instance for details). + const int n_slices = buffer_instance->getRawSlices(&on_raw_slice, 1); + if (n_slices <= 0) { + return {}; + } + auto* container = new BufferInstanceContainer{n_slices, std::move(buffer_instance)}; + if (n_slices == 1) { + grpc::Slice one_slice(on_raw_slice.mem_, on_raw_slice.len_, + &BufferInstanceContainer::derefBufferInstanceContainer, container); + return {&one_slice, 1}; + } + STACK_ARRAY(many_raw_slices, Buffer::RawSlice, n_slices); + container->buffer_->getRawSlices(many_raw_slices.begin(), n_slices); + std::vector slices; + slices.reserve(n_slices); + for (int i = 0; i < n_slices; i++) { + slices.emplace_back(many_raw_slices[i].mem_, many_raw_slices[i].len_, + &BufferInstanceContainer::derefBufferInstanceContainer, container); + } + return {&slices[0], slices.size()}; +} + +struct ByteBufferContainer { + ByteBufferContainer(int ref_count) : ref_count_(ref_count) {} + ~ByteBufferContainer() { ::free(fragments_); } + uint32_t ref_count_; + Buffer::BufferFragmentImpl* fragments_ = nullptr; + std::vector slices_; +}; + +Buffer::InstancePtr GoogleGrpcUtils::makeBufferInstance(const grpc::ByteBuffer& byte_buffer) { + auto buffer = std::make_unique(); + if (byte_buffer.Length() == 0) { + return buffer; + } + // NB: ByteBuffer::Dump moves the data out of the ByteBuffer so we need to ensure that the + // lifetime of the Slice(s) exceeds our Buffer::Instance. + std::vector slices; + byte_buffer.Dump(&slices); + auto* container = new ByteBufferContainer(static_cast(slices.size())); + std::function releaser = + [container](const void*, size_t, const Buffer::BufferFragmentImpl*) { + container->ref_count_--; + if (container->ref_count_ <= 0) { + delete container; + } + }; + // NB: addBufferFragment takes a pointer alias to the BufferFragmentImpl which is passed in so we + // need to ensure that the lifetime of those objects exceeds that of the Buffer::Instance. + RELEASE_ASSERT(!::posix_memalign(reinterpret_cast(&container->fragments_), + alignof(Buffer::BufferFragmentImpl), + sizeof(Buffer::BufferFragmentImpl) * slices.size()), + "posix_memalign failure"); + for (size_t i = 0; i < slices.size(); i++) { + new (&container->fragments_[i]) + Buffer::BufferFragmentImpl(slices[i].begin(), slices[i].size(), releaser); + } + for (size_t i = 0; i < slices.size(); i++) { + buffer->addBufferFragment(container->fragments_[i]); + } + container->slices_ = std::move(slices); + return buffer; +} + +} // namespace Grpc +} // namespace Envoy diff --git a/source/common/grpc/google_grpc_utils.h b/source/common/grpc/google_grpc_utils.h new file mode 100644 index 0000000000000..86975ea4f6bd3 --- /dev/null +++ b/source/common/grpc/google_grpc_utils.h @@ -0,0 +1,33 @@ +#pragma once + +#include +#include + +#include "envoy/buffer/buffer.h" + +#include "grpcpp/grpcpp.h" + +namespace Envoy { +namespace Grpc { + +class GoogleGrpcUtils { +public: + /** + * Build grpc::ByteBuffer which aliases the data in a Buffer::InstancePtr. + * @param buffer source data container. + * @return byteBuffer target container aliased to the data in Buffer::Instance and owning the + * Buffer::Instance. + */ + static grpc::ByteBuffer makeByteBuffer(Buffer::InstancePtr&& buffer); + + /** + * Build Buffer::Instance which aliases the data in a grpc::ByteBuffer. + * @param buffer source data container. + * @return a Buffer::InstancePtr aliased to the data in the provided grpc::ByteBuffer and + * owning the corresponding grpc::Slice(s). + */ + static Buffer::InstancePtr makeBufferInstance(const grpc::ByteBuffer& buffer); +}; + +} // namespace Grpc +} // namespace Envoy diff --git a/source/common/upstream/health_checker_impl.cc b/source/common/upstream/health_checker_impl.cc index 00a264ef31374..5afb9c14159ec 100644 --- a/source/common/upstream/health_checker_impl.cc +++ b/source/common/upstream/health_checker_impl.cc @@ -586,7 +586,7 @@ void GrpcHealthCheckerImpl::GrpcActiveHealthCheckSession::onInterval() { request.set_service(parent_.service_name_.value()); } - request_encoder_->encodeData(*Grpc::Common::serializeBody(request), true); + request_encoder_->encodeData(*Grpc::Common::serializeToGrpcFrame(request), true); } void GrpcHealthCheckerImpl::GrpcActiveHealthCheckSession::onResetStream(Http::StreamResetReason, diff --git a/source/extensions/tracers/lightstep/lightstep_tracer_impl.cc b/source/extensions/tracers/lightstep/lightstep_tracer_impl.cc index d1aa06dd93ee8..b604f83b4dda0 100644 --- a/source/extensions/tracers/lightstep/lightstep_tracer_impl.cc +++ b/source/extensions/tracers/lightstep/lightstep_tracer_impl.cc @@ -64,7 +64,7 @@ void LightStepDriver::LightStepTransporter::Send(const Protobuf::Message& reques Http::MessagePtr message = Grpc::Common::prepareHeaders( driver_.cluster()->name(), lightstep::CollectorServiceFullName(), lightstep::CollectorMethodName(), absl::optional(timeout)); - message->body() = Grpc::Common::serializeBody(request); + message->body() = Grpc::Common::serializeToGrpcFrame(request); active_request_ = driver_.clusterManager() diff --git a/test/common/grpc/BUILD b/test/common/grpc/BUILD index 549801ad5e7dd..0d880ea03ff56 100644 --- a/test/common/grpc/BUILD +++ b/test/common/grpc/BUILD @@ -58,6 +58,18 @@ envoy_cc_test( ], ) +envoy_cc_test( + name = "google_grpc_utils_test", + srcs = envoy_select_google_grpc(["google_grpc_utils_test.cc"]), + deps = [ + "//source/common/grpc:common_lib", + "//source/common/http:headers_lib", + "//test/mocks/upstream:upstream_mocks", + "//test/proto:helloworld_proto_cc", + "//test/test_common:utility_lib", + ] + envoy_select_google_grpc(["//source/common/grpc:google_grpc_utils_lib"]), +) + envoy_cc_test( name = "google_async_client_impl_test", srcs = envoy_select_google_grpc(["google_async_client_impl_test.cc"]), diff --git a/test/common/grpc/common_test.cc b/test/common/grpc/common_test.cc index 8600ec8b9372f..9e1b280d9a2f6 100644 --- a/test/common/grpc/common_test.cc +++ b/test/common/grpc/common_test.cc @@ -1,3 +1,5 @@ +#include + #include "common/grpc/common.h" #include "common/http/headers.h" #include "common/http/message_impl.h" @@ -349,5 +351,18 @@ TEST(GrpcCommonTest, ValidateResponse) { } } +// Ensure that the correct gPRC header is constructed for a Buffer::Instance. +TEST(GrpcCommonTest, PrependGrpcFrameHeader) { + auto buffer = std::make_unique(); + buffer->add("test", 4); + std::array expected_header; + expected_header[0] = 0; // flags + const uint32_t nsize = htonl(4); + std::memcpy(&expected_header[1], reinterpret_cast(&nsize), sizeof(uint32_t)); + std::string header_string(&expected_header[0], 5); + Common::prependGrpcFrameHeader(*buffer); + EXPECT_EQ(buffer->toString(), header_string + "test"); +} + } // namespace Grpc } // namespace Envoy diff --git a/test/common/grpc/google_grpc_utils_test.cc b/test/common/grpc/google_grpc_utils_test.cc new file mode 100644 index 0000000000000..6f7a96a497c50 --- /dev/null +++ b/test/common/grpc/google_grpc_utils_test.cc @@ -0,0 +1,88 @@ +#include + +#include "common/grpc/google_grpc_utils.h" + +#include "test/mocks/upstream/mocks.h" +#include "test/proto/helloworld.pb.h" +#include "test/test_common/utility.h" + +#include "gtest/gtest.h" + +namespace Envoy { +namespace Grpc { +namespace { + +TEST(GoogleGrpcUtilsTest, MakeBufferInstanceEmpty) { + grpc::ByteBuffer byte_buffer; + GoogleGrpcUtils::makeBufferInstance(byte_buffer); +} + +TEST(GoogleGrpcUtilsTest, MakeByteBufferEmpty) { + auto buffer = std::make_unique(); + GoogleGrpcUtils::makeByteBuffer(std::move(buffer)); + buffer = nullptr; + GoogleGrpcUtils::makeByteBuffer(std::move(buffer)); +} + +TEST(GoogleGrpcUtilsTest, MakeBufferInstance1) { + grpc::Slice slice("test"); + grpc::ByteBuffer byte_buffer(&slice, 1); + auto buffer_instance = GoogleGrpcUtils::makeBufferInstance(byte_buffer); + EXPECT_EQ(buffer_instance->toString(), "test"); +} + +// Test building a Buffer::Instance from 3 grpc::Slice(s). +TEST(GoogleGrpcUtilsTest, MakeBufferInstance3) { + std::array slices = {grpc::string("test"), grpc::string(" "), + grpc::string("this")}; + grpc::ByteBuffer byte_buffer(&slices[0], 3); + auto buffer_instance = GoogleGrpcUtils::makeBufferInstance(byte_buffer); + EXPECT_EQ(buffer_instance->toString(), "test this"); +} + +TEST(GoogleGrpcUtilsTest, MakeByteBuffer1) { + auto buffer = std::make_unique(); + buffer->add("test", 4); + auto byte_buffer = GoogleGrpcUtils::makeByteBuffer(std::move(buffer)); + std::vector slices; + byte_buffer.Dump(&slices); + std::string str; + for (auto& s : slices) { + str.append(std::string(reinterpret_cast(s.begin()), s.size())); + } + EXPECT_EQ(str, "test"); +} + +// Test building a grpc::ByteBuffer from a Bufffer::Instance with 3 slices. +TEST(GoogleGrpcUtilsTest, MakeByteBuffer3) { + auto buffer = std::make_unique(); + Buffer::BufferFragmentImpl f1("test", 4, nullptr); + buffer->addBufferFragment(f1); + Buffer::BufferFragmentImpl f2(" ", 1, nullptr); + buffer->addBufferFragment(f2); + Buffer::BufferFragmentImpl f3("this", 4, nullptr); + buffer->addBufferFragment(f3); + auto byte_buffer = GoogleGrpcUtils::makeByteBuffer(std::move(buffer)); + std::vector slices; + byte_buffer.Dump(&slices); + std::string str; + for (auto& s : slices) { + str.append(std::string(reinterpret_cast(s.begin()), s.size())); + } + EXPECT_EQ(str, "test this"); +} + +// Test building a Buffer::Instance from a grpc::ByteBuffer from a Bufffer::Instance with 3 slices. +TEST(GoogleGrpcUtilsTest, ByteBufferInstanceRoundTrip) { + std::array slices = {grpc::string("test"), grpc::string(" "), + grpc::string("this")}; + grpc::ByteBuffer byte_buffer(&slices[0], 3); + auto buffer_instance1 = GoogleGrpcUtils::makeBufferInstance(byte_buffer); + auto byte_buffer2 = GoogleGrpcUtils::makeByteBuffer(std::move(buffer_instance1)); + auto buffer_instance2 = GoogleGrpcUtils::makeBufferInstance(byte_buffer2); + EXPECT_EQ(buffer_instance2->toString(), "test this"); +} + +} // namespace +} // namespace Grpc +} // namespace Envoy diff --git a/test/common/grpc/grpc_client_integration_test.cc b/test/common/grpc/grpc_client_integration_test.cc index 99c9fe55f1a85..7e55827dae9a5 100644 --- a/test/common/grpc/grpc_client_integration_test.cc +++ b/test/common/grpc/grpc_client_integration_test.cc @@ -190,7 +190,7 @@ TEST_P(GrpcClientIntegrationTest, ReplyNoTrailers) { dispatcher_helper_.setStreamEventPending(); stream->expectTrailingMetadata(empty_metadata_); stream->expectGrpcStatus(Status::GrpcStatus::InvalidCode); - auto serialized_response = Grpc::Common::serializeBody(reply); + auto serialized_response = Grpc::Common::serializeToGrpcFrame(reply); stream->fake_stream_->encodeData(*serialized_response, true); stream->fake_stream_->encodeResetStream(); dispatcher_helper_.runDispatcher(); diff --git a/test/common/upstream/health_checker_impl_test.cc b/test/common/upstream/health_checker_impl_test.cc index 5aabd795d0beb..9b1699e3c10bd 100644 --- a/test/common/upstream/health_checker_impl_test.cc +++ b/test/common/upstream/health_checker_impl_test.cc @@ -2658,7 +2658,7 @@ class GrpcHealthCheckerImplTestBase { serializeResponse(grpc::health::v1::HealthCheckResponse::ServingStatus status) { grpc::health::v1::HealthCheckResponse response; response.set_status(status); - const auto data = Grpc::Common::serializeBody(response); + const auto data = Grpc::Common::serializeToGrpcFrame(response); auto ret = std::vector(data->length(), 0); data->copyOut(0, data->length(), &ret[0]); return ret; @@ -2977,7 +2977,7 @@ TEST_F(GrpcHealthCheckerImplTest, SuccessResponseSplitBetweenChunks) { grpc::health::v1::HealthCheckResponse response; response.set_status(grpc::health::v1::HealthCheckResponse::SERVING); - auto data = Grpc::Common::serializeBody(response); + auto data = Grpc::Common::serializeToGrpcFrame(response); const char* raw_data = static_cast(data->linearize(data->length())); const uint64_t chunk_size = data->length() / 5; diff --git a/test/extensions/filters/http/grpc_json_transcoder/grpc_json_transcoder_integration_test.cc b/test/extensions/filters/http/grpc_json_transcoder/grpc_json_transcoder_integration_test.cc index 9117f17be78ac..e83933a338066 100644 --- a/test/extensions/filters/http/grpc_json_transcoder/grpc_json_transcoder_integration_test.cc +++ b/test/extensions/filters/http/grpc_json_transcoder/grpc_json_transcoder_integration_test.cc @@ -109,7 +109,7 @@ class GrpcJsonTranscoderIntegrationTest for (const auto& response_message_str : grpc_response_messages) { ResponseType response_message; EXPECT_TRUE(TextFormat::ParseFromString(response_message_str, &response_message)); - auto buffer = Grpc::Common::serializeBody(response_message); + auto buffer = Grpc::Common::serializeToGrpcFrame(response_message); upstream_request_->encodeData(*buffer, false); } Http::TestHeaderMapImpl response_trailers; 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 e548a9ea3c637..2ef4849614f57 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 @@ -411,7 +411,7 @@ TEST_F(GrpcJsonTranscoderFilterTest, TranscodingUnaryPost) { response.set_id(20); response.set_theme("Children"); - auto response_data = Grpc::Common::serializeBody(response); + auto response_data = Grpc::Common::serializeToGrpcFrame(response); EXPECT_EQ(Http::FilterDataStatus::StopIterationAndBuffer, filter_.encodeData(*response_data, false)); @@ -475,7 +475,7 @@ TEST_F(GrpcJsonTranscoderFilterTest, TranscodingUnaryPostWithPackageServiceMetho response.set_id(20); response.set_theme("Children"); - auto response_data = Grpc::Common::serializeBody(response); + auto response_data = Grpc::Common::serializeToGrpcFrame(response); EXPECT_EQ(Http::FilterDataStatus::StopIterationAndBuffer, filter_.encodeData(*response_data, false)); @@ -503,7 +503,7 @@ TEST_F(GrpcJsonTranscoderFilterTest, ForwardUnaryPostGrpc) { bookstore::CreateShelfRequest request; request.mutable_shelf()->set_theme("Children"); - Buffer::InstancePtr request_data = Grpc::Common::serializeBody(request); + Buffer::InstancePtr request_data = Grpc::Common::serializeToGrpcFrame(request); EXPECT_EQ(Http::FilterDataStatus::Continue, filter_.decodeData(*request_data, true)); Grpc::Decoder decoder; @@ -538,7 +538,7 @@ TEST_F(GrpcJsonTranscoderFilterTest, ForwardUnaryPostGrpc) { response.set_id(20); response.set_theme("Children"); - Buffer::InstancePtr response_data = Grpc::Common::serializeBody(response); + Buffer::InstancePtr response_data = Grpc::Common::serializeToGrpcFrame(response); EXPECT_EQ(Http::FilterDataStatus::Continue, filter_.encodeData(*response_data, true)); frames.clear(); @@ -662,7 +662,7 @@ TEST_F(GrpcJsonTranscoderFilterTest, TranscodingUnaryWithHttpBodyAsOutput) { response.set_content_type("text/html"); response.set_data("

Hello, world!

"); - auto response_data = Grpc::Common::serializeBody(response); + auto response_data = Grpc::Common::serializeToGrpcFrame(response); EXPECT_EQ(Http::FilterDataStatus::StopIterationAndBuffer, filter_.encodeData(*response_data, false)); @@ -696,7 +696,7 @@ TEST_F(GrpcJsonTranscoderFilterTest, TranscodingUnaryWithHttpBodyAsOutputAndSpli response.set_content_type("text/html"); response.set_data("

Hello, world!

"); - auto response_data = Grpc::Common::serializeBody(response); + auto response_data = Grpc::Common::serializeToGrpcFrame(response); // Firstly, the response data buffer is split into two parts. Buffer::OwnedImpl response_data_first_part; @@ -759,7 +759,7 @@ TEST_P(GrpcJsonTranscoderFilterPrintTest, PrintOptions) { author.set_gender(bookstore::Author_Gender_MALE); author.set_last_name("Shakespeare"); - const auto response_data = Grpc::Common::serializeBody(author); + const auto response_data = Grpc::Common::serializeToGrpcFrame(author); EXPECT_EQ(Http::FilterDataStatus::StopIterationAndBuffer, filter_->encodeData(*response_data, false)); diff --git a/test/extensions/tracers/lightstep/lightstep_tracer_impl_test.cc b/test/extensions/tracers/lightstep/lightstep_tracer_impl_test.cc index baf365a636241..d2f2b48998e8f 100644 --- a/test/extensions/tracers/lightstep/lightstep_tracer_impl_test.cc +++ b/test/extensions/tracers/lightstep/lightstep_tracer_impl_test.cc @@ -203,7 +203,7 @@ TEST_F(LightStepDriverTest, FlushSeveralSpans) { std::unique_ptr collector_response = lightstep::Transporter::MakeCollectorResponse(); EXPECT_NE(collector_response, nullptr); - msg->body() = Grpc::Common::serializeBody(*collector_response); + msg->body() = Grpc::Common::serializeToGrpcFrame(*collector_response); callback->onSuccess(std::move(msg)); diff --git a/test/integration/fake_upstream.h b/test/integration/fake_upstream.h index 4ec4e181a3af9..dc979dc4f568e 100644 --- a/test/integration/fake_upstream.h +++ b/test/integration/fake_upstream.h @@ -90,7 +90,7 @@ class FakeStream : public Http::StreamDecoder, void startGrpcStream(); void finishGrpcStream(Grpc::Status::GrpcStatus status); template void sendGrpcMessage(const T& message) { - auto serialized_response = Grpc::Common::serializeBody(message); + auto serialized_response = Grpc::Common::serializeToGrpcFrame(message); encodeData(*serialized_response, false); ENVOY_LOG(debug, "Sent gRPC message: {}", message.DebugString()); }