|
38 | 38 | import static org.hypertrace.core.span.constants.v1.OTSpanTag.OT_SPAN_TAG_HTTP_URL; |
39 | 39 | import static org.hypertrace.core.spannormalizer.utils.TestUtils.createKeyValue; |
40 | 40 | import static org.junit.jupiter.api.Assertions.assertEquals; |
| 41 | +import static org.junit.jupiter.api.Assertions.assertFalse; |
| 42 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
41 | 43 |
|
42 | 44 | import com.google.common.collect.Maps; |
43 | 45 | import io.jaegertracing.api_v2.JaegerSpanInternalModel; |
|
46 | 48 | import java.util.HashMap; |
47 | 49 | import java.util.List; |
48 | 50 | import java.util.Map; |
| 51 | +import java.util.Optional; |
49 | 52 | import org.hypertrace.core.datamodel.AttributeValue; |
50 | 53 | import org.hypertrace.core.datamodel.Event; |
51 | 54 | import org.hypertrace.core.datamodel.eventfields.http.Http; |
| 55 | +import org.hypertrace.core.datamodel.eventfields.http.Request; |
| 56 | +import org.hypertrace.core.semantic.convention.constants.span.OTelSpanSemanticConventions; |
52 | 57 | import org.hypertrace.core.span.constants.RawSpanConstants; |
53 | 58 | import org.hypertrace.core.semantic.convention.constants.http.OTelHttpSemanticConventions; |
54 | 59 | import org.junit.jupiter.api.Assertions; |
@@ -836,7 +841,6 @@ public void testPopulateOtherFieldsOTelSpan() { |
836 | 841 | eventBuilder = Event.newBuilder(); |
837 | 842 | eventBuilder.getHttpBuilder().getRequestBuilder().setUrl("/apis/5673/events?a1=v1&a2=v2"); |
838 | 843 | map = Maps.newHashMap(); |
839 | | - map.put(OTelHttpSemanticConventions.HTTP_URL.getValue(), buildAttributeValue(url)); |
840 | 844 | httpFieldsGenerator.populateOtherFields(eventBuilder, map); |
841 | 845 |
|
842 | 846 | Assertions.assertNull(eventBuilder.getHttpBuilder().getRequestBuilder().getUrl()); |
@@ -876,6 +880,41 @@ public void testPopulateOtherFieldsOTelSpan() { |
876 | 880 | "/some-test-path", eventBuilder.getHttpBuilder().getRequestBuilder().getPath()); |
877 | 881 | assertEquals( |
878 | 882 | "some-query-str=v1", eventBuilder.getHttpBuilder().getRequestBuilder().getQueryString()); |
| 883 | + |
| 884 | + // originally set url is a relative url, should be overridden |
| 885 | + eventBuilder = Event.newBuilder(); |
| 886 | + eventBuilder.getHttpBuilder().getRequestBuilder().setUrl("/api/v1/gatekeeper/check?url=%2Fpixel%2Factivities%3Fadvertisable%3DTRHRT&method=GET&service=pixel"); |
| 887 | + map = Maps.newHashMap(); |
| 888 | + map.put(OTelHttpSemanticConventions.HTTP_SCHEME.getValue(), buildAttributeValue("http")); |
| 889 | + map.put(OTelSpanSemanticConventions.SPAN_KIND.getValue(), buildAttributeValue("server")); |
| 890 | + map.put(OTelHttpSemanticConventions.HTTP_NET_HOST_NAME.getValue(), buildAttributeValue("example.internal.com")); |
| 891 | + map.put(OTelHttpSemanticConventions.HTTP_NET_HOST_PORT.getValue(), buildAttributeValue("50850")); |
| 892 | + map.put(OTelHttpSemanticConventions.HTTP_TARGET.getValue(), buildAttributeValue("/api/v1/gatekeeper/check?url=%2Fpixel%2Factivities%3Fadvertisable%3DTRHRT&method=GET&service=pixel")); |
| 893 | + httpFieldsGenerator.populateOtherFields(eventBuilder, map); |
| 894 | + assertEquals("http://example.internal.com:50850/api/v1/gatekeeper/check?url=%2Fpixel%2Factivities%3Fadvertisable%3DTRHRT&method=GET&service=pixel", eventBuilder.getHttpBuilder().getRequestBuilder().getUrl()); |
| 895 | + } |
| 896 | + |
| 897 | + @Test |
| 898 | + public void testIsAbsoluteUrl() { |
| 899 | + assertTrue(HttpFieldsGenerator.isAbsoluteUrl("http://example.com/abc/xyz")); |
| 900 | + assertFalse(HttpFieldsGenerator.isAbsoluteUrl("/abc/xyz")); |
| 901 | + } |
| 902 | + |
| 903 | + @Test |
| 904 | + public void testGetPathFromUrl() { |
| 905 | + Optional<String> path = HttpFieldsGenerator.getPathFromUrlObject( |
| 906 | + "/api/v1/gatekeeper/check?url=%2Fpixel%2Factivities%3Fadvertisable%3DTRHRT&method=GET&service=pixel"); |
| 907 | + assertEquals(path.get(), "/api/v1/gatekeeper/check"); |
| 908 | + } |
| 909 | + |
| 910 | + @Test |
| 911 | + public void testSetPath() { |
| 912 | + Map<String, JaegerSpanInternalModel.KeyValue> tagsMap = new HashMap<>(); |
| 913 | + tagsMap.put(OTelHttpSemanticConventions.HTTP_TARGET.getValue(), |
| 914 | + createKeyValue("/api/v1/gatekeeper/check?url=%2Fpixel%2Factivities%3Fadvertisable%3DTRHRT&method=GET&service=pixel")); |
| 915 | + Http.Builder builder = Http.newBuilder().setRequestBuilder(Request.newBuilder()); |
| 916 | + HttpFieldsGenerator.setPath(builder, tagsMap); |
| 917 | + assertEquals(builder.getRequestBuilder().getPath(), "/api/v1/gatekeeper/check"); |
879 | 918 | } |
880 | 919 |
|
881 | 920 | private static AttributeValue buildAttributeValue(String value) { |
|
0 commit comments