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

feat: add fallback support for request and response size #272

Merged
merged 11 commits into from
Oct 26, 2021

Conversation

kotharironak
Copy link
Contributor

@kotharironak kotharironak commented Oct 21, 2021

Description

Currently, there are following three attributes consider for calculating response size

  • response_size
  • http.response.size
  • http.response_content_length

As part of this PR, we will be adding fallback to calculate using the content of http.response.body if above are abset.

The same will be applied to request size calculation.

  • request_size
  • http.request.size
  • http.request_content_length

So, the fallback will be the size of http.request.body attribute

Testing

  • Have added unit tests

Checklist:

  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • Any dependent changes have been merged and published in downstream modules

@codecov
Copy link

codecov bot commented Oct 21, 2021

Codecov Report

Merging #272 (f8387fe) into main (896081c) will increase coverage by 0.24%.
The diff coverage is 94.04%.

Impacted file tree graph

@@             Coverage Diff              @@
##               main     #272      +/-   ##
============================================
+ Coverage     80.20%   80.45%   +0.24%     
- Complexity     1181     1209      +28     
============================================
  Files           106      106              
  Lines          4588     4662      +74     
  Branches        424      436      +12     
============================================
+ Hits           3680     3751      +71     
- Misses          709      710       +1     
- Partials        199      201       +2     
Flag Coverage Δ
unit 80.45% <94.04%> (+0.24%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...ormalizer/fieldgenerators/GrpcFieldsGenerator.java 96.96% <93.47%> (+0.12%) ⬆️
...ormalizer/fieldgenerators/HttpFieldsGenerator.java 93.92% <94.73%> (-0.02%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 896081c...f8387fe. Read the comment docs.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@kotharironak
Copy link
Contributor Author

Also added support for tags,

  • http.request.header.content-length
  • http.response.header.content-length

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

String requestBody = attributeValueMap.get(RPC_REQUEST_BODY.getValue()).getValue();
return Optional.of(requestBody.length());
}
if (attributeValueMap.get(RawSpanConstants.getValue(ENVOY_REQUEST_SIZE)) != null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: There are repetitive RawSpanContants.getValue() calls. Can these be extracted out as static variables.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

return Optional.empty();
}

private static boolean isGrpcResponseBodyTruncated(
Map<String, AttributeValue> attributeValueMap) {
if (attributeValueMap.get(RawSpanConstants.getValue(GRPC_RESPONSE_BODY_TRUNCATED)) != null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Extract attributeValueMap.get(RawSpanConstants.getValue(GRPC_RESPONSE_BODY_TRUNCATED) out and reuse below

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

}

private static boolean isRpcResponseBodyTruncated(Map<String, AttributeValue> attributeValueMap) {
if (attributeValueMap.get(RPC_RESPONSE_BODY_TRUNCATED.getValue()) != null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment as above

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@github-actions

This comment has been minimized.

if (!requestSize.isEmpty()) return requestSize.map(Integer::parseInt);

if (SpanAttributeUtils.getBooleanAttribute(
event, RawSpanConstants.getValue(HTTP_REQUEST_BODY_TRUNCATED))) {
Copy link
Contributor

Choose a reason for hiding this comment

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

RawSpanConstants.getValue(HTTP_REQUEST_BODY_TRUNCATED can move to static variable

if (!responseSize.isEmpty()) return responseSize.map(Integer::parseInt);

if (SpanAttributeUtils.getBooleanAttribute(
event, RawSpanConstants.getValue(HTTP_RESPONSE_BODY_TRUNCATED))) {
Copy link
Contributor

Choose a reason for hiding this comment

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

move to static variable

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -269,55 +297,92 @@ public static String getGrpcErrorMsg(Event event) {
return Optional.empty();
}

private static boolean isGrpcRequestBodyTruncated(Map<String, AttributeValue> attributeValueMap) {
if (attributeValueMap.get(GRPC_REQUEST_BODY_TRUNCATED_ATTR) != null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

If the GRPC_REQUEST_BODY_TRUNCATED_ATTR attribute is present in the map, then you end up getting it twice - once for the null check and then for the Boolean parsing below. Please fix.

Copy link
Contributor Author

@kotharironak kotharironak Oct 26, 2021

Choose a reason for hiding this comment

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

Most parts of the file were written in a similar manner so had followed the pattern. But, given this is a part of the ingestion pipeline, a small constant time boost compare to stack push/pop operation vs calc hashing twice would be helpful with respect to traffic. Changing this code, and created an issue for going over all the utilities for the same.
Issue for this : hypertrace/hypertrace#316

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

}

private static boolean isRpcRequestBodyTruncated(Map<String, AttributeValue> attributeValueMap) {
if (attributeValueMap.get(RPC_REQUEST_BODY_TRUNCATED_ATTR) != null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

same as above

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

String requestBody = attributeValueMap.get(RPC_REQUEST_BODY.getValue()).getValue();
return Optional.of(requestBody.length());
}
if (attributeValueMap.get(ENVOY_REQUEST_SIZE_ATTR) != null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

optimize the multiple get from the map here too

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

if (attributeValueMap.get(ENVOY_REQUEST_SIZE_ATTR) != null) {
return Optional.of(
Integer.parseInt(attributeValueMap.get(ENVOY_REQUEST_SIZE_ATTR).getValue()));
} else if (isRpcSystemGrpc(attributeValueMap)
Copy link
Contributor

Choose a reason for hiding this comment

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

optimize the multiple get from the map here too

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

return Optional.of(
Integer.parseInt(
attributeValueMap.get(RPC_REQUEST_METADATA_CONTENT_LENGTH_ATTR).getValue()));
} else if (attributeValueMap.get(GRPC_REQUEST_BODY_ATTR) != null
Copy link
Contributor

Choose a reason for hiding this comment

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

optimize the multiple get from the map here too

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

String requestBody = attributeValueMap.get(GRPC_REQUEST_BODY_ATTR).getValue();
return Optional.of(requestBody.length());
} else if (isRpcSystemGrpc(attributeValueMap)
&& attributeValueMap.get(RPC_REQUEST_BODY_ATTR) != null
Copy link
Contributor

Choose a reason for hiding this comment

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

optimize the multiple get from the map here too

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

return Optional.empty();
}

private static boolean isGrpcResponseBodyTruncated(
Map<String, AttributeValue> attributeValueMap) {
if (attributeValueMap.get(GRPC_RESPONSE_BODY_TRUNCATED_ATTR) != null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

optimize the multiple get from the map here too

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

}

private static boolean isRpcResponseBodyTruncated(Map<String, AttributeValue> attributeValueMap) {
if (attributeValueMap.get(RPC_RESPONSE_BODY_TRUNCATED_ATTR) != null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

optimize the multiple get from the map here too

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@kotharironak
Copy link
Contributor Author

@avinashkolluru Created the issue of multiple read from the map here for handling throughout file - #272 (comment), have the address for them for the exiting PR.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

Copy link
Contributor

@findingrish findingrish left a comment

Choose a reason for hiding this comment

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

LGTM

@kotharironak kotharironak merged commit 7147fec into main Oct 26, 2021
@kotharironak kotharironak deleted the fallback-for-req-response-size branch October 26, 2021 10:27
@github-actions
Copy link

Unit Test Results

  71 files  ±0    71 suites  ±0   1m 18s ⏱️ +9s
383 tests +2  383 ✔️ +2  0 💤 ±0  0 ❌ ±0 

Results for commit 7147fec. ± Comparison against base commit 896081c.

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.

4 participants