Skip to content

tap: add HTTP request/response body tapping#5823

Merged
mattklein123 merged 11 commits intomasterfrom
tap_http_body
Feb 11, 2019
Merged

tap: add HTTP request/response body tapping#5823
mattklein123 merged 11 commits intomasterfrom
tap_http_body

Conversation

@mattklein123
Copy link
Copy Markdown
Member

  1. Add request/response body tapping
  2. Add buffered body limits (TBI for transport socket)
  3. Add the JSON_BODY_AS_BYTES and JSON_BODY_AS_STRING output
    formats for convenience when the body is known to be human
    readable.
  4. Add JSON output for the file per tap sink.

Risk Level: Low
Testing: New tests
Docs Changes: Added
Release Notes: N/A

1) Add request/response body tapping
2) Add buffered body limits (TBI for transport socket)
3) Add the JSON_BODY_AS_BYTES and JSON_BODY_AS_STRING output
   formats for convenience when the body is known to be human
   readable.
4) Add JSON output for the file per tap sink.

Signed-off-by: Matt Klein <mklein@lyft.com>
Signed-off-by: Matt Klein <mklein@lyft.com>
Signed-off-by: Matt Klein <mklein@lyft.com>
Signed-off-by: Matt Klein <mklein@lyft.com>
@htuch
Copy link
Copy Markdown
Member

htuch commented Feb 4, 2019

Please merge master to pick up #5827.

Signed-off-by: Matt Klein <mklein@lyft.com>
Signed-off-by: Matt Klein <mklein@lyft.com>
Signed-off-by: Matt Klein <mklein@lyft.com>
Copy link
Copy Markdown
Member

@htuch htuch left a comment

Choose a reason for hiding this comment

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

LGTM, minor comments.

Comment thread source/extensions/common/tap/tap_config_base.cc Outdated
Comment thread source/extensions/common/tap/tap_config_base.h Outdated
Comment thread source/extensions/filters/http/tap/tap_config_impl.h
repeated OutputSink sinks = 1 [(validate.rules).repeated = {min_items: 1, max_items: 1}];

// [#comment:TODO(mattklein123): Output filtering. E.g., certain headers, truncated body, etc.]
// For buffered tapping, the maximum amount of received body that will be buffered prior to
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.

There will be some stream/buffered selection later I assume?

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.

Yes, I'm going to start working on streaming once I get the basics in place.I still think that we always want to have buffering capabilities, mainly because it's easier for the end user to work with / look at in certain cases.


void Utility::addBufferToProtoBytes(envoy::data::tap::v2alpha::Body& output_bytes,
uint32_t max_buffered_bytes, const Buffer::Instance& data) {
const uint64_t num_slices = data.getRawSlices(nullptr, 0);
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.

use copyOut?

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.

Oh nice. Thanks. Forgot we had this. This will save me a bunch of time in my next PR.

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 was just looking at this, and I think if I do copyOut I'm going to need a third copy. I can move an std::string into the protobuf string, but I can't reserve() an std::string, copy data into it, and then set its size. Right? Is there any way to do this without another copy that I'm missing?

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.

You can do resize() the string and copyOut into &str[0].

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.

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.

This is still slower since resize() will initialize the string data up to the length.

Agree, so I think we can make copyOut take a std::string&, as we see this pattern being used in a couple other places.

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.

That still wouldn't help unless we reimplement copyout() manually outside of the libevent API. cc @brian-pane for the new buffer implementation. I think for now I will just use copyOut() and leave a TODO for perf cleanup later.

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.

Yeah that's what I meant, in other words, toString with start and size.

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.

Yup agreed, will add a TODO and fix in a follow up.

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 just looked at this again and I realized that since I'm appending to the proto string across calls, this will require an extra copy no matter what we do to the buffer API, so I think I'm just going to leave it as is. I will think about what to do in my next change since this is going to get more complicated. I will add a TODO along these lines.

@htuch htuch added the waiting label Feb 8, 2019
Signed-off-by: Matt Klein <mklein@lyft.com>
Signed-off-by: Matt Klein <mklein@lyft.com>
Copy link
Copy Markdown
Member

@htuch htuch 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 9a06dc0 into master Feb 11, 2019
@mattklein123 mattklein123 deleted the tap_http_body branch February 11, 2019 02:20
fredlas pushed a commit to fredlas/envoy that referenced this pull request Mar 5, 2019
1) Add request/response body tapping
2) Add buffered body limits (TBI for transport socket)
3) Add the JSON_BODY_AS_BYTES and JSON_BODY_AS_STRING output
   formats for convenience when the body is known to be human
   readable.
4) Add JSON output for the file per tap sink.

Signed-off-by: Matt Klein <mklein@lyft.com>
Signed-off-by: Fred Douglas <fredlas@google.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.

3 participants