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

METRICS-3663 OpenTelemetry Metrics InputFormat #63

Merged
merged 14 commits into from
Feb 4, 2022
6 changes: 6 additions & 0 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,12 @@
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.16.0</version>
<scope>test</scope>
</dependency>
marcusgreer marked this conversation as resolved.
Show resolved Hide resolved
</dependencies>

<build>
Expand Down
105 changes: 105 additions & 0 deletions extensions-contrib/opentelemetry-extensions/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Licensed to the Apache Software Foundation (ASF) under one
~ or more contributor license agreements. See the NOTICE file
~ distributed with this work for additional information
~ regarding copyright ownership. The ASF licenses this file
~ to you under the Apache License, Version 2.0 (the
~ "License"); you may not use this file except in compliance
~ with the License. You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing,
~ software distributed under the License is distributed on an
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
~ KIND, either express or implied. See the License for the
~ specific language governing permissions and limitations
~ under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.apache.druid.extensions.contrib</groupId>
<artifactId>druid-opentelemetry-extensions</artifactId>
<name>druid-opentelemetry-extensions</name>
<description>druid-opentelemetry-extensions</description>

<properties>
<opentelemetry.proto.version>0.11.0-alpha</opentelemetry.proto.version>
Copy link
Member

Choose a reason for hiding this comment

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

0.12 is out, which removes all the deprecated fields and data point formats. We should upgrade to that so we don't have to worry about the deprecated fields and simplify things quite a bit.

</properties>

<parent>
<artifactId>druid</artifactId>
<groupId>org.apache.druid</groupId>
<version>0.21.0</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
</dependency>
<dependency>
<groupId>org.apache.druid</groupId>
<artifactId>druid-core</artifactId>
<version>${project.parent.version}</version>
<scope>provided</scope>
</dependency>
marcusgreer marked this conversation as resolved.
Show resolved Hide resolved
<dependency>
<groupId>io.opentelemetry.proto</groupId>
<artifactId>opentelemetry-proto</artifactId>
<version>${opentelemetry.proto.version}</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<scope>provided</scope>
</dependency>
marcusgreer marked this conversation as resolved.
Show resolved Hide resolved
<!-- test -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<!-- jmh -->
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-core</artifactId>
<version>1.27</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-generator-annprocess</artifactId>
<version>1.27</version>
<scope>test</scope>
</dependency>
marcusgreer marked this conversation as resolved.
Show resolved Hide resolved
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<nonFilteredFileExtensions>
<nonFilteredFileExtension>desc</nonFilteredFileExtension>
</nonFilteredFileExtensions>
</configuration>
</plugin>
marcusgreer marked this conversation as resolved.
Show resolved Hide resolved
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.apache.druid.data.input.opentelemetry.protobuf;

import com.fasterxml.jackson.databind.Module;
import com.fasterxml.jackson.databind.jsontype.NamedType;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.google.inject.Binder;
import org.apache.druid.initialization.DruidModule;

import java.util.Collections;
import java.util.List;

public class OpenTelemetryMetricsProtobufExtensionsModule implements DruidModule
marcusgreer marked this conversation as resolved.
Show resolved Hide resolved
{

@Override
public List<? extends Module> getJacksonModules()
{
return Collections.singletonList(
new SimpleModule("OpenTelemetryProtobufInputRowParserModule")
.registerSubtypes(
new NamedType(OpenTelemetryMetricsProtobufInputFormat.class, "opentelemetry-metrics-protobuf")
)
);
}

@Override
public void configure(Binder binder)
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.apache.druid.data.input.opentelemetry.protobuf;

import com.fasterxml.jackson.annotation.JsonProperty;
import org.apache.druid.data.input.InputEntity;
import org.apache.druid.data.input.InputEntityReader;
import org.apache.druid.data.input.InputFormat;
import org.apache.druid.data.input.InputRowSchema;
import org.apache.druid.data.input.impl.ByteEntity;
import org.apache.druid.java.util.common.StringUtils;

import java.io.File;
import java.util.Objects;

public class OpenTelemetryMetricsProtobufInputFormat implements InputFormat
{
private static final String DEFAULT_METRIC_DIMENSION = "name";
marcusgreer marked this conversation as resolved.
Show resolved Hide resolved
private static final String DEFAULT_RESOURCE_PREFIX = "resource.";

private final String metricDimension;
private final String metricLabelPrefix;
private final String resourceLabelPrefix;

public OpenTelemetryMetricsProtobufInputFormat(
@JsonProperty("metricDimension") String metricDimension,
@JsonProperty("metricLabelPrefix") String metricLabelPrefix,
@JsonProperty("resourceLabelPrefix") String resourceLabelPrefix
marcusgreer marked this conversation as resolved.
Show resolved Hide resolved
)
{
this.metricDimension = metricDimension != null ? metricDimension : DEFAULT_METRIC_DIMENSION;
this.metricLabelPrefix = StringUtils.nullToEmptyNonDruidDataString(metricLabelPrefix);
this.resourceLabelPrefix = resourceLabelPrefix != null ? resourceLabelPrefix : DEFAULT_RESOURCE_PREFIX;
}

@Override
public boolean isSplittable()
{
return false;
}

@Override
public InputEntityReader createReader(InputRowSchema inputRowSchema, InputEntity source, File temporaryDirectory)
{
return new OpenTelemetryMetricsProtobufReader(
inputRowSchema.getDimensionsSpec(),
(ByteEntity) source,
metricDimension,
metricLabelPrefix,
resourceLabelPrefix
);
}

@JsonProperty
public String getMetricDimension()
{
return metricDimension;
}

@JsonProperty
public String getMetricLabelPrefix()
{
return metricLabelPrefix;
}

@JsonProperty
public String getResourceLabelPrefix()
{
return resourceLabelPrefix;
}

@Override
public boolean equals(Object o)
{
if (this == o) {
return true;
}
if (!(o instanceof OpenTelemetryMetricsProtobufInputFormat)) {
return false;
}
OpenTelemetryMetricsProtobufInputFormat that = (OpenTelemetryMetricsProtobufInputFormat) o;
return Objects.equals(metricDimension, that.metricDimension)
&& Objects.equals(metricLabelPrefix, that.metricLabelPrefix)
&& Objects.equals(resourceLabelPrefix, that.resourceLabelPrefix);
}

@Override
public int hashCode()
{
return Objects.hash(metricDimension, metricLabelPrefix, resourceLabelPrefix);
}
}
marcusgreer marked this conversation as resolved.
Show resolved Hide resolved
Loading