Search in sources :

Example 61 with AttributeValue

use of org.hypertrace.core.datamodel.AttributeValue in project hypertrace-ingester by hypertrace.

the class SpanTypeAttributeEnricherTest method test_getProtocolName_Otelgrpc_shouldReturnGrpc.

@Test
public void test_getProtocolName_Otelgrpc_shouldReturnGrpc() {
    Map<String, AttributeValue> map = new HashMap<>();
    map.put(Constants.getRawSpanConstant(Http.HTTP_REQUEST_METHOD), AttributeValue.newBuilder().setValue("GET").build());
    Event e = createEvent(map, new HashMap<>());
    e.setRpc(Rpc.newBuilder().setSystem("grpc").build());
    addAttribute(e, OTEL_SPAN_TAG_RPC_SYSTEM.getValue(), "grpc");
    Assertions.assertEquals(Protocol.PROTOCOL_GRPC, SpanTypeAttributeEnricher.getProtocolName(e));
}
Also used : AttributeValue(org.hypertrace.core.datamodel.AttributeValue) HashMap(java.util.HashMap) Event(org.hypertrace.core.datamodel.Event) Test(org.junit.jupiter.api.Test)

Example 62 with AttributeValue

use of org.hypertrace.core.datamodel.AttributeValue in project hypertrace-ingester by hypertrace.

the class SpanTypeAttributeEnricherTest method test_getProtocolName_OTgrpc_shouldReturnGrpc.

@Test
public void test_getProtocolName_OTgrpc_shouldReturnGrpc() {
    Map<String, AttributeValue> map = new HashMap<>();
    map.put(Constants.getRawSpanConstant(OTSpanTag.OT_SPAN_TAG_COMPONENT), AttributeValue.newBuilder().setValue(Constants.getEnrichedSpanConstant(Protocol.PROTOCOL_GRPC)).build());
    map.put(Constants.getRawSpanConstant(Http.HTTP_REQUEST_METHOD), AttributeValue.newBuilder().setValue("GET").build());
    Event e = createEvent(map, new HashMap<>());
    Assertions.assertEquals(Protocol.PROTOCOL_GRPC, SpanTypeAttributeEnricher.getProtocolName(e));
    SpanTypeAttributeEnricher enricher = new SpanTypeAttributeEnricher();
    enricher.enrichEvent(null, e);
    Assertions.assertEquals(Protocol.PROTOCOL_GRPC, EnrichedSpanUtils.getProtocol(e));
}
Also used : AttributeValue(org.hypertrace.core.datamodel.AttributeValue) HashMap(java.util.HashMap) Event(org.hypertrace.core.datamodel.Event) Test(org.junit.jupiter.api.Test)

Example 63 with AttributeValue

use of org.hypertrace.core.datamodel.AttributeValue in project hypertrace-ingester by hypertrace.

the class EntityAvroConverterTest method testConvertToAvroEntity.

@Test
public void testConvertToAvroEntity() {
    Map<String, org.hypertrace.entity.data.service.v1.AttributeValue> attributeValueMap = new HashMap<>();
    attributeValueMap.put("attr1", org.hypertrace.entity.data.service.v1.AttributeValue.newBuilder().setValue(Value.newBuilder().setString("v1")).build());
    attributeValueMap.put("attr2", org.hypertrace.entity.data.service.v1.AttributeValue.newBuilder().setValue(Value.newBuilder().setBoolean(true)).build());
    attributeValueMap.put("attr3", org.hypertrace.entity.data.service.v1.AttributeValue.newBuilder().setValue(Value.newBuilder().setInt(23)).build());
    attributeValueMap.put("attr4", org.hypertrace.entity.data.service.v1.AttributeValue.newBuilder().setValueList(AttributeValueList.newBuilder().addValues(org.hypertrace.entity.data.service.v1.AttributeValue.newBuilder().setValue(Value.newBuilder().setString("l1"))).addValues(org.hypertrace.entity.data.service.v1.AttributeValue.newBuilder().setValue(Value.newBuilder().setString("l2"))).addValues(org.hypertrace.entity.data.service.v1.AttributeValue.newBuilder().setValue(Value.newBuilder().setString("l3"))).addValues(org.hypertrace.entity.data.service.v1.AttributeValue.newBuilder().setValue(Value.newBuilder().setBytes(ByteString.copyFrom("l4".getBytes()))))).build());
    attributeValueMap.put("attr5", org.hypertrace.entity.data.service.v1.AttributeValue.newBuilder().setValue(Value.newBuilder().setBytes(ByteString.copyFrom("test-bytes".getBytes()))).build());
    attributeValueMap.put("attr6", org.hypertrace.entity.data.service.v1.AttributeValue.newBuilder().setValue(Value.newBuilder().setDouble(33.0)).build());
    attributeValueMap.put("attr7", org.hypertrace.entity.data.service.v1.AttributeValue.newBuilder().setValue(Value.newBuilder().setFloat(18.0f)).build());
    attributeValueMap.put("attr8", org.hypertrace.entity.data.service.v1.AttributeValue.newBuilder().setValue(Value.newBuilder().setTimestamp(46)).build());
    attributeValueMap.put("attr9", org.hypertrace.entity.data.service.v1.AttributeValue.newBuilder().setValue(Value.newBuilder()).build());
    attributeValueMap.put("attr10", org.hypertrace.entity.data.service.v1.AttributeValue.newBuilder().setValueMap(AttributeValueMap.newBuilder().putAllValues(Map.of("k1", org.hypertrace.entity.data.service.v1.AttributeValue.newBuilder().setValue(Value.newBuilder().setString("v11")).build(), "k2", org.hypertrace.entity.data.service.v1.AttributeValue.newBuilder().setValue(Value.newBuilder().setString("v12")).build()))).build());
    attributeValueMap.put("attr11", org.hypertrace.entity.data.service.v1.AttributeValue.newBuilder().setValue(Value.newBuilder().setLong(37)).build());
    org.hypertrace.entity.data.service.v1.Entity entity = org.hypertrace.entity.data.service.v1.Entity.newBuilder().setEntityId("entity-id").setEntityName("entity-name").setEntityType("entity-type").setTenantId("entity-tenant-id").putAllAttributes(attributeValueMap).build();
    Entity avroEntity1 = EntityAvroConverter.convertToAvroEntity(entity, false);
    assertEquals(Entity.newBuilder().setEntityId("entity-id").setEntityName("entity-name").setEntityType("entity-type").setCustomerId("entity-tenant-id").build(), avroEntity1);
    Entity avroEntity2 = EntityAvroConverter.convertToAvroEntity(entity, true);
    assertEquals(Entity.newBuilder().setEntityId("entity-id").setEntityName("entity-name").setEntityType("entity-type").setCustomerId("entity-tenant-id").setAttributesBuilder(Attributes.newBuilder().setAttributeMap(Map.of("attr1", AttributeValue.newBuilder().setValue("v1").build(), "attr2", AttributeValue.newBuilder().setValue("true").build(), "attr3", AttributeValue.newBuilder().setValue("23").build(), "attr4", AttributeValue.newBuilder().setValueList(List.of("l1", "l2", "l3", HexUtils.getHex("l4".getBytes()))).build(), "attr5", AttributeValue.newBuilder().setBinaryValue(ByteBuffer.wrap("test-bytes".getBytes())).build(), "attr6", AttributeValue.newBuilder().setValue("33.0").build(), "attr7", AttributeValue.newBuilder().setValue("18.0").build(), "attr8", AttributeValue.newBuilder().setValue("46").build(), "attr11", AttributeValue.newBuilder().setValue("37").build()))).build(), avroEntity2);
}
Also used : Entity(org.hypertrace.core.datamodel.Entity) AttributeValue(org.hypertrace.core.datamodel.AttributeValue) HashMap(java.util.HashMap) ByteString(com.google.protobuf.ByteString) Test(org.junit.jupiter.api.Test)

Example 64 with AttributeValue

use of org.hypertrace.core.datamodel.AttributeValue in project hypertrace-ingester by hypertrace.

the class AvroToJsonLoggerTest method testLogAvro.

@Test
public void testLogAvro() {
    String fmt = "Testing logging {}";
    Logger logger = mock(Logger.class);
    when(logger.isDebugEnabled()).thenReturn(false);
    AttributeValue attributeValue = AttributeValue.newBuilder().setValue("test-val").build();
    AvroToJsonLogger.log(logger, "Testing logging {}", attributeValue);
    verify(logger, never()).debug(eq(fmt), anyString());
    when(logger.isDebugEnabled()).thenReturn(true);
    AvroToJsonLogger.log(logger, "Testing logging {}", attributeValue);
    AvroToJsonLogger.log(logger, "Testing logging {}", attributeValue);
    verify(logger, times(2)).debug(fmt, "{\"value\":{\"string\":\"test-val\"},\"binary_value\":null,\"value_list\":null,\"value_map\":null}");
}
Also used : AttributeValue(org.hypertrace.core.datamodel.AttributeValue) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Logger(org.slf4j.Logger) Test(org.junit.jupiter.api.Test)

Example 65 with AttributeValue

use of org.hypertrace.core.datamodel.AttributeValue in project hypertrace-ingester by hypertrace.

the class ErrorsAndExceptionsEnricherTest method test_failStatus_shouldGetError.

@Test
public void test_failStatus_shouldGetError() {
    ErrorsAndExceptionsEnricher enricher = new ErrorsAndExceptionsEnricher();
    Event e1 = createMockEvent();
    Map<String, AttributeValue> attributeValueMap = e1.getAttributes().getAttributeMap();
    attributeValueMap.put(Constants.getEnrichedSpanConstant(API_STATUS), AttributeValue.newBuilder().setValue(Constants.getEnrichedSpanConstant(ApiStatus.API_STATUS_FAIL)).build());
    enricher.enrichEvent(null, e1);
    Assertions.assertEquals(1.0d, e1.getMetrics().getMetricMap().get(Constants.getEnrichedSpanConstant(ErrorMetrics.ERROR_METRICS_ERROR_COUNT)).getValue());
}
Also used : AttributeValue(org.hypertrace.core.datamodel.AttributeValue) Event(org.hypertrace.core.datamodel.Event) Test(org.junit.jupiter.api.Test)

Aggregations

AttributeValue (org.hypertrace.core.datamodel.AttributeValue)84 Test (org.junit.jupiter.api.Test)65 Event (org.hypertrace.core.datamodel.Event)53 BackendInfo (org.hypertrace.traceenricher.enrichment.enrichers.resolver.backend.BackendInfo)24 Entity (org.hypertrace.entity.data.service.v1.Entity)22 HashMap (java.util.HashMap)19 TestUtil.buildAttributeValue (org.hypertrace.traceenricher.TestUtil.buildAttributeValue)11 AvroBuilderCache.fastNewBuilder (org.hypertrace.core.datamodel.shared.AvroBuilderCache.fastNewBuilder)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Map (java.util.Map)3 EventRef (org.hypertrace.core.datamodel.EventRef)3 StructuredTrace (org.hypertrace.core.datamodel.StructuredTrace)3 Attributes (org.hypertrace.core.datamodel.Attributes)2 MetricValue (org.hypertrace.core.datamodel.MetricValue)2 RawSpan (org.hypertrace.core.datamodel.RawSpan)2 SpanEventView (org.hypertrace.viewgenerator.api.SpanEventView)2 ImmutableList (com.google.common.collect.ImmutableList)1 ByteString (com.google.protobuf.ByteString)1 ProtocolStringList (com.google.protobuf.ProtocolStringList)1