Search in sources :

Example 51 with AttributeValue

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

the class JdbcBackendProviderTest method testWebgoatUrl.

@Test
public void testWebgoatUrl() {
    Event e = Event.newBuilder().setCustomerId("__default").setEventId(ByteBuffer.wrap("bdf03dfabf5c70f8".getBytes())).setEntityIdList(Arrays.asList("4bfca8f7-4974-36a4-9385-dd76bf5c8824")).setEnrichedAttributes(Attributes.newBuilder().setAttributeMap(Map.of("SPAN_TYPE", AttributeValue.newBuilder().setValue("EXIT").build())).build()).setAttributes(Attributes.newBuilder().setAttributeMap(Map.of("sql.url", AttributeValue.newBuilder().setValue("jdbc:hsqldb:hsql://dbhost:9001/webgoat").build(), "span.kind", AttributeValue.newBuilder().setValue("client").build(), "sql.query", AttributeValue.newBuilder().setValue("insert into audit_message (message, id) values (?, ?)").build(), "db.operation", AttributeValue.newBuilder().setValue("select").build(), "k8s.pod_id", AttributeValue.newBuilder().setValue("55636196-c840-11e9-a417-42010a8a0064").build(), "docker.container_id", AttributeValue.newBuilder().setValue("ee85cf2cfc3b24613a3da411fdbd2f3eabbe729a5c86c5262971c8d8c29dad0f").build(), "FLAGS", AttributeValue.newBuilder().setValue("0").build())).build()).setEventName("jdbc.connection.prepare").setStartTimeMillis(1566869077746L).setEndTimeMillis(1566869077750L).setMetrics(Metrics.newBuilder().setMetricMap(Map.of("Duration", MetricValue.newBuilder().setValue(4.0).build())).build()).setEventRefList(Arrays.asList(EventRef.newBuilder().setTraceId(ByteBuffer.wrap("random_trace_id".getBytes())).setEventId(ByteBuffer.wrap("random_event_id".getBytes())).setRefType(EventRefType.CHILD_OF).build())).build();
    BackendInfo backendInfo = backendEntityEnricher.resolve(e, structuredTrace, structuredTraceGraph).get();
    final Entity backendEntity = backendInfo.getEntity();
    assertEquals("dbhost:9001", backendEntity.getEntityName());
    assertEquals(3, backendEntity.getIdentifyingAttributesCount());
    Assertions.assertEquals(BackendType.JDBC.name(), backendEntity.getIdentifyingAttributesMap().get(Constants.getEntityConstant(BackendAttribute.BACKEND_ATTRIBUTE_PROTOCOL)).getValue().getString());
    assertEquals("dbhost", backendEntity.getIdentifyingAttributesMap().get(Constants.getEntityConstant(BackendAttribute.BACKEND_ATTRIBUTE_HOST)).getValue().getString());
    assertEquals("9001", backendEntity.getIdentifyingAttributesMap().get(Constants.getEntityConstant(BackendAttribute.BACKEND_ATTRIBUTE_PORT)).getValue().getString());
    assertEquals("hsqldb", backendEntity.getAttributesMap().get(Constants.getRawSpanConstant(Sql.SQL_DB_TYPE)).getValue().getString());
    assertEquals("jdbc.connection.prepare", backendEntity.getAttributesMap().get(Constants.getEnrichedSpanConstant(Backend.BACKEND_FROM_EVENT)).getValue().getString());
    assertEquals("62646630336466616266356337306638", backendEntity.getAttributesMap().get(Constants.getEnrichedSpanConstant(Backend.BACKEND_FROM_EVENT_ID)).getValue().getString());
    assertEquals("/webgoat", backendEntity.getAttributesMap().get(EntityConstants.getValue(BackendAttribute.BACKEND_ATTRIBUTE_PATH)).getValue().getString());
    Map<String, AttributeValue> attributes = backendInfo.getAttributes();
    assertEquals(Map.of("BACKEND_OPERATION", AttributeValueCreator.create("select")), attributes);
}
Also used : Entity(org.hypertrace.entity.data.service.v1.Entity) TestUtil.buildAttributeValue(org.hypertrace.traceenricher.TestUtil.buildAttributeValue) AttributeValue(org.hypertrace.core.datamodel.AttributeValue) Event(org.hypertrace.core.datamodel.Event) BackendInfo(org.hypertrace.traceenricher.enrichment.enrichers.resolver.backend.BackendInfo) Test(org.junit.jupiter.api.Test)

Example 52 with AttributeValue

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

the class JdbcBackendProviderTest method testBackendDestinationWithoutTableName.

