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

decompressor library: add stats to zlib library #11782

Merged
merged 23 commits into from
Jul 12, 2020
Merged

decompressor library: add stats to zlib library #11782

merged 23 commits into from
Jul 12, 2020

Conversation

junr03
Copy link
Member

@junr03 junr03 commented Jun 27, 2020

Commit Message: adding decompressor error stats to the zlib decompressor library.
Additional Description: lots of boilerplate, but will make it easier to continue to add stats in the future. Additionally, the compressor library can use the same pattern.
Risk Level: low
Testing: updated tests
Docs Changes: added documentation.

Signed-off-by: Jose Nino [email protected]

Jose Nino added 7 commits June 24, 2020 10:59
wip
Signed-off-by: Jose Nino <[email protected]>
Signed-off-by: Jose Nino <[email protected]>
Signed-off-by: Jose Nino <[email protected]>
fmt
Signed-off-by: Jose Nino <[email protected]>
Signed-off-by: Jose Nino <[email protected]>
fmt
Signed-off-by: Jose Nino <[email protected]>
@junr03 junr03 requested a review from dio as a code owner June 27, 2020 00:20
@junr03 junr03 requested a review from rojkov June 27, 2020 00:20
@junr03
Copy link
Member Author

junr03 commented Jun 27, 2020

@rojkov we saw some decompression errors, and felt that it warranted adding stats here. Let me know what you think!

@junr03 junr03 changed the title Decompressor stats decompressor library: add stats to zlib library Jun 27, 2020
fix
Signed-off-by: Jose Nino <[email protected]>
Copy link
Member

@rojkov rojkov 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! That's a good addition. I might need a similar patch for the compressor part.

@@ -94,7 +94,7 @@ class DecompressorFilterConfig {
Compression::Decompressor::DecompressorFactoryPtr decompressor_factory);

Compression::Decompressor::DecompressorPtr makeDecompressor() {
return decompressor_factory_->createDecompressor();
return decompressor_factory_->createDecompressor(stats_prefix_ + "decompressor_library");
Copy link
Member

Choose a reason for hiding this comment

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

Can we make this stat prefix be a part of decompressor_factory_'s state? So that this string concatenation would happen only once at Envoy's start rather than for every stream creation.

Copy link
Member Author

Choose a reason for hiding this comment

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

I debated this back and forth because I am not sure if we would have a place where we would want each decompressor created by the same factory to have different strings.

Copy link
Member Author

Choose a reason for hiding this comment

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

lets just do it the way you suggest. Having the string concatenation in the hot path seems like a bad price to pay for the niche ability to configure stats trees differently for individual decompressors.

Copy link
Member Author

Choose a reason for hiding this comment

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

nvm all of the above. I now do understand what you mean. Let me know if what I have pushed is not it.

Copy link
Member

Choose a reason for hiding this comment

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

That's definitely better. Though I was thinking about changing the meaning of DecompressorFactory::statsPrefix(). Instead of returning .gzip it could return the full root stats prefix since we create a factory per DecompressionFilterConfig anyway.

Then DecompressorFilterConfig::stats_prefix_ wouldn't be needed and DecompressorFactory::createDecompressor() would retain its current signature.

Copy link
Member Author

Choose a reason for hiding this comment

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

I didn’t want to do that because I don’t want the filter stats to have the decompressor_library prefix. To me the public statsPrefix function is for a consumer to use. And the argument in createDeconoressor is what the consumer wants to ultimately root the decompressor at.

Copy link
Member

Choose a reason for hiding this comment

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

Alright, fair enough.

"zlib decompression error: {}, msg: {}. Error codes are defined in "
"https://www.zlib.net/manual.html",
result, zstream_ptr_->msg);
stats_.decompression_error_.inc();
Copy link
Member

Choose a reason for hiding this comment

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

Is it enough for your use case not to differentiate errors by their type?

I'm thinking that it might be useful to check the stats and see what's wrong immediately (e.g. is it Z_DATA_ERROR or Z_MEM_ERROR?) instead of increasing log verbosity to trace.

Copy link
Member Author

Choose a reason for hiding this comment

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

The issue is that even a Z_DATA_ERROR can have dozens of different reasons for occurring, so you would still need to look at logs to get at the heart of it. However, I do think your idea of differentiating based on returned error code is good. I'll make the change.

Jose Nino added 2 commits June 29, 2020 10:56
Signed-off-by: Jose Nino <[email protected]>
Signed-off-by: Jose Nino <[email protected]>
@junr03
Copy link
Member Author

junr03 commented Jun 29, 2020

@rojkov updated! I am going to be taking time off the rest of this week, but @rebello95 will take a look at this PR after you give it another look and proceed accordingly.

Jose Nino added 7 commits June 29, 2020 16:41
Signed-off-by: Jose Nino <[email protected]>
fmt
Signed-off-by: Jose Nino <[email protected]>
Signed-off-by: Jose Nino <[email protected]>
Signed-off-by: Jose Nino <[email protected]>
Signed-off-by: Jose Nino <[email protected]>
Copy link
Member

