use of com.google.cloud.videointelligence.v1p3beta1.Entity in project hypertrace-ingester by hypertrace.
the class AbstractBackendEntityEnricher method createBackendIfMissing.
@Nullable
private Entity createBackendIfMissing(Entity backendEntity) {
RequestContext requestContext = RequestContext.forTenantId(backendEntity.getTenantId());
try {
Optional<Entity> backendFromCache = entityCache.getBackendIdAttrsToEntityCache().get(requestContext.buildContextualKey(backendEntity.getIdentifyingAttributesMap()));
return backendFromCache.orElseGet(() -> {
Entity result = this.upsertBackend(backendEntity);
LOGGER.info("Created backend:{}", result);
return result;
});
} catch (ExecutionException ex) {
LOGGER.error("Error trying to load backend from cache for backend:{}", backendEntity);
return null;
}
}
use of com.google.cloud.videointelligence.v1p3beta1.Entity 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()));
}
}
}
use of com.google.cloud.videointelligence.v1p3beta1.Entity in project hypertrace-ingester by hypertrace.
the class MongoBackendProviderTest method checkBackendEntityGeneratedFromInstrumentedMongoEvent.
@Test
public void checkBackendEntityGeneratedFromInstrumentedMongoEvent() {
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("mongo.namespace", AttributeValue.newBuilder().setValue("sampleshop.userReview").build(), "span.kind", AttributeValue.newBuilder().setValue("client").build(), "OPERATION", AttributeValue.newBuilder().setValue("FindOperation").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(), "mongo.operation", AttributeValue.newBuilder().setValue("HelloWorld").build(), "mongo.url", AttributeValue.newBuilder().setValue(MONGO_URL).build())).build()).setEventName("mongo.async.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();
final Entity backendEntity = backendEntityEnricher.resolve(e, structuredTrace, structuredTraceGraph).get().getEntity();
assertEquals("mongo:27017", backendEntity.getEntityName());
assertEquals(3, backendEntity.getIdentifyingAttributesCount());
assertEquals(backendEntity.getIdentifyingAttributesMap().get(Constants.getEntityConstant(BackendAttribute.BACKEND_ATTRIBUTE_PROTOCOL)).getValue().getString(), "MONGO");
assertEquals("mongo", backendEntity.getIdentifyingAttributesMap().get(Constants.getEntityConstant(BackendAttribute.BACKEND_ATTRIBUTE_HOST)).getValue().getString());
assertEquals(backendEntity.getIdentifyingAttributesMap().get(Constants.getEntityConstant(BackendAttribute.BACKEND_ATTRIBUTE_PORT)).getValue().getString(), "27017");
assertEquals(backendEntity.getAttributesMap().get(Constants.getRawSpanConstant(Mongo.MONGO_NAMESPACE)).getValue().getString(), "sampleshop.userReview");
assertEquals(backendEntity.getAttributesMap().get(Constants.getRawSpanConstant(Mongo.MONGO_OPERATION)).getValue().getString(), "HelloWorld");
assertEquals(backendEntity.getAttributesMap().get(Constants.getEnrichedSpanConstant(Backend.BACKEND_FROM_EVENT)).getValue().getString(), "mongo.async.exit");
assertEquals(backendEntity.getAttributesMap().get(Constants.getEnrichedSpanConstant(Backend.BACKEND_FROM_EVENT_ID)).getValue().getString(), "62646630336466616266356337306638");
}
use of com.google.cloud.videointelligence.v1p3beta1.Entity in project hypertrace-ingester by hypertrace.
the class MongoBackendProviderTest method checkBackendEntityGeneratedFromUninstrumentedMongoEvent.
@Test
public void checkBackendEntityGeneratedFromUninstrumentedMongoEvent() {
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("NAMESPACE", AttributeValue.newBuilder().setValue("sampleshop.userReview").build(), "span.kind", AttributeValue.newBuilder().setValue("client").build(), "OPERATION", AttributeValue.newBuilder().setValue("FindOperation").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(), "address", AttributeValue.newBuilder().setValue(MONGO_URL).build())).build()).setEventName("mongo.async.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();
final Entity backendEntity = backendEntityEnricher.resolve(e, structuredTrace, structuredTraceGraph).get().getEntity();
assertEquals("mongo:27017", backendEntity.getEntityName());
assertEquals(3, backendEntity.getIdentifyingAttributesCount());
assertEquals(backendEntity.getIdentifyingAttributesMap().get(Constants.getEntityConstant(BackendAttribute.BACKEND_ATTRIBUTE_PROTOCOL)).getValue().getString(), "MONGO");
assertEquals("mongo", backendEntity.getIdentifyingAttributesMap().get(Constants.getEntityConstant(BackendAttribute.BACKEND_ATTRIBUTE_HOST)).getValue().getString());
assertEquals(backendEntity.getIdentifyingAttributesMap().get(Constants.getEntityConstant(BackendAttribute.BACKEND_ATTRIBUTE_PORT)).getValue().getString(), "27017");
assertEquals(backendEntity.getAttributesMap().get("NAMESPACE").getValue().getString(), "sampleshop.userReview");
assertEquals(backendEntity.getAttributesMap().get(Constants.getEnrichedSpanConstant(Backend.BACKEND_FROM_EVENT)).getValue().getString(), "mongo.async.exit");
assertEquals(backendEntity.getAttributesMap().get(Constants.getEnrichedSpanConstant(Backend.BACKEND_FROM_EVENT_ID)).getValue().getString(), "62646630336466616266356337306638");
}
use of com.google.cloud.videointelligence.v1p3beta1.Entity 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);
}
Aggregations