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

fix : added fallback support for host headers #279

Merged
merged 7 commits into from
Nov 3, 2021
Merged

Conversation

sarthak77
Copy link
Member

@sarthak77 sarthak77 commented Nov 2, 2021

Earlier host header was being checked through grpc authority. So it was suggested to check metadata host if authority was not present as a fallback. Added support for this.

@codecov
Copy link

codecov bot commented Nov 2, 2021

Codecov Report

Merging #279 (ddf8d24) into main (82a7a19) will increase coverage by 0.01%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff              @@
##               main     #279      +/-   ##
============================================
+ Coverage     79.06%   79.07%   +0.01%     
- Complexity     1230     1231       +1     
============================================
  Files           110      110              
  Lines          4857     4861       +4     
  Branches        439      440       +1     
============================================
+ Hits           3840     3844       +4     
  Misses          813      813              
  Partials        204      204              
Flag Coverage Δ
unit 79.07% <100.00%> (+0.01%) ⬆️

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

Impacted Files Coverage Δ
...nt/enrichers/ApiBoundaryTypeAttributeEnricher.java 90.90% <100.00%> (+0.49%) ⬆️

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 82a7a19...ddf8d24. Read the comment docs.

@github-actions

This comment has been minimized.

Optional<String> grpcAuthority = RpcSemanticConventionUtils.getGrpcAuthority(event);
if (grpcAuthority.isPresent()) {
return getSanitizedHostValue(grpcAuthority.get());
} else {
return getGrpcRequestMetadataHost(event);
Copy link
Contributor

Choose a reason for hiding this comment

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

Look for the method - getGrpcXForwardedFor, this method should be similar to that. It should internally check that isRpcSystemGrpc, if yes, it should check for the rpc.request.metadata.host attribute.

Copy link
Contributor

Choose a reason for hiding this comment

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

Second, we also have to sanitize the host value read from other attributes - getSanitizedHostValue (getGrpcRequestMetadataHost())

Copy link
Member Author

Choose a reason for hiding this comment

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

resolved

@github-actions

This comment has been minimized.

@sarthak77 sarthak77 marked this pull request as ready for review November 2, 2021 08:15
@sarthak77 sarthak77 requested a review from a team November 2, 2021 08:15
@github-actions

This comment has been minimized.

@@ -144,11 +144,18 @@ private void enrichHostHeader(Event event) {
}
}

private Optional<String> getGrpcAuthority(Event event) {
private Optional<String> getGrpcHostHeader(Event event) {
Copy link
Member Author

Choose a reason for hiding this comment

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

@kotharironak should I add test over here also?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, add a test with an event not having authority but required tags like rpc.sytem and rec.request.metadata.host, and hostHeader fall back to metadata.host value.

Copy link
Contributor

Choose a reason for hiding this comment

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

Refer the test file ApiBoundaryTypeAttributeEnricherTest, test cases testEnrichEventWithGrpcNoAuthority and similar.

Copy link
Member Author

Choose a reason for hiding this comment

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

resolved

Copy link
Contributor

Choose a reason for hiding this comment

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

There is a test testEnrichEventWithGrpcAuthority in the same file, can you also add the below attribute to it.

addAttributeToEvent(
        innerEntrySpan,
        RPC_REQUEST_METADATA_HOST.getValue(),
        AttributeValue.newBuilder().setValue("testHost2").build());

Copy link
Member 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

@sarthak77 Can you add PR description and message?

@sarthak77 sarthak77 changed the title ENG-12376 fix Bug fix for missing domain name in some traces Nov 2, 2021
@sarthak77 sarthak77 changed the title Bug fix for missing domain name in some traces nit : added support for error prone host headers Nov 2, 2021
return Optional.empty();
}

if (attributeValueMap.get(RPC_REQUEST_METADATA_HOST.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.

Let's move RPC_REQUEST_METATA_HOST.getValue() as static string var at top.

  private static final String RPC_REQUEST_METADATA_HOST_ATTR = RPC_REQUEST_METADATA_HOST.getValue();

Copy link
Contributor

Choose a reason for hiding this comment

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

Repace if block with as below to avoid multiple lookups in map.

return Optional.ofNullable(attributeValueMap.get(RPC_REQUEST_METADATA_HOST_ATTR))
        .map(v -> v.getValue());

Copy link
Member Author

Choose a reason for hiding this comment

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

resolved

@@ -165,6 +166,23 @@ public void testGetGrpcXForwardedFor() {
assertEquals("198.12.34.1", RpcSemanticConventionUtils.getGrpcXForwardedFor(event).get());
}

@Test
public void testGetGrpcRequestMetadataHost() {
Event event = mock(Event.class);
Copy link
Contributor

Choose a reason for hiding this comment

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

Also add one more test, if rpc system is not set to Grpc, the method returns to Optional.Empty()

Copy link
Member Author

Choose a reason for hiding this comment

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

resolved

@github-actions

This comment has been minimized.

@kotharironak kotharironak changed the title nit : added support for error prone host headers fix : added fallback support for host headers Nov 3, 2021
@github-actions

This comment has been minimized.

@Test
public void testEnrichEventWithGrpcNoAuthorityButRequestMetadataHost() {
mockProtocol(innerEntrySpan, Protocol.PROTOCOL_GRPC);
org.hypertrace.core.datamodel.eventfields.grpc.Grpc grpc =
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you remove lines from 307 to 315 that are not required?
Below code,

 org.hypertrace.core.datamodel.eventfields.grpc.Grpc grpc =
        mock(org.hypertrace.core.datamodel.eventfields.grpc.Grpc.class);
    when(innerEntrySpan.getGrpc()).thenReturn(grpc);
    Request request = mock(Request.class);
    when(grpc.getRequest()).thenReturn(request);
    RequestMetadata metadata = mock(RequestMetadata.class);
    when(request.getRequestMetadata()).thenReturn(metadata);
    when(metadata.getAuthority()).thenReturn("localhost:443");

Copy link
Member Author

Choose a reason for hiding this comment

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

resolved

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@sarthak77 sarthak77 merged commit 0b21b01 into main Nov 3, 2021
@sarthak77 sarthak77 deleted the ENG-12376-fix branch November 3, 2021 07:17
@github-actions
Copy link

github-actions bot commented Nov 3, 2021

Unit Test Results

  73 files  ±0    73 suites  ±0   1m 8s ⏱️ +2s
387 tests +1  387 ✔️ +1  0 💤 ±0  0 ❌ ±0 

Results for commit 0b21b01. ± Comparison against base commit 82a7a19.

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.

2 participants