Search in sources :

Example 56 with AttributeValue

use of org.hypertrace.core.datamodel.AttributeValue in project hypertrace-ingester by hypertrace.

the class HttpAttributeEnricherTest method testDecodeQueryParams.

@Test
public void testDecodeQueryParams() {
    String query_string = "action=check%20out&location=hello%3Dworld";
    Event e = createMockEvent();
    addAttribute(e, RawSpanConstants.getValue(HTTP_PATH), "/users");
    addAttribute(e, RawSpanConstants.getValue(HTTP_REQUEST_QUERY_STRING), query_string);
    enricher.enrichEvent(mockTrace, e);
    AttributeValue actionParam = SpanAttributeUtils.getAttributeValue(e, Constants.getEnrichedSpanConstant(HTTP_REQUEST_QUERY_PARAM) + ".action");
    assertEquals("check out", actionParam.getValue());
    assertEquals(List.of("check out"), actionParam.getValueList());
    AttributeValue locationParam = SpanAttributeUtils.getAttributeValue(e, Constants.getEnrichedSpanConstant(HTTP_REQUEST_QUERY_PARAM) + ".location");
    assertEquals("hello=world", locationParam.getValue());
    assertEquals(List.of("hello=world"), locationParam.getValueList());
}
Also used : AttributeValue(org.hypertrace.core.datamodel.AttributeValue) Event(org.hypertrace.core.datamodel.Event) Test(org.junit.jupiter.api.Test)

Example 57 with AttributeValue

use of org.hypertrace.core.datamodel.AttributeValue in project hypertrace-ingester by hypertrace.

the class HttpAttributeEnricherTest method testMultipleValuedQueryParam.

@Test
public void testMultipleValuedQueryParam() {
    String query_string = "action=checkout&action=a&age=2&age=3&location=";
    Event e = createMockEvent();
    addAttribute(e, RawSpanConstants.getValue(HTTP_PATH), "/users");
    addAttribute(e, RawSpanConstants.getValue(HTTP_REQUEST_QUERY_STRING), query_string);
    enricher.enrichEvent(mockTrace, e);
    String httpPathEnrichedValue = SpanAttributeUtils.getStringAttribute(e, Constants.getEnrichedSpanConstant(HTTP_REQUEST_PATH));
    assertEquals("/users", httpPathEnrichedValue);
    AttributeValue actionParam = SpanAttributeUtils.getAttributeValue(e, Constants.getEnrichedSpanConstant(HTTP_REQUEST_QUERY_PARAM) + ".action");
    assertEquals("checkout", actionParam.getValue());
    assertEquals(List.of("checkout", "a"), actionParam.getValueList());
    AttributeValue ageParam = SpanAttributeUtils.getAttributeValue(e, Constants.getEnrichedSpanConstant(HTTP_REQUEST_QUERY_PARAM) + ".age");
    assertEquals("2", ageParam.getValue());
    assertEquals(List.of("2", "3"), ageParam.getValueList());
    AttributeValue locationParam = SpanAttributeUtils.getAttributeValue(e, Constants.getEnrichedSpanConstant(HTTP_REQUEST_QUERY_PARAM) + ".location");
    assertNull(locationParam);
}
Also used : AttributeValue(org.hypertrace.core.datamodel.AttributeValue) Event(org.hypertrace.core.datamodel.Event) Test(org.junit.jupiter.api.Test)

Example 58 with AttributeValue

use of org.hypertrace.core.datamodel.AttributeValue in project hypertrace-ingester by hypertrace.

the class HttpAttributeEnricherTest method testDecodeQueryParamsWithSquareBrackets.

@Test
public void testDecodeQueryParamsWithSquareBrackets() {
    // Url with query params not encoded
    String query_string = "action[]=checkout&age=2&[]=test";
    Event e = createMockEvent();
    addAttribute(e, RawSpanConstants.getValue(HTTP_PATH), "/users");
    addAttribute(e, RawSpanConstants.getValue(HTTP_REQUEST_QUERY_STRING), query_string);
    enricher.enrichEvent(mockTrace, e);
    AttributeValue actionParam = SpanAttributeUtils.getAttributeValue(e, Constants.getEnrichedSpanConstant(HTTP_REQUEST_QUERY_PARAM) + ".action");
    assertEquals("checkout", actionParam.getValue());
    assertEquals(List.of("checkout"), actionParam.getValueList());
    AttributeValue ageParam = SpanAttributeUtils.getAttributeValue(e, Constants.getEnrichedSpanConstant(HTTP_REQUEST_QUERY_PARAM) + ".age");
    assertEquals("2", ageParam.getValue());
    assertEquals(List.of("2"), ageParam.getValueList());
    // If seen only bracket, treat the square braces as param key
    AttributeValue onlySquareBracketParam = SpanAttributeUtils.getAttributeValue(e, Constants.getEnrichedSpanConstant(HTTP_REQUEST_QUERY_PARAM) + ".[]");
    assertEquals("test", onlySquareBracketParam.getValue());
    assertEquals(List.of("test"), onlySquareBracketParam.getValueList());
    // Create event with URL encoded query params
    query_string = "action%5B%5D%3Dcheckout%26age%3D2%26%5B%5D%3Dtest";
    e = createMockEvent();
    addAttribute(e, RawSpanConstants.getValue(HTTP_PATH), "/users");
    addAttribute(e, RawSpanConstants.getValue(HTTP_REQUEST_QUERY_STRING), query_string);
    enricher.enrichEvent(mockTrace, e);
    assertEquals("checkout", actionParam.getValue());
    assertEquals(List.of("checkout"), actionParam.getValueList());
    assertEquals("2", ageParam.getValue());
    assertEquals(List.of("2"), ageParam.getValueList());
    assertEquals("test", onlySquareBracketParam.getValue());
    assertEquals(List.of("test"), onlySquareBracketParam.getValueList());
}
Also used : AttributeValue(org.hypertrace.core.datamodel.AttributeValue) Event(org.hypertrace.core.datamodel.Event) Test(org.junit.jupiter.api.Test)

