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

Modify the OpenTelemetry ProtobufReader's Handling of Attribute Types #77

Merged
merged 7 commits into from
Mar 1, 2022
Merged
Show file tree
Hide file tree
Changes from 4 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 @@ -36,8 +36,10 @@
import org.apache.druid.java.util.common.parsers.CloseableIterator;
import org.apache.druid.java.util.common.parsers.ParseException;

import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -94,8 +96,14 @@ private List<InputRow> parseMetricsData(final MetricsData metricsData)
Map<String, Object> resourceAttributes = resourceMetrics.getResource()
.getAttributesList()
.stream()
.collect(Collectors.toMap(kv -> resourceAttributePrefix + kv.getKey(),
kv -> parseAnyValue(kv.getValue())));
.collect(HashMap::new,
xvrl marked this conversation as resolved.
Show resolved Hide resolved
(m, kv) -> {
Object value = parseAnyValue(kv.getValue());
if (value != null) {
m.put(resourceAttributePrefix + kv.getKey(), value);
}
},
HashMap::putAll);
return resourceMetrics.getInstrumentationLibraryMetricsList()
.stream()
.flatMap(libraryMetrics -> libraryMetrics.getMetricsList()
Expand Down Expand Up @@ -142,8 +150,8 @@ private InputRow parseNumberDataPoint(NumberDataPoint dataPoint,
{

int capacity = resourceAttributes.size()
+ dataPoint.getAttributesCount()
+ 2; // metric name + value columns
+ dataPoint.getAttributesCount()
+ 2; // metric name + value columns
Map<String, Object> event = Maps.newHashMapWithExpectedSize(capacity);
event.put(metricDimension, metricName);

Expand All @@ -154,32 +162,34 @@ private InputRow parseNumberDataPoint(NumberDataPoint dataPoint,
}

event.putAll(resourceAttributes);
dataPoint.getAttributesList().forEach(att -> event.put(metricAttributePrefix + att.getKey(),
parseAnyValue(att.getValue())));
dataPoint.getAttributesList().forEach(att -> {
Object value = parseAnyValue(att.getValue());
if (value != null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we update the tests to make ensure unsupported types are not present in the final row?

event.put(metricAttributePrefix + att.getKey(), value);
}
});

return createRow(TimeUnit.NANOSECONDS.toMillis(dataPoint.getTimeUnixNano()), event);
}

@Nullable
private static Object parseAnyValue(AnyValue value)
{
switch (value.getValueCase()) {
case INT_VALUE:
return value.getIntValue();
case BOOL_VALUE:
return value.getBoolValue();
case ARRAY_VALUE:
return value.getArrayValue();
case BYTES_VALUE:
return value.getBytesValue();
case DOUBLE_VALUE:
return value.getDoubleValue();
case KVLIST_VALUE:
return value.getKvlistValue();
case STRING_VALUE:
return value.getStringValue();

// TODO: Support KVLIST_VALUE, ARRAY_VALUE and BYTES_VALUE
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

druid does support multi-value dimensions, so we should be able to do a follow-up and add support for ARRAY_VALUE


default:
// VALUE_NOT_SET:
return "";
// VALUE_NOT_SET
return null;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.

org.apache.druid.data.input.opencensus.protobuf.OpenCensusProtobufExtensionsModule
org.apache.druid.data.input.opentelemetry.protobuf.OpenTelemetryMetricsProtobufInputFormat