Search in sources :

Example 26 with AttributeValue

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

the class ElasticsearchBackendProviderTest method testBackendResolutionForOTEvent.

@Test
public void testBackendResolutionForOTEvent() {
    BackendInfo backendInfo = backendEntityEnricher.resolve(getElasticsearchOTEvent(), structuredTrace, structuredTraceGraph).get();
    Entity entity = backendInfo.getEntity();
    Assertions.assertEquals("test", entity.getEntityName());
    Map<String, AttributeValue> attributes = backendInfo.getAttributes();
    assertEquals(Map.of("BACKEND_OPERATION", AttributeValueCreator.create("GET"), "BACKEND_DESTINATION", AttributeValueCreator.create("test-index")), attributes);
}
Also used : Entity(org.hypertrace.entity.data.service.v1.Entity) AttributeValue(org.hypertrace.core.datamodel.AttributeValue) BackendInfo(org.hypertrace.traceenricher.enrichment.enrichers.resolver.backend.BackendInfo) Test(org.junit.jupiter.api.Test)

Example 27 with AttributeValue

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

the class ErrorsAndExceptionsEnricherTest method test_successStatus_shouldNotGetError.

@Test
public void test_successStatus_shouldNotGetError() {
    ErrorsAndExceptionsEnricher enricher = new ErrorsAndExceptionsEnricher();
    // Negative test
    Event e2 = createMockEvent();
    Map<String, AttributeValue> attributeValueMap = e2.getAttributes().getAttributeMap();
    attributeValueMap.put(Constants.getEnrichedSpanConstant(API_STATUS), AttributeValue.newBuilder().setValue(Constants.getEnrichedSpanConstant(ApiStatus.API_STATUS_SUCCESS)).build());
    enricher.enrichEvent(null, e2);
    Assertions.assertNull(e2.getMetrics().getMetricMap().get(Constants.getEnrichedSpanConstant(ErrorMetrics.ERROR_METRICS_ERROR_COUNT)));
}
Also used : AttributeValue(org.hypertrace.core.datamodel.AttributeValue) Event(org.hypertrace.core.datamodel.Event) Test(org.junit.jupiter.api.Test)

Example 28 with AttributeValue

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

the class HttpAttributeEnricherTest method testGetQueryParamsFromUrl.

@Test
public void testGetQueryParamsFromUrl() {
    String query_string = "action=checkout&cat=1dog=2&action=a&age=2&age=3;&location=&area&&";
    Event e = createMockEvent();
    // ; in url should not be treated as an splitting character.
    // Url in this test also contains successive & and param with no value.
    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);
    AttributeValue areaParam = SpanAttributeUtils.getAttributeValue(e, Constants.getEnrichedSpanConstant(HTTP_REQUEST_QUERY_PARAM) + ".area");
    assertNull(areaParam);
    AttributeValue catParam = SpanAttributeUtils.getAttributeValue(e, Constants.getEnrichedSpanConstant(HTTP_REQUEST_QUERY_PARAM) + ".cat");
    assertEquals("1dog=2", catParam.getValue());
    assertEquals(List.of("1dog=2"), catParam.getValueList());
}
Also used : AttributeValue(org.hypertrace.core.datamodel.AttributeValue) Event(org.hypertrace.core.datamodel.Event) Test(org.junit.jupiter.api.Test)

Example 29 with AttributeValue

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

the class HttpAttributeEnricherTest method testDecodeQueryParamsInvalidInput.

@Test
public void testDecodeQueryParamsInvalidInput() {
    // Try putting invalid encoded string in both query param key and value.
    String query_string = "action=check%!mout&loca%.Ption=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);
    // If input is invalid(can't be decoded) the input is returned as it is.
    AttributeValue actionParam = SpanAttributeUtils.getAttributeValue(e, Constants.getEnrichedSpanConstant(HTTP_REQUEST_QUERY_PARAM) + ".action");
    assertEquals("check%!mout", actionParam.getValue());
    assertEquals(List.of("check%!mout"), actionParam.getValueList());
    AttributeValue locationParam = SpanAttributeUtils.getAttributeValue(e, Constants.getEnrichedSpanConstant(HTTP_REQUEST_QUERY_PARAM) + ".loca%.Ption");
    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 30 with AttributeValue

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

the class SpanTypeAttributeEnricherTest method test_getProtocolName_grpcAndHttp_shouldReturnGrpc.

@Test
public void test_getProtocolName_grpcAndHttp_shouldReturnGrpc() {
    Map<String, AttributeValue> map = new HashMap<>();
    map.put(Constants.getRawSpanConstant(Grpc.GRPC_METHOD), AttributeValue.newBuilder().setValue("grpc method").build());
    map.put(Constants.getRawSpanConstant(Http.HTTP_REQUEST_METHOD), AttributeValue.newBuilder().setValue("GET").build());
    Event e = createEvent(map, new HashMap<>());
    Assertions.assertEquals(Protocol.PROTOCOL_GRPC, 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)

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