Example 59 with AttributeValue

use of org.hypertrace.core.datamodel.AttributeValue in project hypertrace-ingester by hypertrace.

the class SpanTypeAttributeEnricherTest method test_getProtocolName_httpAttributes_shouldReturnHttp.

@Test
public void test_getProtocolName_httpAttributes_shouldReturnHttp() {
    Map<String, AttributeValue> map = new HashMap<>();
    map.put(Constants.getRawSpanConstant(Http.HTTP_REQUEST_URL), AttributeValue.newBuilder().setValue("http://hypertrace.org").build());
    map.put(Constants.getRawSpanConstant(Http.HTTP_REQUEST_METHOD), AttributeValue.newBuilder().setValue("GET").build());
    Event e = createEvent(map, new HashMap<>());
    Assertions.assertEquals(Protocol.PROTOCOL_HTTP, SpanTypeAttributeEnricher.getProtocolName(e));
}
Also used : AttributeValue(org.hypertrace.core.datamodel.AttributeValue) HashMap(java.util.HashMap) Event(org.hypertrace.core.datamodel.Event) Test(org.junit.jupiter.api.Test)

Example 60 with AttributeValue

use of org.hypertrace.core.datamodel.AttributeValue in project hypertrace-ingester by hypertrace.

the class SpanTypeAttributeEnricherTest method envoySpanCategorization.

@Test
public void envoySpanCategorization() {
    SpanTypeAttributeEnricher enricher = new SpanTypeAttributeEnricher();
    // No operation name
    Event e = createMockEnvoyEvent(null);
    enricher.enrichEvent(null, e);
    Map<String, AttributeValue> enrichedAttributes = e.getEnrichedAttributes().getAttributeMap();
    Assertions.assertEquals(enrichedAttributes.get(Constants.getEnrichedSpanConstant(SPAN_TYPE)).getValue(), Constants.getEnrichedSpanConstant(UNKNOWN));
    // Ingress operation should be Entry span.
    e = createMockEnvoyEvent(Constants.getRawSpanConstant(Envoy.ENVOY_INGRESS_SPAN));
    enricher.enrichEvent(null, e);
    enrichedAttributes = e.getEnrichedAttributes().getAttributeMap();
    Assertions.assertEquals(enrichedAttributes.get(Constants.getEnrichedSpanConstant(SPAN_TYPE)).getValue(), Constants.getEnrichedSpanConstant(ENTRY));
    // Egress operation should be Exit span
    e = createMockEnvoyEvent(Constants.getRawSpanConstant(Envoy.ENVOY_EGRESS_SPAN));
    enricher.enrichEvent(null, e);
    enrichedAttributes = e.getEnrichedAttributes().getAttributeMap();
    Assertions.assertEquals(enrichedAttributes.get(Constants.getEnrichedSpanConstant(SPAN_TYPE)).getValue(), Constants.getEnrichedSpanConstant(EXIT));
    // Random value is Unknown span
    e = createMockEnvoyEvent("Random");
    enricher.enrichEvent(null, e);
    enrichedAttributes = e.getEnrichedAttributes().getAttributeMap();
    Assertions.assertEquals(enrichedAttributes.get(Constants.getEnrichedSpanConstant(SPAN_TYPE)).getValue(), Constants.getEnrichedSpanConstant(UNKNOWN));
}
Also used : AttributeValue(org.hypertrace.core.datamodel.AttributeValue) Event(org.hypertrace.core.datamodel.Event) Test(org.junit.jupiter.api.Test)

Aggregations

AttributeValue (org.hypertrace.core.datamodel.AttributeValue)84 Test (org.junit.jupiter.api.Test)65 Event (org.hypertrace.core.datamodel.Event)53 BackendInfo (org.hypertrace.traceenricher.enrichment.enrichers.resolver.backend.BackendInfo)24 Entity (org.hypertrace.entity.data.service.v1.Entity)22 HashMap (java.util.HashMap)19 TestUtil.buildAttributeValue (org.hypertrace.traceenricher.TestUtil.buildAttributeValue)11 AvroBuilderCache.fastNewBuilder (org.hypertrace.core.datamodel.shared.AvroBuilderCache.fastNewBuilder)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Map (java.util.Map)3 EventRef (org.hypertrace.core.datamodel.EventRef)3 StructuredTrace (org.hypertrace.core.datamodel.StructuredTrace)3 Attributes (org.hypertrace.core.datamodel.Attributes)2 MetricValue (org.hypertrace.core.datamodel.MetricValue)2 RawSpan (org.hypertrace.core.datamodel.RawSpan)2 SpanEventView (org.hypertrace.viewgenerator.api.SpanEventView)2 ImmutableList (com.google.common.collect.ImmutableList)1 ByteString (com.google.protobuf.ByteString)1 ProtocolStringList (com.google.protobuf.ProtocolStringList)1