Search in sources :

Example 6 with AttributeValue

use of org.hypertrace.entity.data.service.v1.AttributeValue in project zipkin-gcp by openzipkin.

the class AttributesExtractorTest method testLabelIsRenamed.

@Test
public void testLabelIsRenamed() {
    Map<String, String> knownLabels = new LinkedHashMap<>();
    knownLabels.put("known.1", "renamed.1");
    knownLabels.put("known.2", "renamed.2");
    AttributesExtractor extractor = new AttributesExtractor(knownLabels);
    Span zipkinSpan = Span.newBuilder().traceId("4").name("test-span").id("5").addAnnotation(1, "annotation.key.1").addAnnotation(13, "known.1").putTag("tag.key.1", "value").putTag("known.2", "known.value").build();
    Map<String, AttributeValue> labels = extractor.extract(zipkinSpan).getAttributeMapMap();
    assertThat(labels).contains(entry("renamed.2", toAttributeValue("known.value")));
}
Also used : AttributeValue(com.google.devtools.cloudtrace.v2.AttributeValue) AttributesExtractor.toAttributeValue(zipkin2.translation.stackdriver.AttributesExtractor.toAttributeValue) Span(zipkin2.Span) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 7 with AttributeValue

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

the class AbstractBackendEntityEnricher method getAttributesToEnrich.

private Map<String, org.hypertrace.core.datamodel.AttributeValue> getAttributesToEnrich(Entity backend) {
    Map<String, org.hypertrace.core.datamodel.AttributeValue> attributes = new LinkedHashMap<>();
    attributes.put(EntityConstants.getValue(BackendAttribute.BACKEND_ATTRIBUTE_ID), AttributeValueCreator.create(backend.getEntityId()));
    attributes.put(EntityConstants.getValue(BackendAttribute.BACKEND_ATTRIBUTE_NAME), AttributeValueCreator.create(backend.getEntityName()));
    attributes.put(EntityConstants.getValue(BackendAttribute.BACKEND_ATTRIBUTE_HOST), createAttributeValue(backend.getAttributesMap().get(EntityConstants.getValue(BackendAttribute.BACKEND_ATTRIBUTE_HOST))));
    attributes.put(EntityConstants.getValue(BackendAttribute.BACKEND_ATTRIBUTE_PORT), createAttributeValue(backend.getAttributesMap().get(EntityConstants.getValue(BackendAttribute.BACKEND_ATTRIBUTE_PORT))));
    attributes.put(EntityConstants.getValue(BackendAttribute.BACKEND_ATTRIBUTE_PROTOCOL), createAttributeValue(backend.getAttributesMap().get(EntityConstants.getValue(BackendAttribute.BACKEND_ATTRIBUTE_PROTOCOL))));
    AttributeValue path = backend.getAttributesMap().get(EntityConstants.getValue(BackendAttribute.BACKEND_ATTRIBUTE_PATH));
    if (path != null) {
        attributes.put(EntityConstants.getValue(BackendAttribute.BACKEND_ATTRIBUTE_PATH), createAttributeValue(path));
    }
    return attributes;
}
Also used : AttributeValue(org.hypertrace.entity.data.service.v1.AttributeValue) LinkedHashMap(java.util.LinkedHashMap)

Example 8 with AttributeValue

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

the class EntityCache method loadServiceFromFQN.

protected Optional<Entity> loadServiceFromFQN(Pair<String, String> tenantIdFQNPair) {
    AttributeValue fqnAttribute = AttributeValue.newBuilder().setValue(Value.newBuilder().setString(tenantIdFQNPair.getRight())).build();
    ByTypeAndIdentifyingAttributes request = ByTypeAndIdentifyingAttributes.newBuilder().setEntityType(EntityType.SERVICE.name()).putIdentifyingAttributes(EntityConstants.getValue(CommonAttribute.COMMON_ATTRIBUTE_FQN), fqnAttribute).build();
    return Optional.ofNullable(edsClient.getByTypeAndIdentifyingAttributes(tenantIdFQNPair.getLeft(), request));
}
Also used : AttributeValue(org.hypertrace.entity.data.service.v1.AttributeValue) ByTypeAndIdentifyingAttributes(org.hypertrace.entity.data.service.v1.ByTypeAndIdentifyingAttributes)

Example 9 with AttributeValue

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

the class EndpointEnricher method enrichEvent.

@Override
public void enrichEvent(StructuredTrace trace, Event event) {
    // This Enricher depends on SpanType so if that's missing, we can't do anything with the span.
    if (event.getEnrichedAttributes() == null) {
        return;
    }
    Map<String, AttributeValue> attributeMap = event.getEnrichedAttributes().getAttributeMap();
    if (attributeMap == null || attributeMap.isEmpty()) {
        return;
    }
    if (!EnrichedSpanUtils.isEntryApiBoundary(event)) {
        return;
    }
    // Lookup the service id from the span. If we can't find a service id, we can't really
    // associate API details with that span.
    String serviceId = EnrichedSpanUtils.getServiceId(event);
    String serviceName = EnrichedSpanUtils.getServiceName(event);
    String customerId = trace.getCustomerId();
    if (serviceId == null) {
        LOGGER.warn("Could not find serviceId in the span so not enriching it with API." + "tenantId: {}, traceId: {}, span: {}", event.getCustomerId(), HexUtils.getHex(trace.getTraceId()), event);
        return;
    }
    Entity apiEntity = null;
    try {
        apiEntity = getOperationNameBasedEndpointDiscoverer(customerId, serviceId, serviceName).getApiEntity(event);
    } catch (Exception e) {
        LOGGER.error("Unable to get apiEntity for tenantId {}, serviceId {} and event {}", customerId, serviceId, event, e);
    }
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("tenantId: {}, serviceId: {}, span: {}, apiEntity: {}", customerId, serviceId, event, apiEntity);
    }
    if (apiEntity != null) {
        // API Id
        addEnrichedAttribute(event, API_ID_ATTR_NAME, AttributeValueCreator.create(apiEntity.getEntityId()));
        // API pattern
        addEnrichedAttribute(event, API_URL_PATTERN_ATTR_NAME, AttributeValueCreator.create(apiEntity.getEntityName()));
        // API name
        org.hypertrace.entity.data.service.v1.AttributeValue apiNameValue = apiEntity.getAttributesMap().get(API_NAME_ATTR_NAME);
        if (apiNameValue != null) {
            addEnrichedAttribute(event, API_NAME_ATTR_NAME, AttributeValueCreator.create(apiNameValue.getValue().getString()));
        }
        // API Discovery
        org.hypertrace.entity.data.service.v1.AttributeValue apiDiscoveryState = apiEntity.getAttributesMap().get(API_DISCOVERY_STATE_ATTR);
        if (apiDiscoveryState != null) {
            addEnrichedAttribute(event, API_DISCOVERY_STATE_ATTR, AttributeValueCreator.create(apiDiscoveryState.getValue().getString()));
        }
    }
}
Also used : Entity(org.hypertrace.entity.data.service.v1.Entity) AttributeValue(org.hypertrace.core.datamodel.AttributeValue)

Example 10 with AttributeValue

use of org.hypertrace.entity.data.service.v1.AttributeValue 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)

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