use of org.hypertrace.entity.data.service.v1.ByTypeAndIdentifyingAttributes 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));
}
use of org.hypertrace.entity.data.service.v1.ByTypeAndIdentifyingAttributes 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));
}
use of org.hypertrace.entity.data.service.v1.ByTypeAndIdentifyingAttributes in project entity-service by hypertrace.
the class EdsCacheClientTest method testGetByTypeAndIdentifyingAttributes.
@Test
public void testGetByTypeAndIdentifyingAttributes() {
String tenantId = "tenant";
String entityId = "entity-12345";
Map<String, AttributeValue> identifyingAttributesMap = new HashMap<>();
identifyingAttributesMap.put("entity_name", AttributeValue.newBuilder().setValue(Value.newBuilder().setString("GET /products").build()).build());
identifyingAttributesMap.put("is_active", AttributeValue.newBuilder().setValue(Value.newBuilder().setBoolean(true).build()).build());
Entity entity = Entity.newBuilder().setTenantId(tenantId).setEntityId(entityId).setEntityType("API").setEntityName("GET /products").putAllIdentifyingAttributes(identifyingAttributesMap).build();
when(entityDataServiceClient.getById(anyString(), anyString())).thenReturn(entity);
when(entityDataServiceClient.getByTypeAndIdentifyingAttributes(anyString(), any())).thenReturn(entity);
ByTypeAndIdentifyingAttributes attributes = ByTypeAndIdentifyingAttributes.newBuilder().setEntityType("API").putAllIdentifyingAttributes(identifyingAttributesMap).build();
edsCacheClient.getByTypeAndIdentifyingAttributes(tenantId, attributes);
edsCacheClient.getByTypeAndIdentifyingAttributes(tenantId, attributes);
verify(entityDataServiceClient, times(1)).getByTypeAndIdentifyingAttributes("tenant", attributes);
verify(entityDataServiceClient, never()).getById("tenant", "entity-12345");
}
use of org.hypertrace.entity.data.service.v1.ByTypeAndIdentifyingAttributes in project hypertrace-ingester by hypertrace.
the class BackendEntityEnricherTest method test_EnrichTrace_ExternalBackendResolved.
@Test
public void test_EnrichTrace_ExternalBackendResolved() {
String eventName = "backend created";
String backendName = "external-backend";
String backendId = "backendId";
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();
when(edsClient.getByTypeAndIdentifyingAttributes(eq(TENANT_ID), eq(request))).thenReturn(null);
// return false for peer service name as part of span
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(null);
// create backend entity
Map<String, String> identifyingAttributes = Map.of(BACKEND_PROTOCOL_ATTR_NAME, "HTTPS", BACKEND_HOST_ATTR_NAME, backendName, BACKEND_PORT_ATTR_NAME, "-1");
Map<String, String> attributes = Map.of("FROM_EVENT", eventName, "FROM_EVENT_ID", HexUtils.getHex(ByteBuffer.wrap(EVENT_ID.getBytes())), "BACKEND_PATH", "/abc/v1/book");
Entity backendEntity = createEntity(EntityType.BACKEND, backendName, identifyingAttributes, attributes, TENANT_ID);
when(edsClient.upsert(eq(backendEntity))).thenReturn(Entity.newBuilder(backendEntity).setEntityId(backendId).putAllAttributes(createEdsAttributes(identifyingAttributes)).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();
e.getAttributes().getAttributeMap().put(RawSpanConstants.getValue(Http.HTTP_HOST), org.hypertrace.core.datamodel.AttributeValue.newBuilder().setValue(backendName).build());
e.getAttributes().getAttributeMap().put(RawSpanConstants.getValue(Http.HTTP_PATH), org.hypertrace.core.datamodel.AttributeValue.newBuilder().setValue("/abc/v1/book").build());
e.getAttributes().getAttributeMap().put(OTelHttpSemanticConventions.HTTP_SCHEME.getValue(), org.hypertrace.core.datamodel.AttributeValue.newBuilder().setValue("https").build());
StructuredTrace trace = createStructuredTrace(TENANT_ID, e);
enricher.enrichTrace(trace);
// assert that backend has been created
Assertions.assertNotNull(EnrichedSpanUtils.getBackendId(e));
Assertions.assertNotNull(EnrichedSpanUtils.getBackendName(e));
}
use of org.hypertrace.entity.data.service.v1.ByTypeAndIdentifyingAttributes in project hypertrace-ingester by hypertrace.
the class BackendEntityEnricherTest method test_EnrichTrace_ExternalBackendNotResolvedAsServiceExists.
@Test
public void test_EnrichTrace_ExternalBackendNotResolvedAsServiceExists() {
String eventName = "service exists";
String backendName = "external-backend";
String serviceId = "serviceId";
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();
// for broken event service and peer service are different
Event.Builder eventBuilder = createApiExitEvent(EVENT_ID).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));
}
Aggregations