@rojkov rojkov left a comment

Choose a reason for hiding this comment

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

Looks good! Just a couple of questions.

@@ -153,4 +155,107 @@ TEST_P(DecompressorIntegrationTest, BidirectionalDecompression) {
uncompressed_response_length);
}

/**
* Exercises gzip decompression bidirectionally with default configuration.
Copy link
Member

Choose a reason for hiding this comment

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

I'd replace "default configuration" with something like "configuration using wrong value for Zlib's windowBits".

Copy link
Member Author

Choose a reason for hiding this comment

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

bad copy paste, sorry!

ASSERT_TRUE(upstream_request_->waitForEndStream(*dispatcher_));

EXPECT_TRUE(upstream_request_->complete());
TestUtility::headerMapEqualIgnoreOrder(
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't we set expectations for these equality checks? Looks like the return value of the check is simply ignored.

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah, they were bad before. Thanks for noticing, updated!

Jose Nino added 2 commits July 6, 2020 12:03
Signed-off-by: Jose Nino <[email protected]>
@junr03
Copy link
Member Author

junr03 commented Jul 7, 2020

@rojkov updated!

Copy link
Member

@rojkov rojkov left a comment

Choose a reason for hiding this comment

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

Probably one comment line needs polishing, but the rest looks good to me.

@@ -49,7 +69,19 @@ class ZlibDecompressorImpl : public Zlib::Base,
int decompression_error_{0};

private:
// TODO: clean up friend class. This is here to allow coverage of chargeErrorStats as it isn't
Copy link
Member

Choose a reason for hiding this comment

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

Nit: you may want to have TODO(junr03) in this line.

Copy link
Member Author

Choose a reason for hiding this comment

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

I like leaving todos I don't intend to do right away without a username that way it doesn't dissuade others to fix todos they find.

Signed-off-by: Jose Nino <[email protected]>
@junr03
Copy link
Member Author

junr03 commented Jul 7, 2020

@dio this is ready for a final pass, do you mind taking it?

dio
dio previously approved these changes Jul 10, 2020
Copy link
Member

@dio dio 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! This is good! Sorry for the late reply!

Http::TestRequestHeaderMapImpl headers_before_filter{
{"cache-control", fmt::format("{}, {}", Http::CustomHeaders::get().CacheControlValues.NoCache,
Http::CustomHeaders::get().CacheControlValues.NoTransform)},
{"content-encoding", "mock"},
{"content-length", "256"}};
std::unique_ptr<Http::RequestOrResponseHeaderMap> headers_after_filter =
doHeaders(headers_before_filter, false /* end_stream */);
TestUtility::headerMapEqualIgnoreOrder(headers_before_filter, *headers_after_filter);
Copy link
Member

Choose a reason for hiding this comment

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

Just curious. So here, we don't expect headers_before_filter to be the same as *headers_after_filter since there is no EXPECT_THAT() replacement here.

Jose Nino added 2 commits July 11, 2020 16:14
Signed-off-by: Jose Nino <[email protected]>
Signed-off-by: Jose Nino <[email protected]>
Copy link
Member

@dio dio 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!

@dio dio merged commit 84affaa into envoyproxy:master Jul 12, 2020
goaway added a commit to envoyproxy/envoy-mobile that referenced this pull request Jul 15, 2020
Description: Pulls in multiple fixes committed to upstream Envoy.

- Update for resolution to TLSContext crash: envoyproxy/envoy#10030
- Fixes for 32 bit archs: envoyproxy/envoy#11726
- Fix for missing posix call on Android: envoyproxy/envoy#12081
- Additional zlib stats: envoyproxy/envoy#11782

Signed-off-by: Mike Schore <[email protected]>
scheler pushed a commit to scheler/envoy that referenced this pull request Aug 4, 2020
This adds decompressor error stats to the zlib decompressor library. This introduces a lot of boilerplate but will make it easier to continue to add stats in the future. Additionally, the compressor library can use the same pattern.

Risk Level: Low.
Testing: Updated.
Docs Changes: Added.

Signed-off-by: Jose Nino <[email protected]>
Signed-off-by: scheler <[email protected]>
jpsim pushed a commit that referenced this pull request Nov 28, 2022
Description: Pulls in multiple fixes committed to upstream Envoy.

- Update for resolution to TLSContext crash: #10030
- Fixes for 32 bit archs: #11726
- Fix for missing posix call on Android: #12081
- Additional zlib stats: #11782

Signed-off-by: Mike Schore <[email protected]>
Signed-off-by: JP Simard <[email protected]>
jpsim pushed a commit that referenced this pull request Nov 29, 2022
Description: Pulls in multiple fixes committed to upstream Envoy.

- Update for resolution to TLSContext crash: #10030
- Fixes for 32 bit archs: #11726
- Fix for missing posix call on Android: #12081
- Additional zlib stats: #11782

Signed-off-by: Mike Schore <[email protected]>
Signed-off-by: JP Simard <[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