-
Notifications
You must be signed in to change notification settings - Fork 16
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
Conversation
Codecov Report
@@ 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
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
This comment has been minimized.
This comment has been minimized.
Optional<String> grpcAuthority = RpcSemanticConventionUtils.getGrpcAuthority(event); | ||
if (grpcAuthority.isPresent()) { | ||
return getSanitizedHostValue(grpcAuthority.get()); | ||
} else { | ||
return getGrpcRequestMetadataHost(event); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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())
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
resolved
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
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) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
resolved
There was a problem hiding this comment.
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());
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@sarthak77 Can you add PR description and message? |
return Optional.empty(); | ||
} | ||
|
||
if (attributeValueMap.get(RPC_REQUEST_METADATA_HOST.getValue()) != null) { |
There was a problem hiding this comment.
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();
There was a problem hiding this comment.
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());
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
resolved
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@Test | ||
public void testEnrichEventWithGrpcNoAuthorityButRequestMetadataHost() { | ||
mockProtocol(innerEntrySpan, Protocol.PROTOCOL_GRPC); | ||
org.hypertrace.core.datamodel.eventfields.grpc.Grpc grpc = |
There was a problem hiding this comment.
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");
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
resolved
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.