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
3 changes: 0 additions & 3 deletions source/common/router/router.cc
Original file line number Diff line number Diff line change
Expand Up @@ -652,9 +652,6 @@ Http::FilterHeadersStatus Filter::decodeHeaders(Http::RequestHeaderMap& headers,
}
callbacks_->streamInfo().setAttemptCount(attempt_count_);

// Inject the active span's tracing context into the request headers.
callbacks_->activeSpan().injectContext(headers);
Comment on lines -655 to -656
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What are the implications of this with regard to retries and hedging? I'm concerned this a change in behavior here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

If start_child_span is set to false, then we may do some repeated injectings when retries occur. This should be safe because in previous implementation, we may re-inject tracing context as well.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

In the #20367, we want to update the injectContext API to add a new parameter to provide target upstream of current upstream request. This PR can also complete some pre-work.


route_entry_->finalizeRequestHeaders(headers, callbacks_->streamInfo(),
!config_.suppress_envoy_headers_);
FilterUtility::setUpstreamScheme(
Expand Down
5 changes: 5 additions & 0 deletions source/common/router/upstream_request.cc
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,11 @@ void UpstreamRequest::onPoolReady(

if (span_ != nullptr) {
span_->injectContext(*parent_.downstreamHeaders());
} else {
// No independent child span for current upstream request then inject the parent span's tracing
// context into the request headers.
Comment on lines +490 to +491
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

OK I understand now, thanks for explaining. Do you mind adding a few more comments here on the implications of doing this multiple times for retries, etc.? I understand this is the way it was always done, but it's a little more confusing now. Thank you!

/wait

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

get it.

// The injectContext() of the parent span may be called repeatedly when the request is retried.
parent_.callbacks()->activeSpan().injectContext(*parent_.downstreamHeaders());
}

upstreamTiming().onFirstUpstreamTxByteSent(parent_.callbacks()->dispatcher().timeSource());
Expand Down
37 changes: 37 additions & 0 deletions test/common/router/router_2_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,43 @@ TEST_F(RouterTestChildSpan, ResetRetryFlow) {
response_decoder->decodeHeaders(std::move(response_headers), true);
}

class RouterTestNoChildSpan : public RouterTestBase {
public:
RouterTestNoChildSpan()
: RouterTestBase(false, false, false, Protobuf::RepeatedPtrField<std::string>{}) {}
};

TEST_F(RouterTestNoChildSpan, BasicFlow) {
EXPECT_CALL(callbacks_.route_->route_entry_, timeout())
.WillOnce(Return(std::chrono::milliseconds(0)));
EXPECT_CALL(callbacks_.dispatcher_, createTimer_(_)).Times(0);

NiceMock<Http::MockRequestEncoder> encoder;
Http::ResponseDecoder* response_decoder = nullptr;
EXPECT_CALL(cm_.thread_local_cluster_.conn_pool_, newStream(_, _, _))
.WillOnce(
Invoke([&](Http::ResponseDecoder& decoder, Http::ConnectionPool::Callbacks& callbacks,
const Http::ConnectionPool::Instance::StreamOptions&)
-> Http::ConnectionPool::Cancellable* {
response_decoder = &decoder;
EXPECT_CALL(callbacks_.active_span_, injectContext(_));
callbacks.onPoolReady(encoder, cm_.thread_local_cluster_.conn_pool_.host_,
upstream_stream_info_, Http::Protocol::Http10);
return nullptr;
}));

Http::TestRequestHeaderMapImpl headers;
HttpTestUtility::addDefaultHeaders(headers);
router_.decodeHeaders(headers, true);
EXPECT_EQ(1U,
callbacks_.route_->route_entry_.virtual_cluster_.stats().upstream_rq_total_.value());

Http::ResponseHeaderMapPtr response_headers(
new Http::TestResponseHeaderMapImpl{{":status", "200"}});
ASSERT(response_decoder);
response_decoder->decodeHeaders(std::move(response_headers), true);
}

namespace {

Protobuf::RepeatedPtrField<std::string> protobufStrList(const std::vector<std::string>& v) {
Expand Down
7 changes: 0 additions & 7 deletions test/common/router/router_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,6 @@ TEST_F(RouterTest, Http1Upstream) {
Http::TestRequestHeaderMapImpl headers;
HttpTestUtility::addDefaultHeaders(headers);
EXPECT_CALL(callbacks_.route_->route_entry_, finalizeRequestHeaders(_, _, true));
EXPECT_CALL(span_, injectContext(_));
router_.decodeHeaders(headers, true);
EXPECT_EQ("10", headers.get_("x-envoy-expected-rq-timeout-ms"));

Expand All @@ -432,7 +431,6 @@ TEST_F(RouterTest, Http2Upstream) {

Http::TestRequestHeaderMapImpl headers;
HttpTestUtility::addDefaultHeaders(headers);
EXPECT_CALL(span_, injectContext(_));
router_.decodeHeaders(headers, true);

// When the router filter gets reset we should cancel the pool request.
Expand Down Expand Up @@ -739,7 +737,6 @@ TEST_F(RouterTest, MaintenanceMode) {
EXPECT_CALL(callbacks_, encodeHeaders_(HeaderMapEqualRef(&response_headers), false));
EXPECT_CALL(callbacks_, encodeData(_, true));
EXPECT_CALL(callbacks_.stream_info_, setResponseFlag(StreamInfo::ResponseFlag::UpstreamOverflow));
EXPECT_CALL(span_, injectContext(_)).Times(0);

Http::TestRequestHeaderMapImpl headers;
HttpTestUtility::addDefaultHeaders(headers);
Expand Down Expand Up @@ -4556,7 +4553,6 @@ TEST_F(RouterTest, DirectResponse) {

Http::TestResponseHeaderMapImpl response_headers{{":status", "200"}};
EXPECT_CALL(callbacks_, encodeHeaders_(HeaderMapEqualRef(&response_headers), true));
EXPECT_CALL(span_, injectContext(_)).Times(0);
Http::TestRequestHeaderMapImpl headers;
HttpTestUtility::addDefaultHeaders(headers);
router_.decodeHeaders(headers, true);
Expand Down Expand Up @@ -4606,7 +4602,6 @@ TEST_F(RouterTest, DirectResponseWithLocation) {
Http::TestResponseHeaderMapImpl response_headers{{":status", "201"},
{"location", "http://host/"}};
EXPECT_CALL(callbacks_, encodeHeaders_(HeaderMapEqualRef(&response_headers), true));
EXPECT_CALL(span_, injectContext(_)).Times(0);
Http::TestRequestHeaderMapImpl headers;
HttpTestUtility::addDefaultHeaders(headers);
router_.decodeHeaders(headers, true);
Expand All @@ -4630,7 +4625,6 @@ TEST_F(RouterTest, DirectResponseWithoutLocation) {

Http::TestResponseHeaderMapImpl response_headers{{":status", "200"}};
EXPECT_CALL(callbacks_, encodeHeaders_(HeaderMapEqualRef(&response_headers), true));
EXPECT_CALL(span_, injectContext(_)).Times(0);
Http::TestRequestHeaderMapImpl headers;
HttpTestUtility::addDefaultHeaders(headers);
router_.decodeHeaders(headers, true);
Expand Down Expand Up @@ -5653,7 +5647,6 @@ TEST_F(RouterTest, ApplicationProtocols) {

Http::TestRequestHeaderMapImpl headers;
HttpTestUtility::addDefaultHeaders(headers);
EXPECT_CALL(span_, injectContext(_));
router_.decodeHeaders(headers, true);

// When the router filter gets reset we should cancel the pool request.
Expand Down