Search in sources :

Example 1 with BackendProvider

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

Aggregations

VisibleForTesting (com.google.common.annotations.VisibleForTesting)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 BackendInfo (org.hypertrace.traceenricher.enrichment.enrichers.resolver.backend.BackendInfo)1