Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/envoy/http/mixer/control.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ Control::Control(const Config& config, Upstream::ClusterManager& cm,
}

Utils::CheckTransport::Func Control::GetCheckTransport(
const HeaderMap* headers) {
return Utils::CheckTransport::GetFunc(*check_client_factory_, headers);
Tracing::Span& parent_span) {
return Utils::CheckTransport::GetFunc(*check_client_factory_, parent_span);
}

// Call controller to get statistics.
Expand Down
2 changes: 1 addition & 1 deletion src/envoy/http/mixer/control.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class Control final : public ThreadLocal::ThreadLocalObject {
::istio::control::http::Controller* controller() { return controller_.get(); }

// Create a per-request Check transport function.
Utils::CheckTransport::Func GetCheckTransport(const HeaderMap* headers);
Utils::CheckTransport::Func GetCheckTransport(Tracing::Span& parent_span);

private:
// Call controller to get statistics.
Expand Down
3 changes: 2 additions & 1 deletion src/envoy/http/mixer/filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ FilterHeadersStatus Filter::decodeHeaders(HeaderMap& headers, bool) {
HeaderUpdate header_update(&headers);
headers_ = &headers;
cancel_check_ = handler_->Check(
&check_data, &header_update, control_.GetCheckTransport(&headers),
&check_data, &header_update,
control_.GetCheckTransport(decoder_callbacks_->activeSpan()),
[this](const Status& status) { completeCheck(status); });
initiating_call_ = false;

Expand Down
53 changes: 9 additions & 44 deletions src/envoy/utils/grpc_transport.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,59 +25,23 @@ namespace {
// gRPC request timeout
const std::chrono::milliseconds kGrpcRequestTimeoutMs(5000);

// HTTP trace headers that should pass to gRPC metadata from origin request.
// x-request-id is added for easy debugging.
const Http::LowerCaseString kRequestId("x-request-id");
const Http::LowerCaseString kB3TraceId("x-b3-traceid");
const Http::LowerCaseString kB3SpanId("x-b3-spanid");
const Http::LowerCaseString kB3ParentSpanId("x-b3-parentspanid");
const Http::LowerCaseString kB3Sampled("x-b3-sampled");
const Http::LowerCaseString kB3Flags("x-b3-flags");
const Http::LowerCaseString kOtSpanContext("x-ot-span-context");

inline void CopyHeaderEntry(const Http::HeaderEntry *entry,
const Http::LowerCaseString &key,
Http::HeaderMap &headers) {
if (entry) {
std::string val(entry->value().c_str(), entry->value().size());
headers.addReferenceKey(key, val);
}
}

} // namespace

template <class RequestType, class ResponseType>
GrpcTransport<RequestType, ResponseType>::GrpcTransport(
Grpc::AsyncClientPtr async_client, const RequestType &request,
const Http::HeaderMap *headers, ResponseType *response,
ResponseType *response, Tracing::Span &parent_span,
istio::mixerclient::DoneFunc on_done)
: async_client_(std::move(async_client)),
headers_(headers),
response_(response),
on_done_(on_done),
request_(async_client_->send(
descriptor(), request, *this, Tracing::NullSpan::instance(),
descriptor(), request, *this, parent_span,
absl::optional<std::chrono::milliseconds>(kGrpcRequestTimeoutMs))) {
ENVOY_LOG(debug, "Sending {} request: {}", descriptor().name(),
request.DebugString());
}

template <class RequestType, class ResponseType>
void GrpcTransport<RequestType, ResponseType>::onCreateInitialMetadata(
Http::HeaderMap &metadata) {
if (!headers_) return;

CopyHeaderEntry(headers_->RequestId(), kRequestId, metadata);
CopyHeaderEntry(headers_->XB3TraceId(), kB3TraceId, metadata);
CopyHeaderEntry(headers_->XB3SpanId(), kB3SpanId, metadata);
CopyHeaderEntry(headers_->XB3ParentSpanId(), kB3ParentSpanId, metadata);
CopyHeaderEntry(headers_->XB3Sampled(), kB3Sampled, metadata);
CopyHeaderEntry(headers_->XB3Flags(), kB3Flags, metadata);

// This one is NOT inline, need to do linar search.
CopyHeaderEntry(headers_->get(kOtSpanContext), kOtSpanContext, metadata);
}

template <class RequestType, class ResponseType>
void GrpcTransport<RequestType, ResponseType>::onSuccess(
std::unique_ptr<ResponseType> &&response, Tracing::Span &) {
Expand Down Expand Up @@ -107,12 +71,13 @@ void GrpcTransport<RequestType, ResponseType>::Cancel() {
template <class RequestType, class ResponseType>
typename GrpcTransport<RequestType, ResponseType>::Func
GrpcTransport<RequestType, ResponseType>::GetFunc(
Grpc::AsyncClientFactory &factory, const Http::HeaderMap *headers) {
return [&factory, headers](const RequestType &request, ResponseType *response,
istio::mixerclient::DoneFunc on_done)
Grpc::AsyncClientFactory &factory, Tracing::Span &parent_span) {
return [&factory, &parent_span](const RequestType &request,
ResponseType *response,
istio::mixerclient::DoneFunc on_done)
-> istio::mixerclient::CancelFunc {
auto transport = new GrpcTransport<RequestType, ResponseType>(
factory.create(), request, headers, response, on_done);
factory.create(), request, response, parent_span, on_done);
return [transport]() { transport->Cancel(); };
};
}
Expand All @@ -137,9 +102,9 @@ const google::protobuf::MethodDescriptor &ReportTransport::descriptor() {

// explicitly instantiate CheckTransport and ReportTransport
template CheckTransport::Func CheckTransport::GetFunc(
Grpc::AsyncClientFactory &factory, const Http::HeaderMap *headers);
Grpc::AsyncClientFactory &factory, Tracing::Span &parent_span);
template ReportTransport::Func ReportTransport::GetFunc(
Grpc::AsyncClientFactory &factory, const Http::HeaderMap *headers);
Grpc::AsyncClientFactory &factory, Tracing::Span &parent_span);

} // namespace Utils
} // namespace Envoy
8 changes: 3 additions & 5 deletions src/envoy/utils/grpc_transport.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,13 @@ class GrpcTransport : public Grpc::TypedAsyncRequestCallbacks<ResponseType>,
istio::mixerclient::DoneFunc on_done)>;

