use of io.opentelemetry.proto.metrics.v1.Gauge in project hypertrace-ingester by hypertrace.
the class MetricsProcessorTest method testMetricsProcessorTopology.
@Test
@SetEnvironmentVariable(key = "SERVICE_NAME", value = "hypertrace-metrics-processor")
public void testMetricsProcessorTopology() {
// prepare stream properties
Map<String, Object> mergedProps = new HashMap<>();
underTest.getBaseStreamsConfig().forEach(mergedProps::put);
underTest.getStreamsConfig(underTestConfig).forEach(mergedProps::put);
mergedProps.put(underTest.getJobConfigKey(), underTestConfig);
StreamsBuilder streamsBuilder = underTest.buildTopology(mergedProps, new StreamsBuilder(), new HashMap<>());
Properties props = new Properties();
mergedProps.forEach(props::put);
// create topology test driver, and i/o topics
TopologyTestDriver topologyTestDriver = new TopologyTestDriver(streamsBuilder.build(), props);
TestInputTopic<byte[], ResourceMetrics> inputTopic = topologyTestDriver.createInputTopic(underTestConfig.getString(MetricsProcessor.INPUT_TOPIC_CONFIG_KEY), Serdes.ByteArray().serializer(), new OtlpMetricsSerde().serializer());
TestOutputTopic outputTopic = topologyTestDriver.createOutputTopic(underTestConfig.getString(MetricsProcessor.OUTPUT_TOPIC_CONFIG_KEY), Serdes.ByteArray().deserializer(), new OtlpMetricsSerde().deserializer());
// create resource metrics and add into pipeline
ResourceMetrics inputResourceMetrics = getTestMetricsGauge("num_calls", "number of calls", 20L);
inputTopic.pipeInput(inputResourceMetrics);
ResourceMetrics outputResourceMetrics = (ResourceMetrics) outputTopic.readValue();
// verification
Assertions.assertNotNull(outputResourceMetrics);
Assertions.assertNotNull(outputResourceMetrics.getResource());
Assertions.assertEquals(1, outputResourceMetrics.getInstrumentationLibraryMetricsCount());
Assertions.assertEquals(1, outputResourceMetrics.getInstrumentationLibraryMetrics(0).getMetricsCount());
Assertions.assertEquals("num_calls", outputResourceMetrics.getInstrumentationLibraryMetrics(0).getMetrics(0).getName());
// data points verification
Gauge outGauge = outputResourceMetrics.getInstrumentationLibraryMetrics(0).getMetrics(0).getGauge();
Assertions.assertNotNull(outGauge);
Assertions.assertEquals(1, outGauge.getDataPointsCount());
Assertions.assertEquals(1634119810000L, TimeUnit.MILLISECONDS.convert(outGauge.getDataPoints(0).getTimeUnixNano(), TimeUnit.NANOSECONDS));
Assertions.assertEquals(3, outGauge.getDataPoints(0).getAttributesCount());
Assertions.assertEquals(20L, outGauge.getDataPoints(0).getAsInt());
}
use of io.opentelemetry.proto.metrics.v1.Gauge in project hypertrace-ingester by hypertrace.
the class OtlpProtoToMetricDataConverter method toGaugeMetricData.
private static MetricData toGaugeMetricData(Resource resource, InstrumentationLibraryInfo instrumentationLibraryInfo, Metric metric) {
Gauge gaugeMetric = metric.getGauge();
DoubleGaugeData data = DoubleGaugeData.create(toDoublePointData(gaugeMetric.getDataPointsList()));
return MetricData.createDoubleGauge(resource, instrumentationLibraryInfo, metric.getName(), metric.getDescription(), metric.getUnit(), data);
}
use of io.opentelemetry.proto.metrics.v1.Gauge in project hypertrace-ingester by hypertrace.
the class InMemoryMetricsProducerTest method testAddMetricDataAndCollectData.
@Test
public void testAddMetricDataAndCollectData() {
// insert 1 data
ResourceMetrics resourceMetrics = prepareMetric("int_num_calls", "number of calls", 1, "Gauge");
List<MetricData> inMetricData = OtlpProtoToMetricDataConverter.toMetricData(resourceMetrics);
Assertions.assertTrue(underTest.addMetricData(inMetricData));
// insert 2nd data
ResourceMetrics resourceMetrics1 = prepareMetric("double_num_calls", "number of calls", 2.5, "Gauge");
List<MetricData> inMetricData1 = OtlpProtoToMetricDataConverter.toMetricData(resourceMetrics1);
// assert that can't add
Assertions.assertTrue(underTest.addMetricData(inMetricData1));
// insert 3nd data
ResourceMetrics resourceMetrics2 = prepareMetric("double_num_calls", "number of calls", 3.5, "Gauge");
List<MetricData> inMetricData2 = OtlpProtoToMetricDataConverter.toMetricData(resourceMetrics2);
// assert that can't add
Assertions.assertFalse(underTest.addMetricData(inMetricData2));
// Now read data
List<MetricData> outData = (List) underTest.collectAllMetrics();
Assertions.assertEquals(1, outData.size());
Assertions.assertEquals(inMetricData.get(0), outData.get(0));
outData = (List) underTest.collectAllMetrics();
Assertions.assertEquals(1, outData.size());
Assertions.assertEquals(inMetricData1.get(0), outData.get(0));
outData = (List) underTest.collectAllMetrics();
Assertions.assertEquals(0, outData.size());
// reinsert 3rd data point
Assertions.assertTrue(underTest.addMetricData(inMetricData2));
outData = (List) underTest.collectAllMetrics();
Assertions.assertEquals(1, outData.size());
Assertions.assertEquals(inMetricData2.get(0), outData.get(0));
}
use of io.opentelemetry.proto.metrics.v1.Gauge in project hypertrace-ingester by hypertrace.
the class ResourceMetricsUtils method prepareMetric.
public static ResourceMetrics prepareMetric(String metricName, String metricDesc, Number value, String type) {
ResourceMetrics.Builder resourceMetricsBuilder = ResourceMetrics.newBuilder();
resourceMetricsBuilder.setResource(prepareResource());
Metric metric;
if (type.equals("Gauge")) {
metric = prepareGaugeMetric(metricName, metricDesc, value);
} else {
metric = prepareSumMetric(metricName, metricDesc, value);
}
resourceMetricsBuilder.addInstrumentationLibraryMetrics(InstrumentationLibraryMetrics.newBuilder().addMetrics(metric).setInstrumentationLibrary(InstrumentationLibrary.newBuilder().setName("Generated").build()).build());
return resourceMetricsBuilder.build();
}
use of io.opentelemetry.proto.metrics.v1.Gauge in project data-prepper by opensearch-project.
the class MetricsPluginGaugeTest method test.
@Test
public void test() throws JsonProcessingException {
NumberDataPoint.Builder p1 = NumberDataPoint.newBuilder().setAsInt(4);
Gauge gauge = Gauge.newBuilder().addDataPoints(p1).build();
io.opentelemetry.proto.metrics.v1.Metric.Builder metric = io.opentelemetry.proto.metrics.v1.Metric.newBuilder().setGauge(gauge).setUnit("seconds").setName("name").setDescription("description");
InstrumentationLibraryMetrics isntLib = InstrumentationLibraryMetrics.newBuilder().addMetrics(metric).build();
Resource resource = Resource.newBuilder().addAttributes(KeyValue.newBuilder().setKey("service.name").setValue(AnyValue.newBuilder().setStringValue("service").build())).build();
ResourceMetrics resourceMetrics = ResourceMetrics.newBuilder().addInstrumentationLibraryMetrics(isntLib).setResource(resource).build();
ExportMetricsServiceRequest exportMetricRequest = ExportMetricsServiceRequest.newBuilder().addResourceMetrics(resourceMetrics).build();
Record<ExportMetricsServiceRequest> record = new Record<>(exportMetricRequest);
Collection<Record<? extends Metric>> records = rawProcessor.doExecute(Collections.singletonList(record));
List<Record<? extends Metric>> list = new ArrayList<>(records);
Record<? extends Metric> dataPrepperResult = list.get(0);
ObjectMapper objectMapper = new ObjectMapper();
Map map = objectMapper.readValue(dataPrepperResult.getData().toJsonString(), Map.class);
assertSumProcessing(map);
}
Aggregations