Skip to content

replace RequestHeaderMap in tracers with general TraceContext - #17212

Merged
lizan merged 5 commits into
envoyproxy:mainfrom
wbpcode:last-tracing
Jul 8, 2021
Merged

lizan merged 5 commits into
envoyproxy:mainfrom
wbpcode:last-tracing

Conversation

@wbpcode

@wbpcode wbpcode commented Jul 1, 2021

Copy link
Copy Markdown
Member

Sub-PR of #16049. Check #16049 get more background information.

This PR is last sub-PR of #16049. It simply replaces Http::RequestHeaderMap with general Tracing::TraceContext in all tracer drivers implementations.

Check #16793 get more info about Tracing::TraceContext.

After this PR, the main body of the entire general tracing system is completed. Next, we can try to use the new general tracing system in dubbo and thrift.

Commit Message: replace RequestHeaderMap in tracers with general TraceContext
Risk Level: Low.
Testing: N/A.
Docs Changes: N/A.
Release Notes: N/A.


namespace {
class OpenTracingHTTPHeadersWriter : public opentracing::HTTPHeadersWriter {
class OpenTracingHeadersWriter : public opentracing::HTTPHeadersWriter {

@Shikugawa Shikugawa Jul 1, 2021 •

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.

Can we operate general tracing context, not only HTTP header in this class? If not, I think we don't have to modify this class. It is because we only accept HTTP headers here, not general tracing context.

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.

🤔 I think there is no problem, because here only simple set and get operations are needed on TraceContext. So it is completely possible to use TraceContext to replace HeaderMap.
TraceContext does not support iterative API for the time being, so dynamic_cast is used to temporarily bypass this problem.
And this is an overall change, we can't just keep this one class without making changes.

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.

The superclass is HTTPHeadersWriter so this is still HTTP only?

@wbpcode wbpcode Jul 4, 2021 •

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.

@lizan Apart from the name, HTTPHeadersWriter does not seem to have anything related to the HTTP protocol.

I have checked source code of opentracing interface and also implementation of datadog/lightstep. HTTPHeadersWriter does not contain any HTTP-dependent interfaces. HTTPHeadersWriter simply inherits from TextMapWriter, without adding any HTTP-related methods.

class TextMapReader {
 public:
  virtual ~TextMapReader() = default;
  virtual expected<string_view> LookupKey(string_view /*key*/) const {
    return make_unexpected(lookup_key_not_supported_error);
  }
  virtual expected<void> ForeachKey(
      std::function<expected<void>(string_view key, string_view value)> f)
      const = 0;
};

class TextMapWriter {
 public:
  virtual ~TextMapWriter() = default;
  virtual expected<void> Set(string_view key, string_view value) const = 0;
};

class HTTPHeadersReader : public TextMapReader {};
class HTTPHeadersWriter : public TextMapWriter {};

datadog/lightstep also does not provide any operations for HTTPHeadersWriter that are different from TextMapWriter.

In summary, HTTPHeadersWriter will not affect the generality of tracers. We can completely replace it with TextMapWriter. The reason why I have not done this at present is because I don't want the general tracing system to have any impact on existing HTTP Tracers users.

@wbpcode

wbpcode commented Jul 1, 2021

Copy link
Copy Markdown
Member Author

/retest

@repokitteh-read-only

Copy link
Copy Markdown

Retrying Azure Pipelines:
Retried failed jobs in: envoy-presubmit

🐱

Caused by: a #17212 (comment) was created by @wbpcode.

see: more, trace.

@lizan lizan self-assigned this Jul 2, 2021
const auto entry = ctx.request_headers->get(name_);
return !entry.empty() ? entry[0]->value().getStringView() : default_value_;
const auto entry = ctx.trace_context->getTraceContext(name_);
return entry.has_value() ? entry.value() : default_value_;

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.

Suggested change
return entry.has_value() ? entry.value() : default_value_;
return entry.value_or(default_value_);

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.


namespace {
class OpenTracingHTTPHeadersWriter : public opentracing::HTTPHeadersWriter {
class OpenTracingHeadersWriter : public opentracing::HTTPHeadersWriter {

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.

The superclass is HTTPHeadersWriter so this is still HTTP only?

@wbpcode

wbpcode commented Jul 5, 2021

Copy link
Copy Markdown
Member Author

/retest

@repokitteh-read-only

Copy link
Copy Markdown

Retrying Azure Pipelines:
Retried failed jobs in: envoy-presubmit

🐱

Caused by: a #17212 (comment) was created by @wbpcode.

see: more, trace.

@lizan
lizan merged commit 00f5656 into envoyproxy:main Jul 8, 2021
leyao-daily pushed a commit to leyao-daily/envoy that referenced this pull request Sep 30, 2021
…roxy#17212)

Sub-PR of envoyproxy#16049. Check envoyproxy#16049 get more background information.

This PR is last sub-PR of envoyproxy#16049. It simply replaces `Http::RequestHeaderMap` with general `Tracing::TraceContext` in all tracer drivers implementations.

Check envoyproxy#16793 get more info about `Tracing::TraceContext`.

After this PR, the main body of the entire general tracing system is completed. Next, we can try to use the new general tracing system in dubbo and thrift.

Commit Message: replace RequestHeaderMap in tracers with general TraceContext
Risk Level: Low.
Testing: N/A.
Docs Changes: N/A.
Release Notes: N/A.

Signed-off-by: wbpcode <[email protected]>
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.

3 participants