-
Notifications
You must be signed in to change notification settings - Fork 5.3k
thrift_proxy: simple thrift router #3863
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
Changes from all commits
a6c04ca
3ae3f17
356e103
c194f89
add4328
21feb75
bacbded
98f68aa
d065987
69b02a3
7fab7e1
5d967d2
e4c839e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| syntax = "proto3"; | ||
|
|
||
| package envoy.extensions.filters.network.thrift_proxy.v2alpha1; | ||
| option go_package = "v2"; | ||
|
|
||
| import "validate/validate.proto"; | ||
| import "gogoproto/gogo.proto"; | ||
|
|
||
| // [#protodoc-title: Thrift route configuration] | ||
|
|
||
| // [#comment:next free field: 3] | ||
| message RouteConfiguration { | ||
| // The name of the route configuration. Reserved for future use in asynchronous route discovery. | ||
| string name = 1; | ||
|
|
||
| // The list of routes that will be matched, in order, against incoming requests. The first route | ||
| // that matches will be used. | ||
| repeated Route routes = 2 [(gogoproto.nullable) = false]; | ||
| } | ||
|
|
||
| // [#comment:next free field: 3] | ||
| message Route { | ||
| // Route matching prarameters. | ||
| RouteMatch match = 1 [(validate.rules).message.required = true, (gogoproto.nullable) = false]; | ||
|
|
||
| // Route request to some upstream cluster. | ||
| RouteAction route = 2 [(validate.rules).message.required = true, (gogoproto.nullable) = false]; | ||
| } | ||
|
|
||
| // [#comment:next free field: 2] | ||
| message RouteMatch { | ||
| // If specified, the route must exactly match the request method name. As a special case, an | ||
| // empty string matches any request method name. | ||
| string method = 1; | ||
| } | ||
|
|
||
| // [#comment:next free field: 2] | ||
| message RouteAction { | ||
| // Indicates the upstream cluster to which the request should be routed. | ||
| string cluster = 1 [(validate.rules).string.min_bytes = 1]; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| load("//bazel:api_build_system.bzl", "api_proto_library_internal") | ||
|
|
||
| licenses(["notice"]) # Apache 2 | ||
|
|
||
| api_proto_library_internal( | ||
| name = "router", | ||
| srcs = ["router.proto"], | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| syntax = "proto3"; | ||
|
|
||
| package envoy.extensions.filters.network.thrift_proxy.v2alpha1.router; | ||
| option go_package = "router"; | ||
|
|
||
| // [#protodoc-title: Thrift Router] | ||
| // Thrift Router configuration. | ||
| message Router { | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| #include "extensions/filters/network/thrift_proxy/app_exception_impl.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Extensions { | ||
| namespace NetworkFilters { | ||
| namespace ThriftProxy { | ||
|
|
||
| static const std::string TApplicationException = "TApplicationException"; | ||
| static const std::string MessageField = "message"; | ||
| static const std::string TypeField = "type"; | ||
| static const std::string StopField = ""; | ||
|
|
||
| void AppException::encode(ThriftProxy::Protocol& proto, Buffer::Instance& buffer) { | ||
| proto.writeMessageBegin(buffer, method_name_, ThriftProxy::MessageType::Exception, seq_id_); | ||
| proto.writeStructBegin(buffer, TApplicationException); | ||
|
|
||
| proto.writeFieldBegin(buffer, MessageField, ThriftProxy::FieldType::String, 1); | ||
| proto.writeString(buffer, error_message_); | ||
| proto.writeFieldEnd(buffer); | ||
|
|
||
| proto.writeFieldBegin(buffer, TypeField, ThriftProxy::FieldType::I32, 2); | ||
| proto.writeInt32(buffer, static_cast<int32_t>(type_)); | ||
| proto.writeFieldEnd(buffer); | ||
|
|
||
| proto.writeFieldBegin(buffer, StopField, ThriftProxy::FieldType::Stop, 0); | ||
|
|
||
| proto.writeStructEnd(buffer); | ||
| proto.writeMessageEnd(buffer); | ||
| } | ||
|
|
||
| } // namespace ThriftProxy | ||
| } // namespace NetworkFilters | ||
| } // namespace Extensions | ||
| } // namespace Envoy |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| #pragma once | ||
|
|
||
| #include "extensions/filters/network/thrift_proxy/filters/filter.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Extensions { | ||
| namespace NetworkFilters { | ||
| namespace ThriftProxy { | ||
|
|
||
| /** | ||
| * Thrift Application Exception types. | ||
| * See https://github.com/apache/thrift/blob/master/doc/specs/thrift-rpc.md | ||
| */ | ||
| enum class AppExceptionType { | ||
| Unknown = 0, | ||
| UnknownMethod = 1, | ||
| InvalidMessageType = 2, | ||
| WrongMethodName = 3, | ||
| BadSequenceId = 4, | ||
| MissingResult = 5, | ||
| InternalError = 6, | ||
| ProtocolError = 7, | ||
| InvalidTransform = 8, | ||
| InvalidProtocol = 9, | ||
| UnsupportedClientType = 10, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Is
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think short-term, we'll stick with the apache definitions. Longer term, we'll probably want to use internal identifiers for various error conditions and then provide a configuration point to control whether they get mapped to apache or fb's values. |
||
| }; | ||
|
|
||
| struct AppException : public ThriftFilters::DirectResponse { | ||
| AppException(const absl::string_view method_name, int32_t seq_id, AppExceptionType type, | ||
| const std::string& error_message) | ||
| : method_name_(method_name), seq_id_(seq_id), type_(type), error_message_(error_message) {} | ||
|
|
||
| void encode(ThriftProxy::Protocol& proto, Buffer::Instance& buffer) override; | ||
|
|
||
| const std::string method_name_; | ||
| const int32_t seq_id_; | ||
| const AppExceptionType type_; | ||
| const std::string error_message_; | ||
| }; | ||
|
|
||
| } // namespace ThriftProxy | ||
| } // namespace NetworkFilters | ||
| } // namespace Extensions | ||
| } // namespace Envoy | ||
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.
is this case-sensitive?
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.
Yes.