Skip to content

skywalking: inject peer IP address into span's peer field#20454

Closed
Shikugawa wants to merge 3 commits intoenvoyproxy:mainfrom
Shikugawa:set-peer
Closed

skywalking: inject peer IP address into span's peer field#20454
Shikugawa wants to merge 3 commits intoenvoyproxy:mainfrom
Shikugawa:set-peer

Conversation

@Shikugawa
Copy link
Copy Markdown
Member

Signed-off-by: Shikugawa rei@tetrate.io

Commit Message: skywalking: inject peer IP address into span's peer field
Additional Description:
Risk Level: Low
Testing: Unit
Docs Changes:
Release Notes:
Platform Specific Features:
[Optional Runtime guard:]
[Optional Fixes #Issue]
[Optional Fixes commit #PR or SHA]
[Optional Deprecated:]
[Optional API Considerations:]

Signed-off-by: Shikugawa <rei@tetrate.io>
@wbpcode
Copy link
Copy Markdown
Member

wbpcode commented Mar 24, 2022

Hi, @Shikugawa does this PR is still necessary after #20367?

@Shikugawa
Copy link
Copy Markdown
Member Author

Hi, @Shikugawa does this PR is still necessary after #20367?

Yes. This PR enables to inject host address into a span. But another enables to inject it into a upstream header.

Signed-off-by: Shikugawa <rei@tetrate.io>
Signed-off-by: Shikugawa <rei@tetrate.io>
Copy link
Copy Markdown
Member

@wbpcode wbpcode left a comment

Choose a reason for hiding this comment

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

Hi, thanks for your great works. And some comments are added.


// TODO: This method is unimplemented for OpenTracing.
std::string getTraceIdAsHex() const override { return EMPTY_STRING; };
void setStreamInfo(const StreamInfo::StreamInfo&) override{};
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.

Unnecessary semicolon. And looks like all the tracers copied the getTraceIdAsHex() which also has a unnecessary semicolon.

Comment on lines +42 to +46
void Span::setStreamInfo(const StreamInfo::StreamInfo& stream_info) {
if (stream_info.upstreamInfo() && stream_info.upstreamInfo()->upstreamHost()) {
span_entity_->setPeer(stream_info.upstreamInfo()->upstreamHost()->address()->asString());
}
}
Copy link
Copy Markdown
Member

@wbpcode wbpcode Mar 29, 2022

Choose a reason for hiding this comment

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

This setStreamInfo will only be called when we finalize downstream span (Entry Span for Skywalking). I am not sure the peer address of Entry Span is the upstream host address ?

The peer address of Entry Span should be the downstream address, right? And the peer address of Exit Span should be the upstream address.
cc @wu-sheng

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The peer address of Entry Span should be the downstream address, right? And the peer address of Exit Span should be the upstream address.

The peer of exit span is the key. The entry span's is optional actually.

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.

Then, the peer address of Exit Span should be the upstream address, is that right?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Yes, it is correct.

Copy link
Copy Markdown
Member

@wbpcode wbpcode Mar 29, 2022

Choose a reason for hiding this comment

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

@wu-sheng Get it, thanks.

Copy link
Copy Markdown
Member

@wbpcode wbpcode Mar 29, 2022

Choose a reason for hiding this comment

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

@Shikugawa based on the above discussions, may be we can complete the peer address injection of Exit Span directly in the #20367.

We can inject the downstream address of the Entry Span here if you think it's necessary. But it should be unnecessary, because Envoy will set peer address tag for the downstream span.

    const auto& remote_address = stream_info.downstreamAddressProvider().directRemoteAddress();

    if (remote_address->type() == Network::Address::Type::Ip) {
      const auto remote_ip = remote_address->ip();
      span.setTag(Tracing::Tags::get().PeerAddress, remote_ip->addressAsString());
    } else {
      span.setTag(Tracing::Tags::get().PeerAddress, remote_address->logicalName());
    }

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 don't think this is good to set peer address in exit span in injectContext due to the incompatibility of the name of the function. I think that it will be better as follows:

void setStreamInfo(const StreamInfo::StreamInfo& stream) {
  if (span_entity_->spanType() == Entry) {
    span_entity_->setPeer(tream_info.downstreamAddressProvider().directRemoteAddress()->addressAsString());
  } else {
    span_entity_->setPeer(tream_info.upstreamInfo()->upstreamHost()->address()->asString());
  }
}

And calls setStreamInfo before finishSpan is called.

Copy link
Copy Markdown
Member

@wbpcode wbpcode Mar 30, 2022

Choose a reason for hiding this comment

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

Thanks for your reply. My hope is that this can be done with minimal code modification, minimal performance overhead, and avoiding duplicate field settings.

If we had done this directly in #20367, the most critical exit span peer injection might have been done with just one extra line of code. And there is no need to repeatedly obtain the upstream host from stream info, and the performance will be slightly better.

The method name doesn't really matter. Because peer of exit span is a unique concept of skywalking, it is unknown to the caller of the virtual method. So we only need to do this work in any suitable method implementation.

However, this is only my personal opinion after all, it is only for reference. As long as the implementation is clean and correct, we can find another relevant maintainer to review the PR, and his review opinion shall prevail. 😸

Copy link
Copy Markdown
Member Author

@Shikugawa Shikugawa Mar 30, 2022

Choose a reason for hiding this comment

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

Since these operations have nothing to do with Header Injection, they complicate the code on the SkyWalking side. In addition, the performance impact of such operations is negligible. So I think I should define setStreamInfo(). Do you have any quick ideas? cc. @mattklein123 @lizan

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Since these operations have nothing to do with Header Injection

The entry span's operation does. The parent endpoint in the header is the entry span's operation name(path).

@wbpcode
Copy link
Copy Markdown
Member

wbpcode commented Mar 29, 2022

/wait

@github-actions
Copy link
Copy Markdown

This pull request has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed in 7 days if no further activity occurs. Please feel free to give a status update now, ping for review, or re-open when it's ready. Thank you for your contributions!

@github-actions github-actions bot added the stale stalebot believes this issue/PR has not been touched recently label Apr 30, 2022
@wbpcode wbpcode added no stalebot Disables stalebot from closing an issue and removed stale stalebot believes this issue/PR has not been touched recently labels Apr 30, 2022
@wbpcode
Copy link
Copy Markdown
Member

wbpcode commented May 9, 2022

check #21137.

@wbpcode wbpcode closed this May 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no stalebot Disables stalebot from closing an issue waiting

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants