use of org.hypertrace.entity.data.service.v1.ByTypeAndIdentifyingAttributes in project hypertrace-ingester by hypertrace.
the class StructuredTracesEnrichmentTest method mockGetServiceEntityMethod.
private void mockGetServiceEntityMethod() {
String[] serviceNames = new String[] { "api_01", "api_02", "api_03" };
for (String serviceName : serviceNames) {
org.hypertrace.entity.data.service.v1.AttributeValue value = org.hypertrace.entity.data.service.v1.AttributeValue.newBuilder().setValue(Value.newBuilder().setString(serviceName)).build();
org.hypertrace.entity.data.service.v1.Entity serviceEntity = org.hypertrace.entity.data.service.v1.Entity.newBuilder().setTenantId(TENANT_ID).setEntityName(serviceName).setEntityId(serviceName + "-id").setEntityType(EntityType.SERVICE.name()).putIdentifyingAttributes(EntityConstants.getValue(CommonAttribute.COMMON_ATTRIBUTE_FQN), value).build();
when(edsClient.getEntitiesByName(TENANT_ID, EntityType.SERVICE.name(), serviceName)).thenReturn(Collections.singletonList(serviceEntity));
ByTypeAndIdentifyingAttributes request = ByTypeAndIdentifyingAttributes.newBuilder().setEntityType(EntityType.SERVICE.name()).putIdentifyingAttributes(EntityConstants.getValue(CommonAttribute.COMMON_ATTRIBUTE_FQN), value).build();
doReturn(serviceEntity).when(edsClient).upsert(serviceEntity);
doReturn(serviceEntity).when(edsClient).getByTypeAndIdentifyingAttributes(TENANT_ID, request);
}
}
use of org.hypertrace.entity.data.service.v1.ByTypeAndIdentifyingAttributes in project entity-service by hypertrace.
the class EdsCacheClientTest method testGetByTypeAndIdentifyingForNull.
@Test
public void testGetByTypeAndIdentifyingForNull() {
String tenantId = "tenant";
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());
when(entityDataServiceClient.getByTypeAndIdentifyingAttributes(anyString(), any())).thenReturn(null);
ByTypeAndIdentifyingAttributes attributes = ByTypeAndIdentifyingAttributes.newBuilder().setEntityType("API").putAllIdentifyingAttributes(identifyingAttributesMap).build();
Entity entity = edsCacheClient.getByTypeAndIdentifyingAttributes(tenantId, attributes);
Assertions.assertNull(entity);
entity = edsCacheClient.getByTypeAndIdentifyingAttributes(tenantId, attributes);
Assertions.assertNull(entity);
verify(entityDataServiceClient, times(2)).getByTypeAndIdentifyingAttributes("tenant", attributes);
verify(entityDataServiceClient, never()).getById("tenant", "entity-12345");
}
use of org.hypertrace.entity.data.service.v1.ByTypeAndIdentifyingAttributes in project entity-service by hypertrace.
the class EdsTypeAndIdAttributesCacheKeyTest method testEqualsHashcode.
@Test
public void testEqualsHashcode() {
Map<String, AttributeValue> identifyingAttributesMap1 = new HashMap<>();
identifyingAttributesMap1.put("entity_name", AttributeValue.newBuilder().setValue(Value.newBuilder().setString("GET /products").build()).build());
identifyingAttributesMap1.put("is_active", AttributeValue.newBuilder().setValue(Value.newBuilder().setBoolean(true).build()).build());
ByTypeAndIdentifyingAttributes attributes1 = ByTypeAndIdentifyingAttributes.newBuilder().setEntityType("API").putAllIdentifyingAttributes(identifyingAttributesMap1).build();
// cacheKey1, cacheKey2 using same input
EdsTypeAndIdAttributesCacheKey cacheKey1 = new EdsTypeAndIdAttributesCacheKey("tenant1", attributes1);
EdsTypeAndIdAttributesCacheKey cacheKey2 = new EdsTypeAndIdAttributesCacheKey("tenant1", attributes1);
Assertions.assertEquals(cacheKey1, cacheKey2);
Assertions.assertEquals(cacheKey1.hashCode(), cacheKey2.hashCode());
// different tenant value
EdsTypeAndIdAttributesCacheKey cacheKey3 = new EdsTypeAndIdAttributesCacheKey("tenant2", attributes1);
Assertions.assertNotEquals(cacheKey1, cacheKey3);
// only entity_type change, and same attributes
ByTypeAndIdentifyingAttributes attributes2 = ByTypeAndIdentifyingAttributes.newBuilder().setEntityType("SERVICE").putAllIdentifyingAttributes(identifyingAttributesMap1).build();
EdsTypeAndIdAttributesCacheKey cacheKey4 = new EdsTypeAndIdAttributesCacheKey("tenant1", attributes2);
Assertions.assertNotEquals(cacheKey1, cacheKey4);
// entity_type is same, but attributes are different
Map<String, AttributeValue> identifyingAttributesMap2 = new HashMap<>();
identifyingAttributesMap1.put("entity_name", AttributeValue.newBuilder().setValue(Value.newBuilder().setString("GET /books").build()).build());
identifyingAttributesMap1.put("is_active", AttributeValue.newBuilder().setValue(Value.newBuilder().setBoolean(false).build()).build());
ByTypeAndIdentifyingAttributes attributes3 = ByTypeAndIdentifyingAttributes.newBuilder().setEntityType("API").putAllIdentifyingAttributes(identifyingAttributesMap2).build();
EdsTypeAndIdAttributesCacheKey cacheKey5 = new EdsTypeAndIdAttributesCacheKey("tenant1", attributes3);
Assertions.assertNotEquals(cacheKey1, cacheKey5);
}
use of org.hypertrace.entity.data.service.v1.ByTypeAndIdentifyingAttributes in project entity-service by hypertrace.
the class EntityDataServiceTest method testEntityGetByTypeAndIdentifyingProperties.
@Test
public void testEntityGetByTypeAndIdentifyingProperties() {
AttributeValue identifyingAttrValue = AttributeValue.newBuilder().setValue(Value.newBuilder().setString("value1-" + System.nanoTime()).build()).build();
Entity entity = Entity.newBuilder().setTenantId(TENANT_ID).setEntityType(EntityType.K8S_POD.name()).setEntityName("Some Service").putIdentifyingAttributes(EntityConstants.getValue(CommonAttribute.COMMON_ATTRIBUTE_EXTERNAL_ID), identifyingAttrValue).build();
Entity createdEntity = entityDataServiceClient.upsert(entity);
assertNotNull(createdEntity);
assertNotNull(createdEntity.getEntityId().trim());
ByTypeAndIdentifyingAttributes byTypeAndIdentifyingAttributes = ByTypeAndIdentifyingAttributes.newBuilder().setEntityType(EntityType.K8S_POD.name()).putIdentifyingAttributes(EntityConstants.getValue(CommonAttribute.COMMON_ATTRIBUTE_EXTERNAL_ID), identifyingAttrValue).build();
Entity foundEntity = entityDataServiceClient.getByTypeAndIdentifyingAttributes(TENANT_ID, byTypeAndIdentifyingAttributes);
assertEquals(createdEntity, foundEntity);
}
Aggregations