static Func GetFunc(Grpc::AsyncClientFactory& factory,
const Http::HeaderMap* headers = nullptr);
Tracing::Span& parent_span);

GrpcTransport(Grpc::AsyncClientPtr async_client, const RequestType& request,
const Http::HeaderMap* headers, ResponseType* response,
ResponseType* response, Tracing::Span& parent_span,
istio::mixerclient::DoneFunc on_done);

// Grpc::AsyncRequestCallbacks<ResponseType>
void onCreateInitialMetadata(Http::HeaderMap& metadata) override;
void onCreateInitialMetadata(Http::HeaderMap&) override {}

void onSuccess(std::unique_ptr<ResponseType>&& response,
Tracing::Span& span) override;
Expand All @@ -60,7 +59,6 @@ class GrpcTransport : public Grpc::TypedAsyncRequestCallbacks<ResponseType>,
static const google::protobuf::MethodDescriptor& descriptor();

Grpc::AsyncClientPtr async_client_;
const Http::HeaderMap* headers_;
ResponseType* response_;
::istio::mixerclient::DoneFunc on_done_;
Grpc::AsyncRequest* request_{};
Expand Down
6 changes: 4 additions & 2 deletions src/envoy/utils/mixer_control.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@ void CreateEnvironment(Event::Dispatcher &dispatcher,
Grpc::AsyncClientFactory &check_client_factory,
Grpc::AsyncClientFactory &report_client_factory,
::istio::mixerclient::Environment *env) {
env->check_transport = CheckTransport::GetFunc(check_client_factory, nullptr);
env->report_transport = ReportTransport::GetFunc(report_client_factory);
env->check_transport = CheckTransport::GetFunc(check_client_factory,
Tracing::NullSpan::instance());
env->report_transport = ReportTransport::GetFunc(
report_client_factory, Tracing::NullSpan::instance());

env->timer_create_func = [&dispatcher](std::function<void()> timer_cb)
-> std::unique_ptr<::istio::mixerclient::Timer> {
Expand Down