Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grpc transcoding: set content-type to json for tailer-only #8158

Closed
wants to merge 3 commits into from

Conversation

qiwzhang
Copy link
Contributor

@qiwzhang qiwzhang commented Sep 5, 2019

Signed-off-by: Wayne Zhang [email protected]

Description:

Set the content-type as application/json for tailer only response.

Risk Level: Low
Testing: integration test.
Fixes #5011

@qiwzhang
Copy link
Contributor Author

qiwzhang commented Sep 5, 2019

@lizan will this change address #5011?

@htuch htuch requested a review from lizan September 6, 2019 00:28
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.

Great, though I'd like to coordinate this with #8009, which addresses some of conversion addressed here too.

const absl::optional<Grpc::Status::GrpcStatus> grpc_status =
Grpc::Common::getGrpcStatus(trailers);
if (!grpc_status || grpc_status.value() == Grpc::Status::GrpcStatus::InvalidCode) {
response_headers_->Status()->value(enumToInt(Http::Code::ServiceUnavailable));
Copy link
Member

Choose a reason for hiding this comment

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

if upstream doesn't return grpc-status, it usually means the HTTP status is not 200 (5xx etc), in that case shall we override the HTTP status?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated, not to set Status() if upstream grpc-status is not available.

Copy link
Contributor

@ascheglov ascheglov Sep 8, 2019

Choose a reason for hiding this comment

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

There should be if (!grpc_status) { return; } before this if (grpc_status.value() == ...).

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. Thanks for catching this crash.

@@ -365,14 +381,16 @@ Http::FilterHeadersStatus JsonTranscoderFilter::encodeHeaders(Http::HeaderMap& h

response_headers_ = &headers;

headers.insertContentType().value().setReference(Http::Headers::get().ContentTypeValues.Json);

if (end_stream) {
// In gRPC wire protocol, headers frame with end_stream is a trailers-only response.
// The return value from encodeTrailers is ignored since it is always continue.
Copy link
Member

Choose a reason for hiding this comment

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

delete this line.

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

@lizan
Copy link
Member

lizan commented Sep 6, 2019

cc @ascheglov

@stale
Copy link

stale bot commented Sep 16, 2019

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 the stale stalebot believes this issue/PR has not been touched recently label Sep 16, 2019
@lizan
Copy link
Member

lizan commented Sep 19, 2019

@qiwzhang #8009 is now in, can you rebase accordingly?

@stale stale bot removed the stale stalebot believes this issue/PR has not been touched recently label Sep 19, 2019
@lizan lizan added the waiting label Sep 20, 2019
@nareddyt
Copy link
Contributor

I have been asked to take over this change. I will make another PR rebased off #8009

nareddyt added a commit to nareddyt/envoy that referenced this pull request Sep 20, 2019
…e that the returned content type is `application/json`. This is required because the response body is an empty JSON body by default.

Risk Level: Low
Testing: Modified integration test to catch this bug.
Docs Changes: None
Release Notes: None

Fixes: envoyproxy#5011
Ref: envoyproxy#8158
Ref: envoyproxy#8009
Signed-off-by: Teju Nareddy <[email protected]>
@qiwzhang qiwzhang closed this Sep 20, 2019
@qiwzhang qiwzhang deleted the grpc_trailer_fix branch September 20, 2019 23:09
lizan pushed a commit that referenced this pull request Sep 24, 2019
* When trailer indicates a gRPC error and there was no HTTP body, ensure that the returned content type is `application/json`. This is required because the response body is an empty JSON body by default.

Risk Level: Low
Testing: Modified integration test to catch this bug.
Docs Changes: None
Release Notes: None

Fixes: #5011
Ref: #8158
Ref: #8009

Signed-off-by: Teju Nareddy <[email protected]>
danzh2010 pushed a commit to danzh2010/envoy that referenced this pull request Oct 4, 2019
…oxy#8312)

* When trailer indicates a gRPC error and there was no HTTP body, ensure that the returned content type is `application/json`. This is required because the response body is an empty JSON body by default.

Risk Level: Low
Testing: Modified integration test to catch this bug.
Docs Changes: None
Release Notes: None

Fixes: envoyproxy#5011
Ref: envoyproxy#8158
Ref: envoyproxy#8009

Signed-off-by: Teju Nareddy <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

grpc-json transcoder: stream return type always returns 200 even in case of errors
4 participants