Skip to content

[envoy] Add support for HttpBody request#10110

Merged
lizan merged 15 commits intoenvoyproxy:masterfrom
euroelessar:httpbody-request-3
Mar 19, 2020
Merged

[envoy] Add support for HttpBody request#10110
lizan merged 15 commits intoenvoyproxy:masterfrom
euroelessar:httpbody-request-3

Conversation

@euroelessar
Copy link
Contributor

Description: Add support for google.api.HttpBody message type in requests.
Support both unary and streaming requests.

Unary requests currently require filter to buffer the whole request before continue.
Streaming requests pass data to backend without any intermediate buffering at all.

Risk Level: Medium
Testing: Add unit and integration tests
Docs Changes: none
Release Notes: added
Fixes #10057

Ruslan Nigmatullin added 2 commits February 19, 2020 14:10
Signed-off-by: Ruslan Nigmatullin <elessar@dropbox.com>
Signed-off-by: Ruslan Nigmatullin <elessar@dropbox.com>
@euroelessar euroelessar requested a review from lizan as a code owner February 19, 2020 22:28
@lizan lizan self-assigned this Feb 19, 2020
Copy link
Member

@lizan lizan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this!

}

bool done = !readToBuffer(*transcoder_->RequestOutput(), request_prefix_);
RELEASE_ASSERT(done, "request transcoder should have been done");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just reject the request with error log? I don't think RELEASE_ASSERT should be done in data path of a filter.

CONSTRUCT_ON_FIRST_USE(Http::LowerCaseString, "trailer");
}

constexpr uint32_t HttpBodyFieldNumber = 2;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inferer those from protobuf lib?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you advice if there is a presence of ProtobufLengthDelimitedField-like constant in protobuf, please? It looks like it's hardcoded as 2 everywhere in the libprotobuf codebase, and all potential helper functions are in internal namespace.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I see that is only in internal::WireFormat, can you move this constexpr to the function you use it (there's only one), and add a comment where it is from?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, added additional comment to already present link to wire format documentation.

Ruslan Nigmatullin added 3 commits February 20, 2020 10:27
cr
Signed-off-by: Ruslan Nigmatullin <elessar@dropbox.com>
Signed-off-by: Ruslan Nigmatullin <elessar@dropbox.com>
Signed-off-by: Ruslan Nigmatullin <elessar@dropbox.com>
@lizan
Copy link
Member

lizan commented Feb 20, 2020

I feel some part of this PR should go to https://github.com/grpc-ecosystem/grpc-httpjson-transcoding/ directly, thoughts? @qiwzhang

@lizan lizan requested a review from qiwzhang February 20, 2020 21:39
Ruslan Nigmatullin added 3 commits February 20, 2020 13:44
Signed-off-by: Ruslan Nigmatullin <elessar@dropbox.com>
Signed-off-by: Ruslan Nigmatullin <elessar@dropbox.com>
…quest-3

Signed-off-by: Ruslan Nigmatullin <elessar@dropbox.com>
@euroelessar
Copy link
Contributor Author

@lizan @qiwzhang Friendly ping

@qiwzhang
Copy link
Contributor

qiwzhang commented Feb 27, 2020

@lizan I can see the benefit of moving some of code to grpc_httpjson_transcoder repo: it will enhance the library to support HttpBody type for both request and response and other callers will benefit from such enhancement.

But I also understand that HttpBody translation is different with JSON translation. It seems that it is not easy to fit HttpBody translation code into that library. I am fine to have specific HttpBody translation code here.

return status;
}

if (method_info->request_body_field_path.empty()) {
Copy link
Contributor

@qiwzhang qiwzhang Feb 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we handle case where the request type is HttpBody and http_rule.body() is *?

if so, should the ending block at line 248 move to line 237?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From reading google cloud's transcoding documentation it looks like "*" body is only applicable to json transcoding:

The special name * can be used in the body mapping to define that every field not bound by the path template should be mapped to the request body.

https://cloud.google.com/endpoints/docs/grpc-service-config/reference/rpc/google.api#google.api.HttpRule

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then, do we support the HttpBody as the gRPC request type?
with auto_mapping =true, we generate a http rule with * body for every grpc method.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you happen to know what is a behavior of Google Cloud in this case?
I'm probably inclined to treat "*" as "" for HttpBody requests.

return false;
}

void JsonTranscoderFilter::createHttpBodyEnvelope(Buffer::Instance& data, uint64_t content_length) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel this code is grpc specific, can be moved to grpc util library. it should be unit-tested thoroughly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few concerns:

  1. It's more protobuf than grpc specific (grpc piece is small and is not a concern)
  2. I'm not sure it's useful anywhere outside of this filter

I agree though that it's not trivial and I'm adding better test coverage

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few concerns:

  1. It's more protobuf than grpc specific (grpc piece is small and is not a concern)
  2. I'm not sure it's useful anywhere outside of this filter

I agree though that it's not trivial and I'm adding better test coverage

This is both grpc and protobuf specific because of the grpc framing part. Ideally it should be in the transcoding library, and a fuzz test should be added too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gRPC-specific code was moved to shared library so it's re-used with http1 reverse bridge.
HttpBody protobuf-specific code was covered by tests for the edge cases.

I'm not sure what would be a benefit of a fuzz testing in this case (user input is limited and well-defined).

// Embedded messages are treated the same way as strings (wire type 2).
constexpr uint32_t ProtobufLengthDelimitedField = 2;

std::string request_prefix = request_prefix_.toString();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not quite understand what request_prefix is for? could not add some examples in the comment

…quest-3

Signed-off-by: Ruslan Nigmatullin <elessar@dropbox.com>
@stale
Copy link

stale bot commented Mar 12, 2020

This pull request has been automatically marked as stale because it has not had activity in the last 7 days. It will be closed in 7 days if no further activity occurs. Please feel free to give a status update now, ping for review, or re-open when it's ready. Thank you for your contributions!

@stale stale bot added stale stalebot believes this issue/PR has not been touched recently and removed stale stalebot believes this issue/PR has not been touched recently labels Mar 12, 2020
@lizan
Copy link
Member

lizan commented Mar 12, 2020

not stable, I'm back from OOO.

Ruslan Nigmatullin added 3 commits March 17, 2020 11:56
Signed-off-by: Ruslan Nigmatullin <elessar@dropbox.com>
…quest-3

Signed-off-by: Ruslan Nigmatullin <elessar@dropbox.com>
Signed-off-by: Ruslan Nigmatullin <elessar@dropbox.com>
Signed-off-by: Ruslan Nigmatullin <elessar@dropbox.com>
Signed-off-by: Ruslan Nigmatullin <elessar@dropbox.com>
@lizan
Copy link
Member

lizan commented Mar 18, 2020

code LGTM, can you fix CI?

…quest-3

Signed-off-by: Ruslan Nigmatullin <elessar@dropbox.com>
@euroelessar
Copy link
Contributor Author

ci/circleci: go_control_plane_mirror looks like a flake (failure to download http archive from github.com)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[transcoder] Support HttpBody in requests

3 participants