Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter Out Metrics with NoRecordedValue Flag Set #157

Merged
merged 4 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.google.common.collect.Sets;
import com.google.protobuf.InvalidProtocolBufferException;
import io.opentelemetry.proto.common.v1.AnyValue;
import io.opentelemetry.proto.metrics.v1.DataPointFlags;
import io.opentelemetry.proto.metrics.v1.Metric;
import io.opentelemetry.proto.metrics.v1.MetricsData;
import io.opentelemetry.proto.metrics.v1.NumberDataPoint;
Expand Down Expand Up @@ -146,14 +147,22 @@ private List<InputRow> parseMetric(Metric metric, Map<String, Object> resourceAt
inputRows = new ArrayList<>(metric.getSum().getDataPointsCount());
metric.getSum()
.getDataPointsList()
.forEach(dataPoint -> inputRows.add(parseNumberDataPoint(dataPoint, resourceAttributes, metricName)));
.forEach(dataPoint -> {
if (hasRecordedValue(dataPoint)) {
inputRows.add(parseNumberDataPoint(dataPoint, resourceAttributes, metricName));
}
});
michaelli321 marked this conversation as resolved.
Show resolved Hide resolved
break;
}
case GAUGE: {
inputRows = new ArrayList<>(metric.getGauge().getDataPointsCount());
metric.getGauge()
.getDataPointsList()
.forEach(dataPoint -> inputRows.add(parseNumberDataPoint(dataPoint, resourceAttributes, metricName)));
.forEach(dataPoint -> {
if (hasRecordedValue(dataPoint)) {
inputRows.add(parseNumberDataPoint(dataPoint, resourceAttributes, metricName));
}
});
break;
}
// TODO Support HISTOGRAM and SUMMARY metrics
Expand All @@ -167,6 +176,11 @@ private List<InputRow> parseMetric(Metric metric, Map<String, Object> resourceAt
return inputRows;
}

private static boolean hasRecordedValue(NumberDataPoint d)
{
return (d.getFlags() & DataPointFlags.FLAG_NO_RECORDED_VALUE_VALUE) == 0;
}

private InputRow parseNumberDataPoint(NumberDataPoint dataPoint,
Map<String, Object> resourceAttributes,
String metricName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import io.opentelemetry.proto.common.v1.AnyValue;
import io.opentelemetry.proto.common.v1.KeyValue;
import io.opentelemetry.proto.common.v1.KeyValueList;
import io.opentelemetry.proto.metrics.v1.DataPointFlags;
import io.opentelemetry.proto.metrics.v1.Metric;
import io.opentelemetry.proto.metrics.v1.MetricsData;
import org.apache.druid.data.input.InputRow;
Expand Down Expand Up @@ -404,6 +405,32 @@ public void testInvalidMetricType()
Assert.assertEquals(0, rowList.size());
}

@Test
public void testNoRecordedValueMetric()
{
metricBuilder.setName("example_gauge")
.getGaugeBuilder()
.addDataPointsBuilder()
.setAsInt(6)
.setFlags(DataPointFlags.FLAG_NO_RECORDED_VALUE_VALUE)
.setTimeUnixNano(TIMESTAMP);

MetricsData metricsData = metricsDataBuilder.build();

SettableByteEntity<ByteEntity> settableByteEntity = new SettableByteEntity<>();
settableByteEntity.setEntity(new ByteEntity(metricsData.toByteArray()));
CloseableIterator<InputRow> rows = new OpenTelemetryMetricsProtobufReader(
dimensionsSpec,
settableByteEntity,
"metric.name",
"raw.value",
"descriptor.",
"custom."
).read();

Assert.assertFalse(rows.hasNext());
}

private void assertDimensionEquals(InputRow row, String dimension, Object expected)
{
List<String> values = row.getDimension(dimension);
Expand Down