use of org.hypertrace.entity.data.service.v1.EnrichedEntity in project entity-service by hypertrace.
the class EntityDataServiceTest method upsertAndVerify.
private void upsertAndVerify(EnrichedEntity enrichedEntity) {
EnrichedEntity createdEntity = entityDataServiceClient.upsertEnrichedEntity(enrichedEntity);
assertNotNull(enrichedEntity);
assertNotNull(createdEntity.getEntityId().trim());
EnrichedEntity actualBackendEntity = entityDataServiceClient.getEnrichedEntityById(TENANT_ID, createdEntity.getEntityId());
assertEquals(createdEntity, actualBackendEntity);
}
use of org.hypertrace.entity.data.service.v1.EnrichedEntity in project entity-service by hypertrace.
the class EntityDataServiceTest method testUpsertAndGetEnrichedEntity.
@Test
public void testUpsertAndGetEnrichedEntity() {
EnrichedEntity entity = EnrichedEntity.newBuilder().setTenantId(TENANT_ID).setEntityType(EntityType.K8S_POD.name()).setEntityName("Some Service").setEntityId(UUID.randomUUID().toString()).putIdentifyingAttributes(EntityConstants.getValue(CommonAttribute.COMMON_ATTRIBUTE_EXTERNAL_ID), generateRandomUUIDAttrValue()).build();
upsertAndVerify(entity);
}
use of org.hypertrace.entity.data.service.v1.EnrichedEntity in project entity-service by hypertrace.
the class EntityDataServiceImpl method upsertEnrichedEntities.
@Override
public void upsertEnrichedEntities(EnrichedEntities request, StreamObserver<Empty> responseObserver) {
String tenantId = RequestContext.CURRENT.get().getTenantId().orElse(null);
if (isNull(tenantId)) {
responseObserver.onError(new ServiceException("Tenant id is missing in the request."));
return;
}
for (EnrichedEntity entity : request.getEntitiesList()) {
if (StringUtils.isEmpty(entity.getEntityType())) {
LOG.info("{}. Invalid upsertEnrichedEntities request:{}", entity, ErrorMessages.ENTITY_TYPE_EMPTY);
responseObserver.onError(new RuntimeException(ErrorMessages.ENTITY_TYPE_EMPTY));
return;
}
if (StringUtils.isEmpty(entity.getEntityId())) {
LOG.info("{}. Invalid upsertEnrichedEntities request:{}", entity, ErrorMessages.ENTITY_ID_EMPTY);
responseObserver.onError(new RuntimeException(ErrorMessages.ENTITY_ID_EMPTY));
return;
}
}
Map<Key, EnrichedEntity> entities = request.getEntitiesList().stream().collect(Collectors.toUnmodifiableMap(entity -> this.entityNormalizer.getEntityDocKey(tenantId, entity.getEntityType(), entity.getEntityId()), Function.identity()));
upsertEntities(entities, enrichedEntitiesCollection, responseObserver);
}
use of org.hypertrace.entity.data.service.v1.EnrichedEntity in project entity-service by hypertrace.
the class EdsCacheClient method initCache.
private void initCache(EntityServiceClientCacheConfig cacheConfig, Executor executor) {
this.enrichedEntityCache = CacheBuilder.newBuilder().refreshAfterWrite(cacheConfig.getEnrichedEntityCacheRefreshMs(), TimeUnit.MILLISECONDS).expireAfterWrite(cacheConfig.getEnrichedEntityCacheExpiryMs(), TimeUnit.MILLISECONDS).maximumSize(cacheConfig.getEnrichedEntityMaxCacheSize()).recordStats().build(CacheLoader.asyncReloading(new CacheLoader<>() {
public EnrichedEntity load(@Nonnull EdsCacheKey key) throws Exception {
EnrichedEntity enrichedEntity = client.getEnrichedEntityById(key.tenantId, key.entityId);
if (enrichedEntity == null) {
throw new NotFoundException("Enriched entity not found");
}
return enrichedEntity;
}
}, executor));
this.entityCache = CacheBuilder.newBuilder().refreshAfterWrite(cacheConfig.getEntityCacheRefreshMs(), TimeUnit.MILLISECONDS).expireAfterWrite(cacheConfig.getEntityCacheExpiryMs(), TimeUnit.MILLISECONDS).maximumSize(cacheConfig.getEntityMaxCacheSize()).recordStats().build(CacheLoader.asyncReloading(new CacheLoader<>() {
public Entity load(@Nonnull EdsCacheKey key) throws Exception {
Entity entity = client.getById(key.tenantId, key.entityId);
if (entity == null) {
throw new NotFoundException("Entity not found");
}
return entity;
}
}, executor));
this.entityIdsCache = CacheBuilder.newBuilder().refreshAfterWrite(cacheConfig.getEntityIdsCacheRefreshMs(), TimeUnit.MILLISECONDS).expireAfterWrite(cacheConfig.getEntityIdsCacheExpiryMs(), TimeUnit.MILLISECONDS).maximumSize(cacheConfig.getEntityIdsMaxCacheSize()).recordStats().build(CacheLoader.asyncReloading(new CacheLoader<>() {
public String load(@Nonnull EdsTypeAndIdAttributesCacheKey key) throws Exception {
Entity entity = client.getByTypeAndIdentifyingAttributes(key.tenantId, key.byTypeAndIdentifyingAttributes);
if (entity == null) {
throw new NotFoundException("Entity not found!!");
}
entityCache.put(new EdsCacheKey(entity.getTenantId(), entity.getEntityId()), entity);
return entity.getEntityId();
}
}, executor));
PlatformMetricsRegistry.registerCache(this.getClass().getName() + ".enrichedEntityCache", enrichedEntityCache, Collections.emptyMap());
PlatformMetricsRegistry.registerCache(this.getClass().getName() + ".entityCache", entityCache, Collections.emptyMap());
PlatformMetricsRegistry.registerCache(this.getClass().getName() + ".entityIdsCache", entityIdsCache, Collections.emptyMap());
}
use of org.hypertrace.entity.data.service.v1.EnrichedEntity in project entity-service by hypertrace.
the class EdsCacheClientTest method testGetEnrichedEntityById.
@Test
public void testGetEnrichedEntityById() {
String tenantId = "tenant";
String enrichedEntityId = "enriched-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());
EnrichedEntity enrichedEntity = EnrichedEntity.newBuilder().setEntityId(enrichedEntityId).setEntityType("API").setEntityName("GET /products").putAllIdentifyingAttributes(identifyingAttributesMap).build();
when(entityDataServiceClient.getEnrichedEntityById(anyString(), anyString())).thenReturn(enrichedEntity);
edsCacheClient.getEnrichedEntityById(tenantId, enrichedEntityId);
edsCacheClient.getEnrichedEntityById(tenantId, enrichedEntityId);
verify(entityDataServiceClient, times(1)).getEnrichedEntityById("tenant", "enriched-12345");
}
Aggregations