use of org.hypertrace.entity.data.service.v1.AttributeValue in project hypertrace-ingester by hypertrace.
the class JdbcBackendProviderTest method testGetBackendEntity.
@Test
public void testGetBackendEntity() {
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("sql.url", AttributeValue.newBuilder().setValue("jdbc:mysql://mysql:3306/shop").build(), "span.kind", AttributeValue.newBuilder().setValue("client").build(), "sql.query", AttributeValue.newBuilder().setValue("insert into audit_message (message, id) values (?, ?)").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())).build()).setEventName("jdbc.connection.prepare").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();
Entity backendEntity = backendEntityEnricher.resolve(e, structuredTrace, structuredTraceGraph).get().getEntity();
Map<String, org.hypertrace.entity.data.service.v1.AttributeValue> idAttrMap = backendEntity.getIdentifyingAttributesMap();
assertEquals("mysql", idAttrMap.get(Constants.getEntityConstant(BackendAttribute.BACKEND_ATTRIBUTE_HOST)).getValue().getString());
assertEquals("3306", idAttrMap.get(Constants.getEntityConstant(BackendAttribute.BACKEND_ATTRIBUTE_PORT)).getValue().getString());
assertEquals("JDBC", idAttrMap.get(Constants.getEntityConstant(BackendAttribute.BACKEND_ATTRIBUTE_PROTOCOL)).getValue().getString());
assertEquals("mysql", backendEntity.getAttributesMap().get(Constants.getRawSpanConstant(Sql.SQL_DB_TYPE)).getValue().getString());
}
use of org.hypertrace.entity.data.service.v1.AttributeValue in project hypertrace-ingester by hypertrace.
the class KafkaBackendProviderTest method TestOtelBackendEventResolution.
@Test
public void TestOtelBackendEventResolution() {
String broker = "kafka-test.hypertrace.com:9092";
BackendInfo backendInfo = backendEntityEnricher.resolve(getOtelKafkaBackendEvent(broker), structuredTrace, structuredTraceGraph).get();
Entity entity = backendInfo.getEntity();
Assertions.assertEquals(broker, entity.getEntityName());
Map<String, AttributeValue> attributes = backendInfo.getAttributes();
assertEquals(Map.of("BACKEND_OPERATION", AttributeValueCreator.create("receive")), attributes);
}
use of org.hypertrace.entity.data.service.v1.AttributeValue in project entity-service by hypertrace.
the class EntityDataServiceTest method testCreateWithIdentifyingAttributes.
@Test
public void testCreateWithIdentifyingAttributes() {
AttributeValue randomUUIDAttrValue = generateRandomUUIDAttrValue();
Entity entity = Entity.newBuilder().setTenantId(TENANT_ID).setEntityType(EntityType.K8S_POD.name()).setEntityName("Some Service").putIdentifyingAttributes(EntityConstants.getValue(CommonAttribute.COMMON_ATTRIBUTE_EXTERNAL_ID), randomUUIDAttrValue).build();
Entity createdEntity = entityDataServiceClient.upsert(entity);
assertNotNull(createdEntity.getEntityId());
Entity entity1 = Entity.newBuilder().setTenantId(TENANT_ID).setEntityType(EntityType.K8S_POD.name()).setEntityName("Some Service 1").putIdentifyingAttributes(EntityConstants.getValue(CommonAttribute.COMMON_ATTRIBUTE_EXTERNAL_ID), randomUUIDAttrValue).build();
Entity createdEntity1 = entityDataServiceClient.upsert(entity1);
// Should be same entity since identifying attributes are the same
assertEquals(createdEntity.getEntityId(), createdEntity1.getEntityId());
}
use of org.hypertrace.entity.data.service.v1.AttributeValue in project entity-service by hypertrace.
the class EntityDataServiceTest method testUpdateEntityWithPredicateViaUpsertAndMerge.
@Test
public void testUpdateEntityWithPredicateViaUpsertAndMerge() {
// Scope this test to its own tenant for isolation
String TENANT_ID = EntityDataServiceTest.TENANT_ID + "testUpdateEntityWithPredicateViaUpsertAndMerge";
EntityDataServiceBlockingStub entityDataServiceStub = buildStubForTenant(TENANT_ID);
setupEntityTypes(channel, TENANT_ID);
Map<String, AttributeValue> createAttributes = Map.of("some-attr", stringValue("v1"));
Map<String, AttributeValue> updateAttributes = Map.of("some-attr", stringValue("v2"));
// Expect create and the first update to succeed, the second to fail
UpsertCondition condition = UpsertCondition.newBuilder().setPropertyPredicate(Predicate.newBuilder().setAttributeKey("some-attr").setOperator(PredicateOperator.PREDICATE_OPERATOR_EQUALS).setValue(stringValue("v1"))).build();
// V1 entity
Entity entityToCreate = Entity.newBuilder().setTenantId(TENANT_ID).setEntityType(EntityType.K8S_POD.name()).setEntityName("V1 UPDATE PREDICATE POD").putIdentifyingAttributes(EntityConstants.getValue(CommonAttribute.COMMON_ATTRIBUTE_EXTERNAL_ID), generateRandomUUIDAttrValue()).putAllAttributes(createAttributes).build();
// Successful create
Entity createdEntity = entityDataServiceStub.mergeAndUpsertEntity(MergeAndUpsertEntityRequest.newBuilder().setEntity(entityToCreate).setUpsertCondition(condition).build()).getEntity();
assertEquals(stringValue("v1"), createdEntity.getAttributesMap().get("some-attr"));
Entity entityUpdate = entityToCreate.toBuilder().putAllAttributes(updateAttributes).build();
Entity updatedEntity = entityDataServiceStub.mergeAndUpsertEntity(MergeAndUpsertEntityRequest.newBuilder().setEntity(entityUpdate).setUpsertCondition(condition).build()).getEntity();
// Successful update
assertEquals(stringValue("v2"), updatedEntity.getAttributesMap().get("some-attr"));
Entity secondEntityUpdate = entityToCreate.toBuilder().putAttributes("some-new-attr", stringValue("foo")).build();
Entity secondUpdatedEntity = entityDataServiceStub.mergeAndUpsertEntity(MergeAndUpsertEntityRequest.newBuilder().setEntity(secondEntityUpdate).setUpsertCondition(condition).build()).getEntity();
// No change, update rejected
assertFalse(secondUpdatedEntity.getAttributesMap().containsKey("some-new-attr"));
assertEquals(stringValue("v2"), secondUpdatedEntity.getAttributesMap().get("some-attr"));
// V2 Entity
entityToCreate = Entity.newBuilder().setTenantId(TENANT_ID).setEntityId(UUID.randomUUID().toString()).setEntityType(TEST_ENTITY_TYPE_V2).setEntityName("V2 entity predicate update").putAllAttributes(createAttributes).build();
// Successful create
createdEntity = entityDataServiceStub.mergeAndUpsertEntity(MergeAndUpsertEntityRequest.newBuilder().setEntity(entityToCreate).setUpsertCondition(condition).build()).getEntity();
assertEquals(stringValue("v1"), createdEntity.getAttributesMap().get("some-attr"));
entityUpdate = entityToCreate.toBuilder().putAllAttributes(updateAttributes).build();
updatedEntity = entityDataServiceStub.mergeAndUpsertEntity(MergeAndUpsertEntityRequest.newBuilder().setEntity(entityUpdate).setUpsertCondition(condition).build()).getEntity();
// Successful update
assertEquals(stringValue("v2"), updatedEntity.getAttributesMap().get("some-attr"));
secondEntityUpdate = entityToCreate.toBuilder().putAttributes("some-new-attr", stringValue("foo")).build();
secondUpdatedEntity = entityDataServiceStub.mergeAndUpsertEntity(MergeAndUpsertEntityRequest.newBuilder().setEntity(secondEntityUpdate).setUpsertCondition(condition).build()).getEntity();
// No change, update rejected
assertFalse(secondUpdatedEntity.getAttributesMap().containsKey("some-new-attr"));
assertEquals(stringValue("v2"), secondUpdatedEntity.getAttributesMap().get("some-attr"));
}
use of org.hypertrace.entity.data.service.v1.AttributeValue in project entity-service by hypertrace.
the class EntityNormalizerTest method returnsSimpleKeyForV1Entity.
@Test
void returnsSimpleKeyForV1Entity() {
when(this.mockEntityTypeClient.get(V1_ENTITY_TYPE)).thenReturn(Single.error(new RuntimeException()));
// Getting a key for a v1 entity when provided with direct id
assertEquals(new SingleValueKey(TENANT_ID, "id-in"), this.normalizer.getEntityDocKey(TENANT_ID, V1_ENTITY_TYPE, "id-in"));
// Getting a key for a v1 entity whose ID is already set
assertEquals(new SingleValueKey(TENANT_ID, "id-in"), this.normalizer.getEntityDocKey(TENANT_ID, Entity.newBuilder().setEntityType(V1_ENTITY_TYPE).setEntityId("id-in").build()));
// Getting a key for a v1 entity whose ID is not yet generated
Map<String, AttributeValue> valueMap = buildValueMap(Map.of(V1_ID_ATTR.getName(), "foo-value"));
when(this.mockIdAttrCache.getIdentifyingAttributes(TENANT_ID, V1_ENTITY_TYPE)).thenReturn(List.of(V1_ID_ATTR));
when(this.mockIdGenerator.generateEntityId(TENANT_ID, V1_ENTITY_TYPE, valueMap)).thenReturn("generated-id");
assertEquals(new SingleValueKey(TENANT_ID, "generated-id"), this.normalizer.getEntityDocKey(TENANT_ID, Entity.newBuilder().setEntityType(V1_ENTITY_TYPE).putAllIdentifyingAttributes(valueMap).build()));
}
Aggregations