Search in sources :

Example 11 with AttributeValue

use of org.hypertrace.entity.data.service.v1.AttributeValue in project hypertrace-ingester by hypertrace.

the class RabbitMqBackendProviderTest method testBackendOperationAndDestinationResolution.

@Test
public void testBackendOperationAndDestinationResolution() {
    String routingKey = "routingkey";
    BackendInfo backendInfo = backendEntityEnricher.resolve(getRabbitMqEventMissingOperation(routingKey), structuredTrace, structuredTraceGraph).get();
    Entity entity = backendInfo.getEntity();
    Assertions.assertEquals(routingKey, entity.getEntityName());
    Map<String, AttributeValue> attributes = backendInfo.getAttributes();
    assertEquals(Map.of("BACKEND_OPERATION", AttributeValueCreator.create("basic.publish"), "BACKEND_DESTINATION", AttributeValueCreator.create("routingkey.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 12 with AttributeValue

use of org.hypertrace.entity.data.service.v1.AttributeValue in project hypertrace-ingester by hypertrace.

the class RabbitMqBackendProviderTest method testBackendDestinationResolutionWithRoutingKey.

@Test
public void testBackendDestinationResolutionWithRoutingKey() {
    String routingKey = "routingkey";
    BackendInfo backendInfo = backendEntityEnricher.resolve(getRabbitMqDestinationWithRoutingKey(routingKey), structuredTrace, structuredTraceGraph).get();
    Entity entity = backendInfo.getEntity();
    Assertions.assertEquals(routingKey, entity.getEntityName());
    Map<String, AttributeValue> attributes = backendInfo.getAttributes();
    assertEquals(Map.of("BACKEND_DESTINATION", AttributeValueCreator.create("routingkey")), 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 13 with AttributeValue

use of org.hypertrace.entity.data.service.v1.AttributeValue in project hypertrace-ingester by hypertrace.

the class RedisBackendProviderTest method checkBackendEntityGeneratedFromRedisEvent.

@Test
public void checkBackendEntityGeneratedFromRedisEvent() {
    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("redis.connection", AttributeValue.newBuilder().setValue("redis-cart:6379").build(), "span.kind", AttributeValue.newBuilder().setValue("client").build(), "redis.command", AttributeValue.newBuilder().setValue("GET").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(), "redis.args", AttributeValue.newBuilder().setValue("key<product_5d644175551847d7408760b3>").build())).build()).setEventName("reactive.redis.exit").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("redis-cart:6379", backendEntity.getEntityName());
    assertEquals(3, backendEntity.getIdentifyingAttributesCount());
    assertEquals(backendEntity.getIdentifyingAttributesMap().get(Constants.getEntityConstant(BackendAttribute.BACKEND_ATTRIBUTE_PROTOCOL)).getValue().getString(), "REDIS");
    assertEquals(backendEntity.getIdentifyingAttributesMap().get(Constants.getEntityConstant(BackendAttribute.BACKEND_ATTRIBUTE_HOST)).getValue().getString(), "redis-cart");
    assertEquals(backendEntity.getIdentifyingAttributesMap().get(Constants.getEntityConstant(BackendAttribute.BACKEND_ATTRIBUTE_PORT)).getValue().getString(), "6379");
    assertEquals(backendEntity.getAttributesMap().get(Constants.getEnrichedSpanConstant(Backend.BACKEND_FROM_EVENT)).getValue().getString(), "reactive.redis.exit");
    assertEquals(backendEntity.getAttributesMap().get(Constants.getEnrichedSpanConstant(Backend.BACKEND_FROM_EVENT_ID)).getValue().getString(), "62646630336466616266356337306638");
    assertEquals(backendEntity.getAttributesMap().get("redis.command").getValue().getString(), "GET");
    assertEquals(backendEntity.getAttributesMap().get("redis.args").getValue().getString(), "key<product_5d644175551847d7408760b3>");
    Map<String, AttributeValue> attributes = backendInfo.getAttributes();
    assertEquals(Map.of("BACKEND_OPERATION", AttributeValueCreator.create("GET")), 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 14 with AttributeValue

use of org.hypertrace.entity.data.service.v1.AttributeValue in project hypertrace-ingester by hypertrace.

the class SqsBackendProviderTest method TestOtelSqsBackendResolution.

@Test
public void TestOtelSqsBackendResolution() {
    String sqsConnectionString = "https://queue.amazonaws.com/80398EXAMPLE/MyQueue";
    URL sqsURL;
    try {
        sqsURL = new URL(sqsConnectionString);
        String sqsHost = sqsURL.getHost();
        BackendInfo backendInfo = backendEntityEnricher.resolve(getOtelSqsBackendEvent(sqsConnectionString), structuredTrace, structuredTraceGraph).get();
        Entity entity = backendInfo.getEntity();
        Assertions.assertEquals(sqsHost, entity.getEntityName());
        Map<String, AttributeValue> attributes = backendInfo.getAttributes();
        assertEquals(Map.of("BACKEND_OPERATION", AttributeValueCreator.create("receive"), "BACKEND_DESTINATION", AttributeValueCreator.create("QueueName")), attributes);
    } catch (MalformedURLException e) {
        Assertions.fail("Unable to create URL for given connection string");
    }
}
Also used : Entity(org.hypertrace.entity.data.service.v1.Entity) AttributeValue(org.hypertrace.core.datamodel.AttributeValue) MalformedURLException(java.net.MalformedURLException) URL(java.net.URL) BackendInfo(org.hypertrace.traceenricher.enrichment.enrichers.resolver.backend.BackendInfo) Test(org.junit.jupiter.api.Test)

Example 15 with AttributeValue

use of org.hypertrace.entity.data.service.v1.AttributeValue in project hypertrace-ingester by hypertrace.

the class BackendEntityEnricherTest method test_EnrichTrace_ExternalBackendNotResolvedAsPeerServiceExists.

@Test
public void test_EnrichTrace_ExternalBackendNotResolvedAsPeerServiceExists() {
    String eventName = "service exists";
    String backendName = "external-backend";
    String serviceId = "serviceId";
    String peerService = "peerService";
    // return false for backend service name identified by http backend resolver
    AttributeValue fqnAttribute = AttributeValue.newBuilder().setValue(Value.newBuilder().setString(backendName)).build();
    ByTypeAndIdentifyingAttributes request = ByTypeAndIdentifyingAttributes.newBuilder().setEntityType(EntityType.SERVICE.name()).putIdentifyingAttributes(EntityConstants.getValue(org.hypertrace.entity.constants.v1.CommonAttribute.COMMON_ATTRIBUTE_FQN), fqnAttribute).build();
    // check for if service exists for peer service
    when(edsClient.getByTypeAndIdentifyingAttributes(eq(TENANT_ID), eq(request))).thenReturn(null);
    AttributeValue fqnAttributePeerService = AttributeValue.newBuilder().setValue(Value.newBuilder().setString(peerService)).build();
    ByTypeAndIdentifyingAttributes requestPeerService = ByTypeAndIdentifyingAttributes.newBuilder().setEntityType(EntityType.SERVICE.name()).putIdentifyingAttributes(EntityConstants.getValue(org.hypertrace.entity.constants.v1.CommonAttribute.COMMON_ATTRIBUTE_FQN), fqnAttributePeerService).build();
    when(edsClient.getByTypeAndIdentifyingAttributes(eq(TENANT_ID), eq(requestPeerService))).thenReturn(Entity.newBuilder().setEntityId(serviceId).build());
    // for broken event service and peer service are different
    Event.Builder eventBuilder = createApiExitEvent(EVENT_ID, backendName, peerService).setEventName(eventName).setEnrichedAttributes(createNewAvroAttributes(Map.of("PROTOCOL", "HTTPS")));
    eventBuilder.getHttpBuilder().getRequestBuilder().setHost(backendName).setScheme("https").setPath("/abc/v1/book");
    Event e = eventBuilder.build();
    StructuredTrace trace = createStructuredTrace(TENANT_ID, e);
    enricher.enrichTrace(trace);
    // assert that backend has been created
    Assertions.assertNull(EnrichedSpanUtils.getBackendId(e));
    Assertions.assertNull(EnrichedSpanUtils.getBackendName(e));
}
Also used : AttributeValue(org.hypertrace.entity.data.service.v1.AttributeValue) ByTypeAndIdentifyingAttributes(org.hypertrace.entity.data.service.v1.ByTypeAndIdentifyingAttributes) StructuredTrace(org.hypertrace.core.datamodel.StructuredTrace) Event(org.hypertrace.core.datamodel.Event) Test(org.junit.jupiter.api.Test) AbstractAttributeEnricherTest(org.hypertrace.traceenricher.enrichment.enrichers.AbstractAttributeEnricherTest)

Aggregations

Test (org.junit.jupiter.api.Test)39 Entity (org.hypertrace.entity.data.service.v1.Entity)37 AttributeValue (org.hypertrace.entity.data.service.v1.AttributeValue)24 AttributeValue (org.hypertrace.core.datamodel.AttributeValue)22 BackendInfo (org.hypertrace.traceenricher.enrichment.enrichers.resolver.backend.BackendInfo)20 Event (org.hypertrace.core.datamodel.Event)12 EnrichedEntity (org.hypertrace.entity.data.service.v1.EnrichedEntity)11 AttributeValue (com.google.devtools.cloudtrace.v2.AttributeValue)10 Test (org.junit.Test)10 HashMap (java.util.HashMap)9 ByTypeAndIdentifyingAttributes (org.hypertrace.entity.data.service.v1.ByTypeAndIdentifyingAttributes)9 TestUtil.buildAttributeValue (org.hypertrace.traceenricher.TestUtil.buildAttributeValue)7 Span (zipkin2.Span)7 AttributesExtractor.toAttributeValue (zipkin2.translation.stackdriver.AttributesExtractor.toAttributeValue)7 ArrayList (java.util.ArrayList)5 List (java.util.List)5 Map (java.util.Map)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 Span (com.google.devtools.cloudtrace.v2.Span)3 TruncatableString (com.google.devtools.cloudtrace.v2.TruncatableString)3