@Test
public void testBackendDestinationWithoutTableName() {
    Event e = Event.newBuilder().setCustomerId("__default").setEventId(ByteBuffer.wrap("bdf03dfabf5c70f8".getBytes())).setEntityIdList(Arrays.asList("4bfca8f7-4974-36a4-9385-dd76bf5c8824")).setEnrichedAttributes(Attributes.newBuilder().setAttributeMap(Map.of("SPAN_TYPE", AttributeValue.newBuilder().setValue("EXIT").build())).build()).setAttributes(Attributes.newBuilder().setAttributeMap(Map.of("sql.url", AttributeValue.newBuilder().setValue("jdbc:hsqldb:hsql://dbhost:9001/webgoat").build(), "span.kind", AttributeValue.newBuilder().setValue("client").build(), "db.name", AttributeValue.newBuilder().setValue("customer").build())).build()).setEventName("jdbc.connection.prepare").setEventRefList(Arrays.asList(EventRef.newBuilder().setTraceId(ByteBuffer.wrap("random_trace_id".getBytes())).setEventId(ByteBuffer.wrap("random_event_id".getBytes())).setRefType(EventRefType.CHILD_OF).build())).build();
    BackendInfo backendInfo = backendEntityEnricher.resolve(e, structuredTrace, structuredTraceGraph).get();
    Map<String, AttributeValue> attributes = backendInfo.getAttributes();
    assertEquals(Map.of("BACKEND_DESTINATION", AttributeValueCreator.create("customer")), attributes);
}
Also used : TestUtil.buildAttributeValue(org.hypertrace.traceenricher.TestUtil.buildAttributeValue) AttributeValue(org.hypertrace.core.datamodel.AttributeValue) Event(org.hypertrace.core.datamodel.Event) BackendInfo(org.hypertrace.traceenricher.enrichment.enrichers.resolver.backend.BackendInfo) Test(org.junit.jupiter.api.Test)

Example 53 with AttributeValue

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

the class KafkaBackendProviderTest method TestOtelBackendDestinationResolution.

