use of io.opentelemetry.proto.metrics.v1.Sum in project opentelemetry-java by open-telemetry.
the class OtlpExporterIntegrationTest method testMetricExport.
private static void testMetricExport(MetricExporter metricExporter) {
MetricReaderFactory reader = PeriodicMetricReader.builder(metricExporter).setInterval(Duration.ofSeconds(5)).newMetricReaderFactory();
SdkMeterProvider meterProvider = SdkMeterProvider.builder().setResource(RESOURCE).registerMetricReader(reader).build();
Meter meter = meterProvider.meterBuilder(OtlpExporterIntegrationTest.class.getName()).build();
LongCounter longCounter = meter.counterBuilder("my-counter").build();
longCounter.add(100, Attributes.builder().put("key", "value").build());
try {
await().atMost(Duration.ofSeconds(30)).untilAsserted(() -> assertThat(grpcServer.metricRequests).hasSize(1));
} finally {
meterProvider.close();
}
ExportMetricsServiceRequest request = grpcServer.metricRequests.get(0);
assertThat(request.getResourceMetricsCount()).isEqualTo(1);
ResourceMetrics resourceMetrics = request.getResourceMetrics(0);
assertThat(resourceMetrics.getResource().getAttributesList()).contains(KeyValue.newBuilder().setKey(ResourceAttributes.SERVICE_NAME.getKey()).setValue(AnyValue.newBuilder().setStringValue("integration test").build()).build());
assertThat(resourceMetrics.getInstrumentationLibraryMetricsCount()).isEqualTo(1);
InstrumentationLibraryMetrics ilMetrics = resourceMetrics.getInstrumentationLibraryMetrics(0);
assertThat(ilMetrics.getInstrumentationLibrary().getName()).isEqualTo(OtlpExporterIntegrationTest.class.getName());
assertThat(ilMetrics.getMetricsCount()).isEqualTo(1);
Metric metric = ilMetrics.getMetrics(0);
assertThat(metric.getName()).isEqualTo("my-counter");
assertThat(metric.getDataCase()).isEqualTo(Metric.DataCase.SUM);
Sum sum = metric.getSum();
assertThat(sum.getAggregationTemporality()).isEqualTo(AggregationTemporality.AGGREGATION_TEMPORALITY_CUMULATIVE);
assertThat(sum.getDataPointsCount()).isEqualTo(1);
NumberDataPoint dataPoint = sum.getDataPoints(0);
assertThat(dataPoint.getAsInt()).isEqualTo(100);
assertThat(dataPoint.getAttributesList()).isEqualTo(Collections.singletonList(KeyValue.newBuilder().setKey("key").setValue(AnyValue.newBuilder().setStringValue("value").build()).build()));
}
use of io.opentelemetry.proto.metrics.v1.Sum in project opentelemetry-java by open-telemetry.
the class ExponentialHistogramDataPointMarshaler method calculateSize.
private static int calculateSize(long startTimeUnixNano, long timeUnixNano, int scale, long count, double sum, long zeroCount, ExponentialHistogramBucketsMarshaler positiveBucketMarshaler, ExponentialHistogramBucketsMarshaler negativeBucketMarshaler, ExemplarMarshaler[] exemplarMarshalers, KeyValueMarshaler[] attributesMarshalers) {
int size = 0;
size += MarshalerUtil.sizeFixed64(ExponentialHistogramDataPoint.START_TIME_UNIX_NANO, startTimeUnixNano);
size += MarshalerUtil.sizeFixed64(ExponentialHistogramDataPoint.TIME_UNIX_NANO, timeUnixNano);
size += MarshalerUtil.sizeSInt32(ExponentialHistogramDataPoint.SCALE, scale);
size += MarshalerUtil.sizeFixed64(ExponentialHistogramDataPoint.COUNT, count);
size += MarshalerUtil.sizeDouble(ExponentialHistogramDataPoint.SUM, sum);
size += MarshalerUtil.sizeFixed64(ExponentialHistogramDataPoint.ZERO_COUNT, zeroCount);
size += MarshalerUtil.sizeMessage(ExponentialHistogramDataPoint.POSITIVE, positiveBucketMarshaler);
size += MarshalerUtil.sizeMessage(ExponentialHistogramDataPoint.NEGATIVE, negativeBucketMarshaler);
size += MarshalerUtil.sizeRepeatedMessage(ExponentialHistogramDataPoint.EXEMPLARS, exemplarMarshalers);
size += MarshalerUtil.sizeRepeatedMessage(ExponentialHistogramDataPoint.ATTRIBUTES, attributesMarshalers);
return size;
}
use of io.opentelemetry.proto.metrics.v1.Sum in project opentelemetry-java by open-telemetry.
the class SummaryDataPointMarshaler method calculateSize.
private static int calculateSize(long startTimeUnixNano, long timeUnixNano, long count, double sum, ValueAtQuantileMarshaler[] quantileValues, KeyValueMarshaler[] attributes) {
int size = 0;
size += MarshalerUtil.sizeFixed64(SummaryDataPoint.START_TIME_UNIX_NANO, startTimeUnixNano);
size += MarshalerUtil.sizeFixed64(SummaryDataPoint.TIME_UNIX_NANO, timeUnixNano);
size += MarshalerUtil.sizeFixed64(SummaryDataPoint.COUNT, count);
size += MarshalerUtil.sizeDouble(SummaryDataPoint.SUM, sum);
size += MarshalerUtil.sizeRepeatedMessage(SummaryDataPoint.QUANTILE_VALUES, quantileValues);
size += MarshalerUtil.sizeRepeatedMessage(SummaryDataPoint.ATTRIBUTES, attributes);
return size;
}
use of io.opentelemetry.proto.metrics.v1.Sum in project opentelemetry-java by open-telemetry.
the class HistogramDataPointMarshaler method calculateSize.
private static int calculateSize(long startTimeUnixNano, long timeUnixNano, long count, double sum, List<Long> bucketCounts, List<Double> explicitBounds, ExemplarMarshaler[] exemplars, KeyValueMarshaler[] attributes) {
int size = 0;
size += MarshalerUtil.sizeFixed64(HistogramDataPoint.START_TIME_UNIX_NANO, startTimeUnixNano);
size += MarshalerUtil.sizeFixed64(HistogramDataPoint.TIME_UNIX_NANO, timeUnixNano);
size += MarshalerUtil.sizeFixed64(HistogramDataPoint.COUNT, count);
size += MarshalerUtil.sizeDouble(HistogramDataPoint.SUM, sum);
size += MarshalerUtil.sizeRepeatedFixed64(HistogramDataPoint.BUCKET_COUNTS, bucketCounts);
size += MarshalerUtil.sizeRepeatedDouble(HistogramDataPoint.EXPLICIT_BOUNDS, explicitBounds);
size += MarshalerUtil.sizeRepeatedMessage(HistogramDataPoint.EXEMPLARS, exemplars);
size += MarshalerUtil.sizeRepeatedMessage(HistogramDataPoint.ATTRIBUTES, attributes);
return size;
}
Aggregations