Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xray: Use correct types for segment document output #10834

Merged
merged 7 commits into from
Apr 22, 2020

Conversation

dastbe
Copy link
Contributor

@dastbe dastbe commented Apr 17, 2020

Description: Switches X-Ray tracing plugin to use proto3 structs, which emit correctly typed outputs (String for StringValue, Number for NumberValue, etc.) such that X-Ray will process those fields.
Risk Level: Low
Testing: unit-tests, manual
Docs Changes: N/A
Release Notes: N/A
Fixes: #10814

manual verification via a udpdump script

received message: 
{
  "format": "json",
  "version": 1
}
{
  "name": "test",
  "id": "0001db556b0a4300",
  "trace_id": "1-5e98e9bb-1d9f337ee5da4242b7c90aa5",
  "start_time": 1587079611.7999656,
  "end_time": 1587079611.803993,
  "http": {
    "request": {
      "method": "GET",
      "x_forwarded_for": false,
      "url": "http://localhost:8080/",
      "user_agent": "curl/7.58.0",
      "client_ip": "127.0.0.1"
    },
    "response": {
      "content_length": 976,
      "status": 200
    }
  },
  "annotations": {
    "downstream_cluster": "-",
    "response_flags": "-",
    "request_size": "0",
    "upstream_cluster": "service1",
    "guid:x-request-id": "7f35dadf-d8b9-9798-a97e-21e2c759ce11",
    "http.protocol": "HTTP/1.1",
    "node_id": "abc_id",
    "component": "proxy"
  }
}

David Bell added 2 commits April 17, 2020 20:56
Signed-off-by: David Bell <belldav@amazon.com>
…retain type information

Risk Level: Low
Testing: unit tests, manual
Docs Changes: N/A
Release Notes: N/A
Fixes: envoyproxy#10814

Signed-off-by: David Bell <belldav@amazon.com>
@mattklein123
Copy link
Member

@marcomagdy for first pass. Also, please substantially improve xray coverage here: https://storage.googleapis.com/envoy-coverage/report-master/index.html. There is a lot missing. Thank you!

/wait

Signed-off-by: David Bell <belldav@amazon.com>
Copy link
Contributor

@marcomagdy marcomagdy left a comment

Choose a reason for hiding this comment

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

Thank you for taking care of this. I left some comments.

daemon::Segment_http_annotations* http = s.mutable_http();

ProtobufWkt::Struct* request = http->mutable_request();
auto request_fields = request->mutable_fields();
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: auto* instead of auto when the deduced type is a pointer.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed.

