Search in sources :

Example 21 with AttributeValue

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());
}
Also used : Entity(org.hypertrace.entity.data.service.v1.Entity) TestUtil.buildAttributeValue(org.hypertrace.traceenricher.TestUtil.buildAttributeValue) AttributeValue(org.hypertrace.core.datamodel.AttributeValue) Event(org.hypertrace.core.datamodel.Event) Test(org.junit.jupiter.api.Test)

Example 22 with AttributeValue

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);
}
Also used : Entity(org.hypertrace.entity.data.service.v1.Entity) AttributeValue(org.hypertrace.core.datamodel.AttributeValue) BackendInfo(org.hypertrace.traceenricher.enrichment.enrichers.resolver.backend.BackendInfo) Test(org.junit.jupiter.api.Test)

Example 23 with AttributeValue

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());
}
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) Test(org.junit.jupiter.api.Test)

Example 24 with AttributeValue

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"));
}
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) UpsertCondition(org.hypertrace.entity.data.service.v1.MergeAndUpsertEntityRequest.UpsertCondition) EntityDataServiceBlockingStub(org.hypertrace.entity.data.service.v1.EntityDataServiceGrpc.EntityDataServiceBlockingStub) Test(org.junit.jupiter.api.Test)

Example 25 with AttributeValue

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

Aggregations

Test (org.junit.jupiter.api.Test)39 Entity (org.hypertrace.entity.data.service.v1.Entity)37 AttributeValue (org.hypertrace.entity.data.service.v1.AttributeValue)24 AttributeValue (org.hypertrace.core.datamodel.AttributeValue)22 BackendInfo (org.hypertrace.traceenricher.enrichment.enrichers.resolver.backend.BackendInfo)20 Event (org.hypertrace.core.datamodel.Event)12 EnrichedEntity (org.hypertrace.entity.data.service.v1.EnrichedEntity)11 AttributeValue (com.google.devtools.cloudtrace.v2.AttributeValue)10 Test (org.junit.Test)10 HashMap (java.util.HashMap)9 ByTypeAndIdentifyingAttributes (org.hypertrace.entity.data.service.v1.ByTypeAndIdentifyingAttributes)9 TestUtil.buildAttributeValue (org.hypertrace.traceenricher.TestUtil.buildAttributeValue)7 Span (zipkin2.Span)7 AttributesExtractor.toAttributeValue (zipkin2.translation.stackdriver.AttributesExtractor.toAttributeValue)7 ArrayList (java.util.ArrayList)5 List (java.util.List)5 Map (java.util.Map)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 Span (com.google.devtools.cloudtrace.v2.Span)3 TruncatableString (com.google.devtools.cloudtrace.v2.TruncatableString)3