Skip to content

Commit 01f403e

Browse files
authored
thrift_proxy: introduce header transport (istio#4082)
Implements the Thrift "header" transport which primarily provides key/value pairs that may contain arbitrary message metadata. *Risk Level*: low *Testing*: added unit/integration tests *Docs Changes*: n/a *Release Notes*: n/a Signed-off-by: Stephan Zuercher <[email protected]>
1 parent 564d256 commit 01f403e

File tree

22 files changed

+1493
-31
lines changed

22 files changed

+1493
-31
lines changed

api/envoy/config/filter/network/thrift_proxy/v2alpha1/thrift_proxy.proto

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ message ThriftProxy {
2323

2424
// The Thrift proxy will assume the client is using the Thrift unframed transport.
2525
UNFRAMED = 2;
26+
27+
// The Thrift proxy will assume the client is using the Thrift header transport.
28+
HEADER = 3;
2629
}
2730

2831
// Supplies the type of transport that the Thrift proxy should use. Defaults to `AUTO_TRANSPORT`.

source/extensions/filters/network/thrift_proxy/BUILD

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,13 @@ envoy_cc_library(
187187
name = "transport_lib",
188188
srcs = [
189189
"framed_transport_impl.cc",
190+
"header_transport_impl.cc",
190191
"transport_impl.cc",
191192
"unframed_transport_impl.cc",
192193
],
193194
hdrs = [
194195
"framed_transport_impl.h",
196+
"header_transport_impl.h",
195197
"transport_impl.h",
196198
"unframed_transport_impl.h",
197199
],

source/extensions/filters/network/thrift_proxy/config.cc

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ static const TransportTypeMap& transportTypeMap() {
4141
{envoy::config::filter::network::thrift_proxy::v2alpha1::
4242
ThriftProxy_TransportType_UNFRAMED,
4343
TransportType::Unframed},
44+
{envoy::config::filter::network::thrift_proxy::v2alpha1::ThriftProxy_TransportType_HEADER,
45+
TransportType::Header},
4446
});
4547
}
4648

@@ -92,6 +94,20 @@ ConfigImpl::ConfigImpl(
9294
transport_(config.transport()), proto_(config.protocol()),
9395
route_matcher_(new Router::RouteMatcher(config.route_config())) {
9496

97+
if (transportTypeMap().find(transport_) == transportTypeMap().end()) {
98+
throw EnvoyException(fmt::format(
99+
"unknown transport {}",
100+
envoy::config::filter::network::thrift_proxy::v2alpha1::ThriftProxy_TransportType_Name(
101+
transport_)));
102+
}
103+
104+
if (protocolTypeMap().find(proto_) == protocolTypeMap().end()) {
105+
throw EnvoyException(fmt::format(
106+
"unknown protocol {}",
107+
envoy::config::filter::network::thrift_proxy::v2alpha1::ThriftProxy_ProtocolType_Name(
108+
proto_)));
109+
}
110+
95111
// Construct the only Thrift DecoderFilter: the Router
96112
auto& factory =
97113
Envoy::Config::Utility::getAndCheckFactory<ThriftFilters::NamedThriftFilterConfigFactory>(
@@ -115,14 +131,14 @@ DecoderPtr ConfigImpl::createDecoder(DecoderCallbacks& callbacks) {
115131

116132
TransportPtr ConfigImpl::createTransport() {
117133
TransportTypeMap::const_iterator i = transportTypeMap().find(transport_);
118-
RELEASE_ASSERT(i != transportTypeMap().end(), "invalid transport type");
134+
ASSERT(i != transportTypeMap().end());
119135

120136
return NamedTransportConfigFactory::getFactory(i->second).createTransport();
121137
}
122138

123139
ProtocolPtr ConfigImpl::createProtocol() {
124140
ProtocolTypeMap::const_iterator i = protocolTypeMap().find(proto_);
125-
RELEASE_ASSERT(i != protocolTypeMap().end(), "invalid protocol type");
141+
ASSERT(i != protocolTypeMap().end());
126142
return NamedProtocolConfigFactory::getFactory(i->second).createProtocol();
127143
}
128144

source/extensions/filters/network/thrift_proxy/decoder.cc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,25 @@ ThriftFilters::FilterStatus Decoder::onData(Buffer::Instance& data, bool& buffer
385385
}
386386
ENVOY_LOG(debug, "thrift: {} transport started", transport_->name());
387387

388+
if (metadata_->hasProtocol()) {
389+
if (protocol_->type() == ProtocolType::Auto) {
390+
protocol_->setType(metadata_->protocol());
391+
ENVOY_LOG(debug, "thrift: {} transport forced {} protocol", transport_->name(),
392+
protocol_->name());
393+
} else if (metadata_->protocol() != protocol_->type()) {
394+
throw EnvoyException(fmt::format("transport reports protocol {}, but configured for {}",
395+
ProtocolNames::get().fromType(metadata_->protocol()),
396+
ProtocolNames::get().fromType(protocol_->type())));
397+
}
398+
}
399+
if (metadata_->hasAppException()) {
400+
AppExceptionType ex_type = metadata_->appExceptionType();
401+
std::string ex_msg = metadata_->appExceptionMessage();
402+
// Force new metadata if we get called again.
403+
metadata_.reset();
404+
throw AppException(ex_type, ex_msg);
405+
}
406+
388407
request_ = std::make_unique<ActiveRequest>(callbacks_.newDecoderFilter());
389408
frame_started_ = true;
390409
state_machine_ =

0 commit comments

Comments
 (0)