-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
http/filter: Add a callback for sendLocalReply() and encode gRPC message for local responses when the request is gRPC #3299
Merged
mattklein123
merged 20 commits into
envoyproxy:master
from
jrajahalme:grpc-local-responses
May 15, 2018
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
5d98848
router: Use gRPC message for local responses when the request is gRPC
jrajahalme 7896b64
grpc: Move utility functions to http/utility.
jrajahalme 29ba376
http: Make Utility::sendLocalResponse() aware of gRPC.
jrajahalme 2c264bf
http: add StreamDecoderFilter callback sendLocalReply().
jrajahalme c21e507
http: Add a missing include.
jrajahalme 4c6b212
http: Mark local complete also when sending local gRPC response.
jrajahalme 0903339
http: Add comment for clarification (needed)
jrajahalme ae9c406
http: Move gRPC utilities back to grpc/common
jrajahalme 52f9baf
test/grpc: Revert unnecessary namespace prefix changes.
jrajahalme 42327a3
Merge branch 'master' into grpc-local-responses
jrajahalme 04f23a6
http: Use sendLocalReply() for all local replies in ConnectionManager…
jrajahalme a47b2a1
filters: Use sendLocalReply() decoder callback for local replies.
jrajahalme 6bd512a
conn_manager_impl: Fix format.
jrajahalme 26aa335
filters: Remove unnecessary tracking of stream status.
jrajahalme dea2787
http: Clarify comments on sendLocalReply()
jrajahalme 06b22a7
conn_manager_impl: Remove nullptr parameter and add TODOs.
jrajahalme e125f63
filter: Add comment about gRPC encoding of local responses.
jrajahalme 2860297
common/grpc: Add status_lib
jrajahalme 74724fd
test: http mock cleanup.
jrajahalme 2b57fc4
http: Final review comment fixes.
jrajahalme File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
#include "common/grpc/status.h" | ||
|
||
namespace Envoy { | ||
namespace Grpc { | ||
|
||
Status::GrpcStatus Utility::httpToGrpcStatus(uint64_t http_response_status) { | ||
// From | ||
// https://github.com/grpc/grpc/blob/master/doc/http-grpc-status-mapping.md. | ||
switch (http_response_status) { | ||
case 400: | ||
return Status::GrpcStatus::Internal; | ||
case 401: | ||
return Status::GrpcStatus::Unauthenticated; | ||
case 403: | ||
return Status::GrpcStatus::PermissionDenied; | ||
case 404: | ||
return Status::GrpcStatus::Unimplemented; | ||
case 429: | ||
case 502: | ||
case 503: | ||
case 504: | ||
return Status::GrpcStatus::Unavailable; | ||
default: | ||
return Status::GrpcStatus::Unknown; | ||
} | ||
} | ||
|
||
uint64_t Utility::grpcToHttpStatus(Status::GrpcStatus grpc_status) { | ||
// From https://cloud.google.com/apis/design/errors#handling_errors. | ||
switch (grpc_status) { | ||
case Status::GrpcStatus::Ok: | ||
return 200; | ||
case Status::GrpcStatus::Canceled: | ||
// Client closed request. | ||
return 499; | ||
case Status::GrpcStatus::Unknown: | ||
// Internal server error. | ||
return 500; | ||
case Status::GrpcStatus::InvalidArgument: | ||
// Bad request. | ||
return 400; | ||
case Status::GrpcStatus::DeadlineExceeded: | ||
// Gateway Time-out. | ||
return 504; | ||
case Status::GrpcStatus::NotFound: | ||
// Not found. | ||
return 404; | ||
case Status::GrpcStatus::AlreadyExists: | ||
// Conflict. | ||
return 409; | ||
case Status::GrpcStatus::PermissionDenied: | ||
// Forbidden. | ||
return 403; | ||
case Status::GrpcStatus::ResourceExhausted: | ||
// Too many requests. | ||
return 429; | ||
case Status::GrpcStatus::FailedPrecondition: | ||
// Bad request. | ||
return 400; | ||
case Status::GrpcStatus::Aborted: | ||
// Conflict. | ||
return 409; | ||
case Status::GrpcStatus::OutOfRange: | ||
// Bad request. | ||
return 400; | ||
case Status::GrpcStatus::Unimplemented: | ||
// Not implemented. | ||
return 501; | ||
case Status::GrpcStatus::Internal: | ||
// Internal server error. | ||
return 500; | ||
case Status::GrpcStatus::Unavailable: | ||
// Service unavailable. | ||
return 503; | ||
case Status::GrpcStatus::DataLoss: | ||
// Internal server error. | ||
return 500; | ||
case Status::GrpcStatus::Unauthenticated: | ||
// Unauthorized. | ||
return 401; | ||
case Status::GrpcStatus::InvalidCode: | ||
default: | ||
// Internal server error. | ||
return 500; | ||
} | ||
} | ||
|
||
} // namespace Grpc | ||
} // namespace Envoy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#pragma once | ||
|
||
#include <cstdint> | ||
|
||
#include "envoy/grpc/status.h" | ||
|
||
namespace Envoy { | ||
namespace Grpc { | ||
|
||
/** | ||
* Grpc::Status utilities. | ||
*/ | ||
class Utility { | ||
public: | ||
/** | ||
* Returns the gRPC status code from a given HTTP response status code. Ordinarily, it is expected | ||
* that a 200 response is provided, but gRPC defines a mapping for intermediaries that are not | ||
* gRPC aware, see https://github.com/grpc/grpc/blob/master/doc/http-grpc-status-mapping.md. | ||
* @param http_response_status HTTP status code. | ||
* @return Status::GrpcStatus corresponding gRPC status code. | ||
*/ | ||
static Status::GrpcStatus httpToGrpcStatus(uint64_t http_response_status); | ||
|
||
/** | ||
* @param grpc_status gRPC status from grpc-status header. | ||
* @return uint64_t the canonical HTTP status code corresponding to a gRPC status code. | ||
*/ | ||
static uint64_t grpcToHttpStatus(Status::GrpcStatus grpc_status); | ||
}; | ||
|
||
} // namespace Grpc | ||
} // namespace Envoy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if this is correct for an HTTP client; do we ever hit this in the configured client filter stack? I.e. could it be
NOT_IMPLEMENTED
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I initially left this empty, and when tests failed put NOT_REACHED and it was reached. With this it works, and I did not dig deeper.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested it again, these fail if this is just
{}
:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah we can definitely hit this for AsyncClient, since it goes through router and can return 503 for no healthy upstream and a bunch of other reasons.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, that makes sense.