Skip to content

Commit

Permalink
xray tracer: correctly annotate child spans as xray subsegments (envo…
Browse files Browse the repository at this point in the history
…yproxy#20170)

* test: adding a multi-envoy test (envoyproxy#20016)

Functionally this

handles the multi-envoy signal handler crash
skips instantiating a runtime singleton (off by default, must stay off until remove global runtime: rebase runtime features on ABSL_flags envoyproxy#19847 is closed)
Multi-envoy does not correctly support runtime flags or deprecation stats due to envoyproxy#19847 being incomplete. It can still handle proxy traffic client - L1 - L2 - upstream as shown in test.

Risk Level: low
Testing: yes
Docs Changes: n/a
Release Notes: n/a
Part of envoyproxy/envoy-mobile#2003

Signed-off-by: Alyssa Wilk <alyssar@chromium.org>
Signed-off-by: Rex Chang <58710378+rexnp@users.noreply.github.com>

* Add a congestionWindowInBytes method to Envoy::Network::Connection (envoyproxy#20105)

Signed-off-by: Bin Wu <wub@google.com>
Signed-off-by: Rex Chang <58710378+rexnp@users.noreply.github.com>

* Update QUICHE from 50f15e7a5 to cf1588207 (envoyproxy#20154)

https://github.com/google/quiche/compare/50f15e7a5..cf1588207

$ git log 50f15e7a5..cf1588207 --date=short --no-merges --format="%ad %al %s"

2022-02-28 wub Deprecate --gfe2_reloadable_flag_quic_crypto_noop_if_disconnected_after_process_chlo.
2022-02-27 vasilvv Remove QuicheMemSlice(QuicUniqueBufferPtr, size_t) constructor.
2022-02-26 fayang Use std::string instead of absl::string_view in CryptoBufferMap.
2022-02-25 bnc Ignore incoming HTTP/3 MAX_PUSH_ID frames.
2022-02-25 bnc Remove Http3DebugVisitor::OnMaxPushIdFrameSent().
2022-02-25 bnc Remove QuicSpdySession::CanCreatePushStreamWithId().
2022-02-25 fayang Deprecate gfe2_reloadable_flag_quic_single_ack_in_packet2.

Signed-off-by: Alyssa Wilk <alyssar@chromium.org>
Signed-off-by: Rex Chang <58710378+rexnp@users.noreply.github.com>

* build(deps): bump actions/stale from 4.1.0 to 5 (envoyproxy#20159)

Bumps [actions/stale](https://github.com/actions/stale) from 4.1.0 to 5.
- [Release notes](https://github.com/actions/stale/releases)
- [Changelog](https://github.com/actions/stale/blob/main/CHANGELOG.md)
- [Commits](actions/stale@v4.1.0...v5)

---
updated-dependencies:
- dependency-name: actions/stale
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Signed-off-by: Rex Chang <58710378+rexnp@users.noreply.github.com>

* admin: improve test coverage and increase the coverage-percent threshold (envoyproxy#20025)

Adds a missing test for recent lookups now that there are no more fake symbol tables. Adds tests for a variety of override methods defined in admin.h that were previously hard to hit.

Adds a benchmark test to establish a baseline for the speedups in envoyproxy#19693

Signed-off-by: Joshua Marantz <jmarantz@google.com>
Signed-off-by: Rex Chang <58710378+rexnp@users.noreply.github.com>

* test: removing a bunch of direct runtime singleton access (envoyproxy#19993)

Signed-off-by: Alyssa Wilk <alyssar@chromium.org>
Signed-off-by: Rex Chang <58710378+rexnp@users.noreply.github.com>

* build(deps): bump grpcio-tools in /examples/grpc-bridge/client (envoyproxy#20040)

Bumps [grpcio-tools](https://github.com/grpc/grpc) from 1.43.0 to 1.44.0.
- [Release notes](https://github.com/grpc/grpc/releases)
- [Changelog](https://github.com/grpc/grpc/blob/master/doc/grpc_release_schedule.md)
- [Commits](grpc/grpc@v1.43.0...v1.44.0)

---
updated-dependencies:
- dependency-name: grpcio-tools
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Signed-off-by: Rex Chang <58710378+rexnp@users.noreply.github.com>

* adds to spellcheck

Signed-off-by: Rex Chang <58710378+rexnp@users.noreply.github.com>

* xray tracer: set subsegment type for child spans (#2)

* xray tracer: set subsegment type for child spans

Signed-off-by: Rex Chang <58710378+rexnp@users.noreply.github.com>

* adds test coverage

Signed-off-by: Rex Chang <58710378+rexnp@users.noreply.github.com>

* Xray subsegment (#3)

* xray tracer: set subsegment type for child spans

Signed-off-by: Rex Chang <58710378+rexnp@users.noreply.github.com>

* adds test coverage

Signed-off-by: Rex Chang <58710378+rexnp@users.noreply.github.com>

* updates xray subsegment name to use operation name (instead of parent's span name)

Signed-off-by: Rex Chang <58710378+rexnp@users.noreply.github.com>

* updates doc

Signed-off-by: Rex Chang <58710378+rexnp@users.noreply.github.com>

* updates doc

Signed-off-by: Rex Chang <58710378+rexnp@users.noreply.github.com>

* Xray subsegment (#4)

* xray tracer: set subsegment type for child spans

Signed-off-by: Rex Chang <58710378+rexnp@users.noreply.github.com>

* adds test coverage

Signed-off-by: Rex Chang <58710378+rexnp@users.noreply.github.com>

* updates xray subsegment name to use operation name (instead of parent's span name)

Signed-off-by: Rex Chang <58710378+rexnp@users.noreply.github.com>

* updates doc

Signed-off-by: Rex Chang <58710378+rexnp@users.noreply.github.com>

* updates doc

Signed-off-by: Rex Chang <58710378+rexnp@users.noreply.github.com>

* adds to spell check dictionary

Signed-off-by: Rex Chang <58710378+rexnp@users.noreply.github.com>

* fixes spellcheck

Signed-off-by: Rex Chang <58710378+rexnp@users.noreply.github.com>

* adds to spellcheck

Signed-off-by: Rex Chang <58710378+rexnp@users.noreply.github.com>

xray tracer: set subsegment type for child spans (#2)

* xray tracer: set subsegment type for child spans

Signed-off-by: Rex Chang <58710378+rexnp@users.noreply.github.com>

* adds test coverage

Signed-off-by: Rex Chang <58710378+rexnp@users.noreply.github.com>

Xray subsegment (#3)

* xray tracer: set subsegment type for child spans

Signed-off-by: Rex Chang <58710378+rexnp@users.noreply.github.com>

* adds test coverage

Signed-off-by: Rex Chang <58710378+rexnp@users.noreply.github.com>

* updates xray subsegment name to use operation name (instead of parent's span name)

Signed-off-by: Rex Chang <58710378+rexnp@users.noreply.github.com>

* updates doc

Signed-off-by: Rex Chang <58710378+rexnp@users.noreply.github.com>

* updates doc

Signed-off-by: Rex Chang <58710378+rexnp@users.noreply.github.com>

Xray subsegment (#4)

* xray tracer: set subsegment type for child spans

Signed-off-by: Rex Chang <58710378+rexnp@users.noreply.github.com>

* adds test coverage

Signed-off-by: Rex Chang <58710378+rexnp@users.noreply.github.com>

* updates xray subsegment name to use operation name (instead of parent's span name)

Signed-off-by: Rex Chang <58710378+rexnp@users.noreply.github.com>

* updates doc

Signed-off-by: Rex Chang <58710378+rexnp@users.noreply.github.com>

* updates doc

Signed-off-by: Rex Chang <58710378+rexnp@users.noreply.github.com>

* adds to spell check dictionary

Signed-off-by: Rex Chang <58710378+rexnp@users.noreply.github.com>

fixes spellcheck

Signed-off-by: Rex Chang <58710378+rexnp@users.noreply.github.com>

* fixes spell check

Signed-off-by: Rex Chang <58710378+rexnp@users.noreply.github.com>

Co-authored-by: alyssawilk <alyssar@chromium.org>
Co-authored-by: Bin Wu <46450037+wu-bin@users.noreply.github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Joshua Marantz <jmarantz@google.com>
  • Loading branch information
5 people authored Mar 15, 2022
1 parent 1945b1e commit 82c02b7
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/root/version_history/current.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ Bug Fixes
* upstream: cluster slow start config add ``min_weight_percent`` field to avoid too big EDF deadline which cause slow start endpoints receiving no traffic, default 10%. This fix is releted to `issue#19526 <https://github.com/envoyproxy/envoy/issues/19526>`_.
* upstream: fix stack overflow when a cluster with large number of idle connections is removed.
* xray: fix the AWS X-Ray tracer extension to not sample the trace if ``sampled=`` keyword is not present in the header ``x-amzn-trace-id``.
* xray: fix the AWS X-Ray tracer extension to annotate a child span with ``type=subsegment`` to correctly relate subsegments to a parent segment. Previously a subsegment would be treated as an independent segment.

Removed Config or Runtime
-------------------------
Expand Down
3 changes: 3 additions & 0 deletions source/extensions/tracers/xray/daemon.proto
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ message Segment {
}
// Object containing one or more fields that X-Ray indexes for use with filter expressions.
map<string, string> annotations = 8;
// Set type to "subsegment" when sending a child span so X-Ray treats it as a subsegment.
// https://docs.aws.amazon.com/xray/latest/devguide/xray-api-segmentdocuments.html#api-segmentdocuments-subsegments
string type = 14;
}

message Header {
Expand Down
7 changes: 5 additions & 2 deletions source/extensions/tracers/xray/tracer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ void Span::finishSpan() {
s.set_error(clientError());
s.set_fault(serverError());
s.set_throttle(isThrottled());

if (type() == Subsegment) {
s.set_type(std::string(Subsegment));
}
auto* aws = s.mutable_aws()->mutable_fields();
for (const auto& field : aws_metadata_) {
aws->insert({field.first, field.second});
Expand Down Expand Up @@ -108,13 +110,14 @@ void Span::injectContext(Tracing::TraceContext& trace_context) {
Tracing::SpanPtr Span::spawnChild(const Tracing::Config& config, const std::string& operation_name,
Envoy::SystemTime start_time) {
auto child_span = std::make_unique<XRay::Span>(time_source_, random_, broker_);
child_span->setName(name());
child_span->setName(operation_name);
child_span->setOperation(operation_name);
child_span->setDirection(Tracing::HttpTracerUtility::toString(config.operationName()));
child_span->setStartTime(start_time);
child_span->setParentId(id());
child_span->setTraceId(traceId());
child_span->setSampled(sampled());
child_span->setType(Subsegment);
return child_span;
}

Expand Down
13 changes: 13 additions & 0 deletions source/extensions/tracers/xray/tracer.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ namespace Tracers {
namespace XRay {

constexpr auto XRayTraceHeader = "x-amzn-trace-id";
constexpr absl::string_view Subsegment = "subsegment";

class Span : public Tracing::Span, Logger::Loggable<Logger::Id::config> {
public:
Expand Down Expand Up @@ -101,6 +102,12 @@ class Span : public Tracing::Span, Logger::Loggable<Logger::Id::config> {
parent_segment_id_ = std::string(parent_segment_id);
}

/**
* Sets the type of the Span. In X-Ray, an independent subsegment has a type of "subsegment".
* https://docs.aws.amazon.com/xray/latest/devguide/xray-api-segmentdocuments.html#api-segmentdocuments-subsegments
*/
void setType(absl::string_view type) { type_ = std::string(type); }

/**
* Sets the aws metadata field of the Span.
*/
Expand Down Expand Up @@ -156,6 +163,11 @@ class Span : public Tracing::Span, Logger::Loggable<Logger::Id::config> {
*/
const std::string& direction() const { return direction_; }

/**
* Gets this Span's type.
*/
const std::string& type() const { return type_; }

/**
* Gets this Span's name.
*/
Expand Down Expand Up @@ -216,6 +228,7 @@ class Span : public Tracing::Span, Logger::Loggable<Logger::Id::config> {
std::string parent_segment_id_;
std::string name_;
std::string origin_;
std::string type_;
absl::flat_hash_map<std::string, ProtobufWkt::Value> aws_metadata_;
absl::flat_hash_map<std::string, ProtobufWkt::Value> http_request_annotations_;
absl::flat_hash_map<std::string, ProtobufWkt::Value> http_response_annotations_;
Expand Down
10 changes: 9 additions & 1 deletion test/extensions/tracers/xray/tracer_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ TEST_F(XRayTracerTest, SerializeSpanTest) {
EXPECT_FALSE(s.id().empty());
EXPECT_EQ(2, s.annotations().size());
EXPECT_TRUE(s.parent_id().empty());
EXPECT_TRUE(s.type().empty());
EXPECT_FALSE(s.fault()); /*server error*/
EXPECT_FALSE(s.error()); /*client error*/
EXPECT_FALSE(s.throttle()); /*request throttled*/
Expand Down Expand Up @@ -142,6 +143,7 @@ TEST_F(XRayTracerTest, SerializeSpanTestServerError) {
EXPECT_FALSE(s.trace_id().empty());
EXPECT_FALSE(s.id().empty());
EXPECT_TRUE(s.parent_id().empty());
EXPECT_TRUE(s.type().empty());
EXPECT_TRUE(s.fault()); /*server error*/
EXPECT_FALSE(s.error()); /*client error*/
EXPECT_EQ(expected_status_code,
Expand Down Expand Up @@ -175,6 +177,7 @@ TEST_F(XRayTracerTest, SerializeSpanTestClientError) {
EXPECT_FALSE(s.trace_id().empty());
EXPECT_FALSE(s.id().empty());
EXPECT_TRUE(s.parent_id().empty());
EXPECT_TRUE(s.type().empty());
EXPECT_FALSE(s.fault()); /*server error*/
EXPECT_TRUE(s.error()); /*client error*/
EXPECT_FALSE(s.throttle()); /*request throttled*/
Expand Down Expand Up @@ -208,6 +211,7 @@ TEST_F(XRayTracerTest, SerializeSpanTestClientErrorWithThrottle) {
EXPECT_FALSE(s.trace_id().empty());
EXPECT_FALSE(s.id().empty());
EXPECT_TRUE(s.parent_id().empty());
EXPECT_TRUE(s.type().empty());
EXPECT_FALSE(s.fault()); /*server error*/
EXPECT_TRUE(s.error()); /*client error*/
EXPECT_TRUE(s.throttle()); /*request throttled*/
Expand Down Expand Up @@ -239,6 +243,7 @@ TEST_F(XRayTracerTest, SerializeSpanTestWithEmptyValue) {
EXPECT_FALSE(s.trace_id().empty());
EXPECT_FALSE(s.id().empty());
EXPECT_TRUE(s.parent_id().empty());
EXPECT_TRUE(s.type().empty());
EXPECT_FALSE(s.http().request().fields().contains(Tracing::Tags::get().Status));
};

Expand Down Expand Up @@ -270,6 +275,7 @@ TEST_F(XRayTracerTest, SerializeSpanTestWithStatusCodeNotANumber) {
EXPECT_FALSE(s.trace_id().empty());
EXPECT_FALSE(s.id().empty());
EXPECT_TRUE(s.parent_id().empty());
EXPECT_TRUE(s.type().empty());
EXPECT_FALSE(s.http().request().fields().contains(Tracing::Tags::get().Status));
EXPECT_FALSE(s.http().request().fields().contains("content_length"));
};
Expand Down Expand Up @@ -346,7 +352,9 @@ TEST_F(XRayTracerTest, ChildSpanHasParentInfo) {
TestUtility::validate(s);
// Hex encoded 64 bit identifier
EXPECT_STREQ("00000000000003e7", s.parent_id().c_str());
EXPECT_EQ(expected_->span_name, s.name().c_str());
EXPECT_EQ(expected_->operation_name, s.name().c_str());
EXPECT_TRUE(xray_parent_span->type().empty());
EXPECT_EQ(Subsegment, s.type().c_str());
EXPECT_STREQ(xray_parent_span->traceId().c_str(), s.trace_id().c_str());
EXPECT_STREQ("0000003d25bebe62", s.id().c_str());
};
Expand Down
1 change: 1 addition & 0 deletions tools/spelling/spelling_dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1177,6 +1177,7 @@ subnets
suboptimal
subsecond
subseconds
subsegment
subsequence
subsetting
substr
Expand Down

0 comments on commit 82c02b7

Please sign in to comment.