Skip to content

tracing: inject the tracing header before the upstream filter chain is started#27269

Merged
wbpcode merged 7 commits intoenvoyproxy:mainfrom
wbpcode:dev-fix-tracing-injection
May 15, 2023
Merged

tracing: inject the tracing header before the upstream filter chain is started#27269
wbpcode merged 7 commits intoenvoyproxy:mainfrom
wbpcode:dev-fix-tracing-injection

Conversation

@wbpcode
Copy link
Copy Markdown
Member

@wbpcode wbpcode commented May 9, 2023

Commit Message: tracing: inject the tracing header before the upstream filter chain is started
Additional Description:

The #20503 introduced a unexpected behavior change: that is the tracing headers will be injected after the request_headers_to_add is handled.

It means that users connot access the tracing headers in the request_headers_to_add. But some users require this. Here is the ticket #23972.

I originally intended to resolve this problem by using the upstream header mutation filter.

However, the upstream filter chain will be started directly without waiting the upstream connection to be ready (unexpected design, why, shorter latency?) But the tracing headers will be injected after the upstream connection is ready. So, the upstream header mutation filter still cannot access the tracing headers in some case.

This PR just make sure the tracing headers injection will complete before the upstream filter chain start.

Risk Level: Low.
Testing: n/a.
Docs Changes: n/a.
Release Notes: n/a.
Platform Specific Features: n/a.
[Optional Runtime guard:]
[Optional Fixes #Issue]
[Optional Fixes commit #PR or SHA]
[Optional Deprecated:]
[Optional API Considerations:]

…s started

Signed-off-by: wbpcode <wangbaiping@corp.netease.com>
wbpcode added 3 commits May 9, 2023 12:24
Signed-off-by: wbpcode <wangbaiping@corp.netease.com>
Signed-off-by: wbpcode <wangbaiping@corp.netease.com>
Copy link
Copy Markdown
Contributor

@alyssawilk alyssawilk left a comment

Choose a reason for hiding this comment

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

Thanks for the quick fix!

wbpcode added 2 commits May 10, 2023 16:37
Signed-off-by: wbpcode <wangbaiping@corp.netease.com>
Comment on lines +110 to +119
// The router checks that the connection pool is non-null before creating the upstream request.
auto upstream_host = conn_pool_->host();
if (span_ != nullptr) {
span_->injectContext(*parent_.downstreamHeaders(), upstream_host);
} else {
// No independent child span for current upstream request then inject the parent span's tracing
// context into the request headers.
// The injectContext() of the parent span may be called repeatedly when the request is retried.
parent_.callbacks()->activeSpan().injectContext(*parent_.downstreamHeaders(), upstream_host);
}
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.

And tell the truth, I have a quesion about the host() of pool.
If we can access the host directly by the pool, why we need the host parameter in the onPoolReady() method?
For historical reason?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I suspect so, but not sure.

@wbpcode
Copy link
Copy Markdown
Member Author

wbpcode commented May 11, 2023

hmmmm, why this pr effect the coverage of tap transport_sockets 🤔

image

image

@wbpcode
Copy link
Copy Markdown
Member Author

wbpcode commented May 14, 2023

#27382 resolved this coverage problem temporarily.

@wbpcode
Copy link
Copy Markdown
Member Author

wbpcode commented May 14, 2023

friendly ping @alyssawilk

Comment on lines +110 to +119
// The router checks that the connection pool is non-null before creating the upstream request.
auto upstream_host = conn_pool_->host();
if (span_ != nullptr) {
span_->injectContext(*parent_.downstreamHeaders(), upstream_host);
} else {
// No independent child span for current upstream request then inject the parent span's tracing
// context into the request headers.
// The injectContext() of the parent span may be called repeatedly when the request is retried.
parent_.callbacks()->activeSpan().injectContext(*parent_.downstreamHeaders(), upstream_host);
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I suspect so, but not sure.

@wbpcode wbpcode merged commit 2ede973 into envoyproxy:main May 15, 2023
wbpcode pushed a commit to wbpcode/envoy that referenced this pull request May 16, 2023
…s started (envoyproxy#27269)

* tracing: inject the tracing header before the upstream filter chain is started

Signed-off-by: wbpcode <wangbaiping@corp.netease.com>

* fix test

Signed-off-by: wbpcode <wangbaiping@corp.netease.com>

* update comment

Signed-off-by: wbpcode <wangbaiping@corp.netease.com>

* update comment

Signed-off-by: wbpcode <wangbaiping@corp.netease.com>

---------

Signed-off-by: wbpcode <wangbaiping@corp.netease.com>
@wbpcode wbpcode deleted the dev-fix-tracing-injection branch May 23, 2023 03:33
wbpcode pushed a commit to wbpcode/envoy that referenced this pull request May 23, 2023
…s started (envoyproxy#27269)

* tracing: inject the tracing header before the upstream filter chain is started

Signed-off-by: wbpcode <wangbaiping@corp.netease.com>

* fix test

Signed-off-by: wbpcode <wangbaiping@corp.netease.com>

* update comment

Signed-off-by: wbpcode <wangbaiping@corp.netease.com>

* update comment

Signed-off-by: wbpcode <wangbaiping@corp.netease.com>

---------

Signed-off-by: wbpcode <wangbaiping@corp.netease.com>
phlax pushed a commit that referenced this pull request May 24, 2023
…s started (#27269)

* tracing: inject the tracing header before the upstream filter chain is started

Signed-off-by: wbpcode <wangbaiping@corp.netease.com>

* fix test

Signed-off-by: wbpcode <wangbaiping@corp.netease.com>

* update comment

Signed-off-by: wbpcode <wangbaiping@corp.netease.com>

* update comment

Signed-off-by: wbpcode <wangbaiping@corp.netease.com>

---------

Signed-off-by: wbpcode <wangbaiping@corp.netease.com>
reskin89 pushed a commit to reskin89/envoy that referenced this pull request Jul 11, 2023
…s started (envoyproxy#27269)

* tracing: inject the tracing header before the upstream filter chain is started

Signed-off-by: wbpcode <wangbaiping@corp.netease.com>

* fix test

Signed-off-by: wbpcode <wangbaiping@corp.netease.com>

* update comment

Signed-off-by: wbpcode <wangbaiping@corp.netease.com>

* update comment

Signed-off-by: wbpcode <wangbaiping@corp.netease.com>

---------

Signed-off-by: wbpcode <wangbaiping@corp.netease.com>
Signed-off-by: Ryan Eskin <ryan.eskin89@protonmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants