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));
}
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));
}
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);
}
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}");
}
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());
}
Aggregations