Search in sources :

Example 1 with BackendInfo

use of org.hypertrace.traceenricher.enrichment.enrichers.resolver.backend.BackendInfo in project hypertrace-ingester by hypertrace.

the class AbstractBackendEntityEnricher method resolve.

@VisibleForTesting
public Optional<BackendInfo> resolve(Event event, StructuredTrace trace, StructuredTraceGraph structuredTraceGraph) {
    for (BackendProvider backendProvider : getBackendProviders()) {
        backendProvider.init(event);
        if (!backendProvider.isValidBackend(event)) {
            continue;
        }
        BackendType type = backendProvider.getBackendType(event);
        Optional<String> maybeBackendUri = backendProvider.getBackendUri(event, structuredTraceGraph);
        if (maybeBackendUri.isEmpty() || StringUtils.isEmpty(maybeBackendUri.get())) {
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("Unable to infer backend uri from event {} for backend type {}", HexUtils.getHex(event.getEventId()), type);
            }
            continue;
        }
        String backendUri = maybeBackendUri.get();
        final Builder entityBuilder = getBackendEntityBuilder(type, backendUri, event, trace);
        backendProvider.getEntityAttributes(event).forEach(entityBuilder::putAttributes);
        Map<String, org.hypertrace.core.datamodel.AttributeValue> enrichedAttributes = new HashMap<>();
        Optional<String> backendOperation = backendProvider.getBackendOperation(event);
        Optional<String> backendDestination = backendProvider.getBackendDestination(event);
        backendOperation.ifPresent(operation -> enrichedAttributes.put(BACKEND_OPERATION_ATTR, AttributeValueCreator.create(operation)));
        backendDestination.ifPresent(destination -> enrichedAttributes.put(BACKEND_DESTINATION_ATTR, AttributeValueCreator.create(destination)));
        return Optional.of(new BackendInfo(entityBuilder.build(), Collections.unmodifiableMap(enrichedAttributes)));
    }
    return Optional.empty();
}
Also used : AttributeValue(org.hypertrace.entity.data.service.v1.AttributeValue) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Builder(org.hypertrace.entity.data.service.v1.Entity.Builder) BackendProvider(org.hypertrace.traceenricher.enrichment.enrichers.backend.provider.BackendProvider) BackendType(org.hypertrace.traceenricher.enrichment.enrichers.BackendType) BackendInfo(org.hypertrace.traceenricher.enrichment.enrichers.resolver.backend.BackendInfo) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 2 with BackendInfo

use of org.hypertrace.traceenricher.enrichment.enrichers.resolver.backend.BackendInfo in project hypertrace-ingester by hypertrace.

the class RabbitMqBackendProviderTest method testEventResolution.

@Test
public void testEventResolution() {
    String routingKey = "routingkey";
    BackendInfo backendInfo = backendEntityEnricher.resolve(getRabbitMqEvent(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("receive"), "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 3 with BackendInfo

use of org.hypertrace.traceenricher.enrichment.enrichers.resolver.backend.BackendInfo 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 4 with BackendInfo

use of org.hypertrace.traceenricher.enrichment.enrichers.resolver.backend.BackendInfo 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 5 with BackendInfo

use of org.hypertrace.traceenricher.enrichment.enrichers.resolver.backend.BackendInfo 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)

Aggregations

BackendInfo (org.hypertrace.traceenricher.enrichment.enrichers.resolver.backend.BackendInfo)26 Test (org.junit.jupiter.api.Test)25 AttributeValue (org.hypertrace.core.datamodel.AttributeValue)24 Entity (org.hypertrace.entity.data.service.v1.Entity)20 Event (org.hypertrace.core.datamodel.Event)12 TestUtil.buildAttributeValue (org.hypertrace.traceenricher.TestUtil.buildAttributeValue)10 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 AttributeValue (org.hypertrace.entity.data.service.v1.AttributeValue)1 Builder (org.hypertrace.entity.data.service.v1.Entity.Builder)1 BackendType (org.hypertrace.traceenricher.enrichment.enrichers.BackendType)1 BackendProvider (org.hypertrace.traceenricher.enrichment.enrichers.backend.provider.BackendProvider)1