Search in sources :

Example 6 with ByTypeAndIdentifyingAttributes

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);
    }
}
Also used : ByTypeAndIdentifyingAttributes(org.hypertrace.entity.data.service.v1.ByTypeAndIdentifyingAttributes)

Example 7 with ByTypeAndIdentifyingAttributes

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");
}
Also used : Entity(org.hypertrace.entity.data.service.v1.Entity) EnrichedEntity(org.hypertrace.entity.data.service.v1.EnrichedEntity) AttributeValue(org.hypertrace.entity.data.service.v1.AttributeValue) ByTypeAndIdentifyingAttributes(org.hypertrace.entity.data.service.v1.ByTypeAndIdentifyingAttributes) HashMap(java.util.HashMap) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 8 with ByTypeAndIdentifyingAttributes

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);
}
Also used : AttributeValue(org.hypertrace.entity.data.service.v1.AttributeValue) ByTypeAndIdentifyingAttributes(org.hypertrace.entity.data.service.v1.ByTypeAndIdentifyingAttributes) HashMap(java.util.HashMap) Test(org.junit.jupiter.api.Test)

Example 9 with ByTypeAndIdentifyingAttributes

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);
}
Also used : EnrichedEntity(org.hypertrace.entity.data.service.v1.EnrichedEntity) Entity(org.hypertrace.entity.data.service.v1.Entity) AttributeValue(org.hypertrace.entity.data.service.v1.AttributeValue) ByTypeAndIdentifyingAttributes(org.hypertrace.entity.data.service.v1.ByTypeAndIdentifyingAttributes) Test(org.junit.jupiter.api.Test)

Aggregations

ByTypeAndIdentifyingAttributes (org.hypertrace.entity.data.service.v1.ByTypeAndIdentifyingAttributes)9 AttributeValue (org.hypertrace.entity.data.service.v1.AttributeValue)8 Test (org.junit.jupiter.api.Test)7 Entity (org.hypertrace.entity.data.service.v1.Entity)4 HashMap (java.util.HashMap)3 Event (org.hypertrace.core.datamodel.Event)3 StructuredTrace (org.hypertrace.core.datamodel.StructuredTrace)3 EnrichedEntity (org.hypertrace.entity.data.service.v1.EnrichedEntity)3 AbstractAttributeEnricherTest (org.hypertrace.traceenricher.enrichment.enrichers.AbstractAttributeEnricherTest)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2