Skip to content

Commit

Permalink
Do not export counters with no points. (#1978)
Browse files Browse the repository at this point in the history
CHANGELOG: counters with no points are no longer exported via the OTLP exporter
  • Loading branch information
carlosalberto authored Nov 11, 2020
1 parent 58ccf97 commit 56b1c23
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ static List<ResourceMetrics> toProtoResourceMetrics(Collection<MetricData> metri
groupByResourceAndLibrary(Collection<MetricData> metricDataList) {
Map<Resource, Map<InstrumentationLibraryInfo, List<Metric>>> result = new HashMap<>();
for (MetricData metricData : metricDataList) {
if (metricData.getPoints().isEmpty()) {
// If no points available then ignore.
continue;
}

Resource resource = metricData.getResource();
Map<InstrumentationLibraryInfo, List<Metric>> libraryInfoListMap =
result.get(metricData.getResource());
Expand All @@ -92,10 +97,6 @@ static Metric toProtoMetric(MetricData metricData) {
.setName(metricData.getName())
.setDescription(metricData.getDescription())
.setUnit(metricData.getUnit());
// If no points available then return.
if (metricData.getPoints().isEmpty()) {
return builder.build();
}

boolean monotonic = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -468,8 +468,26 @@ void toProtoResourceMetrics() {
InstrumentationLibrary.newBuilder().setName("name").setVersion("version").build();
InstrumentationLibrary emptyInstrumentationLibraryProto =
InstrumentationLibrary.newBuilder().setName("").setVersion("").build();
Metric metricNoPoints =
Metric.newBuilder().setName("name").setDescription("description").setUnit("1").build();
Metric metricDoubleSum =
Metric.newBuilder()
.setName("name")
.setDescription("description")
.setUnit("1")
.setDoubleSum(
DoubleSum.newBuilder()
.setIsMonotonic(true)
.setAggregationTemporality(AGGREGATION_TEMPORALITY_CUMULATIVE)
.addDataPoints(
DoubleDataPoint.newBuilder()
.setStartTimeUnixNano(123)
.setTimeUnixNano(456)
.addAllLabels(
singletonList(
StringKeyValue.newBuilder().setKey("k").setValue("v").build()))
.setValue(5.0)
.build())
.build())
.build();

assertThat(
MetricAdapter.toProtoResourceMetrics(
Expand All @@ -481,39 +499,43 @@ void toProtoResourceMetrics() {
"description",
"1",
MetricData.Type.MONOTONIC_DOUBLE,
Collections.emptyList()),
Collections.singletonList(
MetricData.DoublePoint.create(123, 456, Labels.of("k", "v"), 5.0))),
MetricData.create(
resource,
instrumentationLibraryInfo,
"name",
"description",
"1",
MetricData.Type.MONOTONIC_DOUBLE,
Collections.emptyList()),
Collections.singletonList(
MetricData.DoublePoint.create(123, 456, Labels.of("k", "v"), 5.0))),
MetricData.create(
Resource.getEmpty(),
instrumentationLibraryInfo,
"name",
"description",
"1",
MetricData.Type.MONOTONIC_DOUBLE,
Collections.emptyList()),
Collections.singletonList(
MetricData.DoublePoint.create(123, 456, Labels.of("k", "v"), 5.0))),
MetricData.create(
Resource.getEmpty(),
InstrumentationLibraryInfo.getEmpty(),
"name",
"description",
"1",
MetricData.Type.MONOTONIC_DOUBLE,
Collections.emptyList()))))
Collections.singletonList(
MetricData.DoublePoint.create(123, 456, Labels.of("k", "v"), 5.0))))))
.containsExactlyInAnyOrder(
ResourceMetrics.newBuilder()
.setResource(resourceProto)
.addAllInstrumentationLibraryMetrics(
singletonList(
InstrumentationLibraryMetrics.newBuilder()
.setInstrumentationLibrary(instrumentationLibraryProto)
.addAllMetrics(ImmutableList.of(metricNoPoints, metricNoPoints))
.addAllMetrics(ImmutableList.of(metricDoubleSum, metricDoubleSum))
.build()))
.build(),
ResourceMetrics.newBuilder()
Expand All @@ -522,11 +544,11 @@ void toProtoResourceMetrics() {
ImmutableList.of(
InstrumentationLibraryMetrics.newBuilder()
.setInstrumentationLibrary(emptyInstrumentationLibraryProto)
.addAllMetrics(singletonList(metricNoPoints))
.addAllMetrics(singletonList(metricDoubleSum))
.build(),
InstrumentationLibraryMetrics.newBuilder()
.setInstrumentationLibrary(instrumentationLibraryProto)
.addAllMetrics(singletonList(metricNoPoints))
.addAllMetrics(singletonList(metricDoubleSum))
.build()))
.build());
}
Expand Down

0 comments on commit 56b1c23

Please sign in to comment.