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

context: add response.total_size #9839

Merged
merged 2 commits into from
Jan 28, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/root/intro/arch_overview/security/rbac_filter.rst
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ The following attributes are exposed to the language runtime:
response.headers, string map, All response headers
response.trailers, string map, All response trailers
response.size, int, Size of the response body
response.total_size, int, Total size of the response including the headers and the trailers
Copy link
Contributor

Choose a reason for hiding this comment

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

Unpacked or on the wire (i.e. does it account for HPACK/QPACK, chunked encoding, etc.)?

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 had the same question. I'm using bytes() property of the header map. I think it's reporting the compressed size, since the numbers don't seem to add up.

Copy link
Contributor

@PiotrSikora PiotrSikora Jan 27, 2020

Choose a reason for hiding this comment

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

Hmm, I thought that bytes() is used to make sure that uncompressed headers don't exceed the configured limit, so that shouldn't be the case.

@asraa you're the authority here, any ideas?

Copy link
Member

Choose a reason for hiding this comment

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

bytes() is approximate uncompressed size.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

FWIW existing code uses the same method to get the sizes: https://github.com/istio/proxy/blob/master/src/envoy/http/mixer/filter.cc#L61. So far noone complained that it's not precise.

Copy link
Member

Choose a reason for hiding this comment

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

This looks fine to me in general, so will defer to all of you if you want different doc text or you want to go with this.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would be helpful to clarify that this is "approximate uncompressed size of headers and trailers" and not the wire size.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, updated the doc.

response.flags, int, Additional details about the response beyond the standard response code
source.address, string, Downstream connection remote address
source.port, int, Downstream connection remote port
Expand Down
3 changes: 3 additions & 0 deletions source/extensions/filters/common/expr/context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ absl::optional<CelValue> ResponseWrapper::operator[](CelValue key) const {
return CelValue::CreateInt64(optional_status.value());
}
return {};
} else if (value == TotalSize) {
return CelValue::CreateInt64(info_.bytesSent() + headers_.value_->byteSize() +
trailers_.value_->byteSize());
}
return {};
}
Expand Down
7 changes: 7 additions & 0 deletions test/extensions/filters/common/expr/context_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,13 @@ TEST(Context, ResponseAttributes) {
EXPECT_EQ(123, value.value().Int64OrDie());
}

{
auto value = response[CelValue::CreateStringView(TotalSize)];
EXPECT_TRUE(value.has_value());
ASSERT_TRUE(value.value().IsInt64());
EXPECT_EQ(160, value.value().Int64OrDie());
}

{
auto value = response[CelValue::CreateStringView(Code)];
EXPECT_TRUE(value.has_value());
Expand Down