@Test
public void TestOtelBackendDestinationResolution() {
    String broker = "kafka-test.hypertrace.com:9092";
    BackendInfo backendInfo = backendEntityEnricher.resolve(getOtelKafkaBackendEventForDestination(broker), structuredTrace, structuredTraceGraph).get();
    Entity entity = backendInfo.getEntity();
    Assertions.assertEquals(broker, entity.getEntityName());
    Map<String, AttributeValue> attributes = backendInfo.getAttributes();
    assertEquals(Map.of("BACKEND_DESTINATION", AttributeValueCreator.create("myGroup.QueueName")), 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 54 with AttributeValue

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

the class ErrorsAndExceptionsEnricherTest method errorExists.

@Test
public void errorExists() {
    ErrorsAndExceptionsEnricher enricher = new ErrorsAndExceptionsEnricher();
    Event e1 = createMockTestEvent();
    Map<String, AttributeValue> attributeValueMap = e1.getAttributes().getAttributeMap();
    attributeValueMap.put(Constants.getRawSpanConstant(Error.ERROR_ERROR), AttributeValueCreator.create(true));
    enricher.enrichEvent(null, e1);
    Assertions.assertEquals(1.0d, e1.getMetrics().getMetricMap().get(Constants.getEnrichedSpanConstant(ErrorMetrics.ERROR_METRICS_ERROR_COUNT)).getValue());
    Event e2 = createMockTestEvent();
    attributeValueMap = e2.getAttributes().getAttributeMap();
    attributeValueMap.put(Constants.getRawSpanConstant(Error.ERROR_STACK_TRACE), AttributeValueCreator.create("test stack"));
    enricher.enrichEvent(null, e2);
    Assertions.assertEquals(1.0d, e2.getMetrics().getMetricMap().get(Constants.getEnrichedSpanConstant(ErrorMetrics.ERROR_METRICS_EXCEPTION_COUNT)).getValue());
    Event e3 = createMockTestEvent();
    attributeValueMap = e3.getAttributes().getAttributeMap();
    attributeValueMap.put(Constants.getRawSpanConstant(Error.ERROR_ERROR).toLowerCase(), AttributeValueCreator.create(true));
    enricher.enrichEvent(null, e3);
    Assertions.assertEquals(1.0d, e3.getMetrics().getMetricMap().get(Constants.getEnrichedSpanConstant(ErrorMetrics.ERROR_METRICS_ERROR_COUNT)).getValue());
    Event e4 = createMockTestEvent();
    attributeValueMap = e4.getAttributes().getAttributeMap();
    attributeValueMap.put(Constants.getRawSpanConstant(Error.ERROR_ERROR).toLowerCase(), AttributeValueCreator.create(true));
    enricher.enrichEvent(null, e4);
    Assertions.assertEquals(1.0d, e4.getMetrics().getMetricMap().get(Constants.getEnrichedSpanConstant(ErrorMetrics.ERROR_METRICS_ERROR_COUNT)).getValue());
    Event e5 = createMockTestEvent();
    attributeValueMap = e5.getAttributes().getAttributeMap();
    attributeValueMap.put(OTelErrorSemanticConventions.EXCEPTION_TYPE.getValue().toLowerCase(), AttributeValueCreator.create(true));
    enricher.enrichEvent(null, e5);
    Assertions.assertEquals(1.0d, e5.getMetrics().getMetricMap().get(Constants.getEnrichedSpanConstant(ErrorMetrics.ERROR_METRICS_ERROR_COUNT)).getValue());
    Event e6 = createMockTestEvent();
    attributeValueMap = e6.getAttributes().getAttributeMap();
    attributeValueMap.put(OTelErrorSemanticConventions.EXCEPTION_STACKTRACE.getValue().toLowerCase(), AttributeValueCreator.create(true));
    enricher.enrichEvent(null, e6);
    Assertions.assertEquals(1.0d, e6.getMetrics().getMetricMap().get(Constants.getEnrichedSpanConstant(ErrorMetrics.ERROR_METRICS_EXCEPTION_COUNT)).getValue());
    StructuredTrace trace = createStructuredTrace("test-id", e1, e2, e3, e4, e5, e6);
    enricher.enrichEvent(trace, e1);
    enricher.enrichEvent(trace, e2);
    enricher.enrichEvent(trace, e3);
    enricher.enrichEvent(trace, e4);
    enricher.enrichEvent(trace, e5);
    enricher.enrichEvent(trace, e6);
    trace.setMetrics(Metrics.newBuilder().setMetricMap(new HashMap<>()).build());
    Assertions.assertEquals(1.0d, e4.getMetrics().getMetricMap().get(Constants.getEnrichedSpanConstant(ErrorMetrics.ERROR_METRICS_ERROR_COUNT)).getValue());
    enricher.enrichTrace(trace);
    Assertions.assertEquals(6.0d, trace.getMetrics().getMetricMap().get(Constants.getEnrichedSpanConstant(ErrorMetrics.ERROR_METRICS_TOTAL_SPANS_WITH_ERRORS)).getValue());
    Assertions.assertEquals(3.0d, trace.getMetrics().getMetricMap().get(Constants.getEnrichedSpanConstant(ErrorMetrics.ERROR_METRICS_TOTAL_SPANS_WITH_EXCEPTIONS)).getValue());
    // Trace itself doesn't have an error since there was no entry span.
    Assertions.assertTrue(trace.getAttributes().getAttributeMap().containsKey(Constants.getEnrichedSpanConstant(CommonAttribute.COMMON_ATTRIBUTE_TRANSACTION_HAS_ERROR)));
    // Make e1 as ENTRY span so that the error is reflected on the structured trace.
    e1.getEnrichedAttributes().getAttributeMap().put(Constants.getEnrichedSpanConstant(CommonAttribute.COMMON_ATTRIBUTE_SPAN_TYPE), AttributeValueCreator.create(Constants.getEnrichedSpanConstant(BoundaryTypeValue.BOUNDARY_TYPE_VALUE_ENTRY)));
    enricher.enrichTrace(trace);
    Assertions.assertEquals(6.0d, trace.getMetrics().getMetricMap().get(Constants.getEnrichedSpanConstant(ErrorMetrics.ERROR_METRICS_TOTAL_SPANS_WITH_ERRORS)).getValue());
    Assertions.assertEquals(3.0d, trace.getMetrics().getMetricMap().get(Constants.getEnrichedSpanConstant(ErrorMetrics.ERROR_METRICS_TOTAL_SPANS_WITH_EXCEPTIONS)).getValue());
    Assertions.assertEquals("true", trace.getAttributes().getAttributeMap().get(Constants.getEnrichedSpanConstant(CommonAttribute.COMMON_ATTRIBUTE_TRANSACTION_HAS_ERROR)).getValue());
}
Also used : AttributeValue(org.hypertrace.core.datamodel.AttributeValue) StructuredTrace(org.hypertrace.core.datamodel.StructuredTrace) Event(org.hypertrace.core.datamodel.Event) Test(org.junit.jupiter.api.Test)

Example 55 with AttributeValue

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

the class HttpAttributeEnricherTest method testSemicolonInQueryParam.

@Test
public void testSemicolonInQueryParam() {
    String query_string = "action=checkout;age=2";
    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;age=2", actionParam.getValue());
    assertEquals(List.of("checkout;age=2"), actionParam.getValueList());
}
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