for (const auto& field : http_request_annotations_) {
request_fields->insert(StructField{field.first, field.second});

(*request_fields)[field.first] = field.second;
Copy link
Contributor

Choose a reason for hiding this comment

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

This line is a duplicate. remove?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

bleh, looking at this and cout it looks like I didn't look at my rebase merge closely enough. fixed.

@@ -179,20 +191,31 @@ void Span::setTag(absl::string_view name, absl::string_view value) {
}

if (name == HttpUrl) {
http_request_annotations_.emplace(SpanUrl, value);
http_request_annotations_.emplace(SpanUrl, ValueUtil::stringValue(std::string(value)));
Copy link
Contributor

Choose a reason for hiding this comment

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

value is a string already.
so this should be ValueUtil::stringValue(value); instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So value is a string_view, and based off my read of the abseil docs and the header there is no implicit conversion from string_view to string. As rusty as I am at c++, I'm assuming the reason the "implicit conversion" works for flat_hash_map::emplace is because its constructing from arguments internally

Copy link
Contributor

Choose a reason for hiding this comment

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

if value is a string_view, then this is fine.

} else if (name == HttpStatusCode) {
http_response_annotations_.emplace(SpanStatus, value);
uint64_t status_code;
std::cout << "belldav" << value << std::endl;
Copy link
Contributor

Choose a reason for hiding this comment

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

remove

Copy link
Contributor Author

Choose a reason for hiding this comment

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

😬, removed.

Comment on lines 202 to 205
if (!absl::SimpleAtoi(value, &status_code)) {
ENVOY_LOG(warn, "{} must be a number, given: {}", HttpStatusCode, value);
return;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Rather than discard the entire trace, it's better just to skip the status if we can't parse it.

Also, Matt is likely to have you change this log verbosity to debug or trace.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

setTag only operates on a single key-value pair, so this won't fail the entire trace.

I could however see failing to parse falling back to registering a custom annotation with these values.

Copy link
Contributor

@marcomagdy marcomagdy Apr 21, 2020

Choose a reason for hiding this comment

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

You're right. I confused this with the code in finishSpan().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did drop the log level down to debug.

Comment on lines 208 to 213
uint64_t response_size;
if (!absl::SimpleAtoi(value, &response_size)) {
ENVOY_LOG(warn, "{} must be a number, given: {}", HttpResponseSize, value);
return;
}
http_response_annotations_.emplace(SpanContentLength, ValueUtil::numberValue(response_size));
Copy link
Contributor

@marcomagdy marcomagdy Apr 21, 2020

Choose a reason for hiding this comment

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

same as above. change log verbosity, and skip just the value.

Comment on lines 83 to 85
daemon::Segment_http_annotations* http = s.mutable_http();

ProtobufWkt::Struct* request = http->mutable_request();
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd change those two lines to:

ProtobufWkt::Struct* request = s.http()->mutable_request();

The http is not used anywhere else.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

makes sense. this was left over from my misunderstanding that constructing submessages and assigning isn't the right way to go in c++.

Comment on lines 440 to 446
/**
* Wrap double into ProtobufWkt::Value string value.
* @param d double to be wrapped.
* @return wrapped double.
*/
static ProtobufWkt::Value numberValue(const double str);

Copy link
Contributor

Choose a reason for hiding this comment

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

There's already a numberValue(..) utility function on line 459.
You can remove this function and its definition.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed.

David Bell added 3 commits April 21, 2020 19:13
Signed-off-by: David Bell <belldav@amazon.com>
This reverts commit ecd5844.

Signed-off-by: David Bell <belldav@amazon.com>
Signed-off-by: David Bell <belldav@amazon.com>
Signed-off-by: David Bell <belldav@amazon.com>
Copy link
Contributor

@marcomagdy marcomagdy left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks.

@mattklein123 I have a separate PR for improving the test coverage here #10890

Copy link
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

Thanks!

@mattklein123 mattklein123 merged commit ad31f1c into envoyproxy:master Apr 22, 2020
penguingao pushed a commit to penguingao/envoy that referenced this pull request Apr 22, 2020
Risk Level: Low
Testing: unit tests, manual
Docs Changes: N/A
Release Notes: N/A
Fixes: envoyproxy#10814

Signed-off-by: pengg <pengg@google.com>
spenceral added a commit to spenceral/envoy that referenced this pull request Apr 23, 2020
Signed-off-by: Spencer Lewis <slewis@squareup.com>
* master: (46 commits)
  allow specifying the API version of bootstrap from the command line (envoyproxy#10803)
  config: adding connect matcher (unused) (envoyproxy#10894)
  Add missing dependency on `assert.h` (envoyproxy#10918)
  Lower heap and disk space used by kafka tests (envoyproxy#10915)
  [tools] handle commits merged without PR in deprecated script (envoyproxy#10723)
  tools: including working tree in modified_since_last_github_commit.sh diff. (envoyproxy#10911)
  rocketmq_proxy: implement rocketmq proxy
  [docs] PR template to include commit message (envoyproxy#10900)
  docs: breaking long word to stop content overflow. (envoyproxy#10880)
  Delete legacy connection pool code. (envoyproxy#10881)
  wasm: clarify how configuration is passed (envoyproxy#10782)
  issue template: clarify security/crash reporting (envoyproxy#10885)
  api/faq: add entry on incremental xDS. (envoyproxy#10876)
  router: retry overloaded requests (envoyproxy#10847)
  Remove inclusion of pthread.h, not needed for linux compilation (envoyproxy#10895)
  request_id: Add option to always set request id in response (envoyproxy#10808)
  xray: Use correct types for segment document output (envoyproxy#10834)
  router: fixing a watermark bug for streaming retries (envoyproxy#10866)
  http: auditing Path() calls for safety with Pathless CONNECT (envoyproxy#10851)
  Remove hardcoded type urls Part.2 (envoyproxy#10848)
  ...
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.

X-Ray tracing plugin doesn't publish conformant segment document
3 participants