Search in sources :

Example 31 with AttributeValue

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

the class SpanTypeAttributeEnricherTest method test_getProtocolName_noHttpAndGrpc_shouldReturnUnknown.

@Test
public void test_getProtocolName_noHttpAndGrpc_shouldReturnUnknown() {
    Map<String, AttributeValue> map = new HashMap<>();
    map.put(Constants.getRawSpanConstant(SpanAttribute.SPAN_ATTRIBUTE_SPAN_KIND), AttributeValue.newBuilder().setValue("ENTRY").build());
    Event e = createEvent(map, new HashMap<>());
    Assertions.assertEquals(Protocol.PROTOCOL_UNSPECIFIED, 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 32 with AttributeValue

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

the class SpanTypeAttributeEnricherTest method spanNameConvention.

@Test
public void spanNameConvention() {
    SpanTypeAttributeEnricher enricher = new SpanTypeAttributeEnricher();
    Event e = createMockEvent();
    when(e.getEventName()).thenReturn("Sent./a/");
    enricher.enrichEvent(null, e);
    Map<String, AttributeValue> enrichedAttributes = e.getEnrichedAttributes().getAttributeMap();
    Assertions.assertEquals(enrichedAttributes.get(Constants.getEnrichedSpanConstant(SPAN_TYPE)).getValue(), Constants.getEnrichedSpanConstant(EXIT));
    e = createMockEvent();
    when(e.getEventName()).thenReturn("Recv./b/");
    enricher.enrichEvent(null, e);
    enrichedAttributes = e.getEnrichedAttributes().getAttributeMap();
    Assertions.assertEquals(enrichedAttributes.get(Constants.getEnrichedSpanConstant(SPAN_TYPE)).getValue(), Constants.getEnrichedSpanConstant(ENTRY));
}
Also used : AttributeValue(org.hypertrace.core.datamodel.AttributeValue) Event(org.hypertrace.core.datamodel.Event) Test(org.junit.jupiter.api.Test)

Example 33 with AttributeValue

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

the class TraceUI method flattenAttributes.

private static JSONObject flattenAttributes(Event e) {
    JSONObject jsonObject = new JSONObject();
    jsonObject.put("eventId", HexUtils.getHex(e.getEventId()));
    if (e.getAttributes() != null && e.getAttributes().getAttributeMap() != null) {
        Map<String, AttributeValue> map = e.getAttributes().getAttributeMap();
        for (String key : map.keySet()) {
            String value = map.get(key).getValue();
            jsonObject.put(key, value);
        }
    }
    if (e.getEnrichedAttributes() != null && e.getEnrichedAttributes().getAttributeMap() != null) {
        Map<String, AttributeValue> map = e.getEnrichedAttributes().getAttributeMap();
        for (String key : map.keySet()) {
            String value = map.get(key).getValue();
            jsonObject.put(key, value);
        }
    }
    return jsonObject;
}
Also used : AttributeValue(org.hypertrace.core.datamodel.AttributeValue) JSONObject(org.json.JSONObject)

Example 34 with AttributeValue

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

the class GrpcBackendProviderTest method checkBackendEntityGeneratedFromGrpcEvent.

@Test
public void checkBackendEntityGeneratedFromGrpcEvent() {
    Map<String, AttributeValue> attributeMap = ImmutableMap.<String, AttributeValue>builder().put("grpc.method", AttributeValue.newBuilder().setValue("/hipstershop.ProductCatalogService/ListProducts").build()).put("span.kind", AttributeValue.newBuilder().setValue("client").build()).put("component", AttributeValue.newBuilder().setValue("grpc").build()).put("k8s.pod_id", AttributeValue.newBuilder().setValue("55636196-c840-11e9-a417-42010a8a0064").build()).put("docker.container_id", AttributeValue.newBuilder().setValue("ee85cf2cfc3b24613a3da411fdbd2f3eabbe729a5c86c5262971c8d8c29dad0f").build()).put("FLAGS", AttributeValue.newBuilder().setValue("0").build()).put("grpc.host_port", AttributeValue.newBuilder().setValue("productcatalogservice:3550").build()).put("grpc.response.body", AttributeValue.newBuilder().setValue("products {\\n  id: \\\"5d644175551847d7408760b5\\\"\\n  name: \\\"Vintage Record Player\\\"\\n  description: \\\"It still works.\\\"\\n  picture: \\\"/static").build()).put("grpc.request.body", AttributeValue.newBuilder().setValue("").build()).build();
    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(), "rpc.service", AttributeValue.newBuilder().setValue("myservice.EchoService").build(), "PROTOCOL", AttributeValue.newBuilder().setValue("GRPC").build())).build()).setAttributes(Attributes.newBuilder().setAttributeMap(attributeMap).build()).setEventName("Sent.hipstershop.ProductCatalogService.ListProducts").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();
    final BackendInfo backendInfo = backendEntityEnricher.resolve(e, structuredTrace, structuredTraceGraph).get();
    final Entity backendEntity = backendInfo.getEntity();
    assertEquals("productcatalogservice:3550", backendEntity.getEntityName());
    assertEquals(3, backendEntity.getIdentifyingAttributesCount());
    assertEquals(backendEntity.getIdentifyingAttributesMap().get(Constants.getEntityConstant(BackendAttribute.BACKEND_ATTRIBUTE_PROTOCOL)).getValue().getString(), "GRPC");
    assertEquals(backendEntity.getIdentifyingAttributesMap().get(Constants.getEntityConstant(BackendAttribute.BACKEND_ATTRIBUTE_HOST)).getValue().getString(), "productcatalogservice");
    assertEquals(backendEntity.getIdentifyingAttributesMap().get(Constants.getEntityConstant(BackendAttribute.BACKEND_ATTRIBUTE_PORT)).getValue().getString(), "3550");
    assertEquals(backendEntity.getAttributesMap().get(Constants.getEnrichedSpanConstant(Backend.BACKEND_FROM_EVENT)).getValue().getString(), "Sent.hipstershop.ProductCatalogService.ListProducts");
    assertEquals(backendEntity.getAttributesMap().get(Constants.getEnrichedSpanConstant(Backend.BACKEND_FROM_EVENT_ID)).getValue().getString(), "62646630336466616266356337306638");
    assertEquals(backendEntity.getAttributesMap().get(Constants.getRawSpanConstant(Grpc.GRPC_METHOD)).getValue().getString(), "/hipstershop.ProductCatalogService/ListProducts");
    Map<String, AttributeValue> attributes = backendInfo.getAttributes();
    assertEquals(Map.of("BACKEND_DESTINATION", AttributeValueCreator.create("myservice.EchoService"), "BACKEND_OPERATION", AttributeValueCreator.create("/hipstershop.ProductCatalogService/ListProducts")), attributes);
}
Also used : Entity(org.hypertrace.entity.data.service.v1.Entity) 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 35 with AttributeValue

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

the class JdbcBackendProviderTest method testBackendDestinationWithTableName.

@Test
public void testBackendDestinationWithTableName() {
    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.sql.table", AttributeValue.newBuilder().setValue("orders").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.orders")), 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)

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