forked from apache/druid
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
METRICS-3663 OpenTelemetry Metrics InputFormat (#63)
* An OpenTelemetry metrics extension * An InputFormat that is able to ingest metrics that are in the OpenTelemetry format * Unit tests for the InputFormat * Benchmarking Tests for the new OpenTelemetryMetricsProtobufInputFormat
- Loading branch information
1 parent
16f6710
commit e4eba21
Showing
8 changed files
with
947 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
<?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> | ||
</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>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> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.core</groupId> | ||
<artifactId>jackson-databind</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.druid</groupId> | ||
<artifactId>druid-core</artifactId> | ||
<version>${project.parent.version}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<!-- 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> | ||
</dependencies> | ||
</project> |
121 changes: 121 additions & 0 deletions
121
...ache/druid/data/input/opentelemetry/protobuf/OpenTelemetryMetricsProtobufInputFormat.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
/* | ||
* 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 = "metric"; | ||
private static final String DEFAULT_VALUE_DIMENSION = "value"; | ||
private static final String DEFAULT_RESOURCE_PREFIX = "resource."; | ||
|
||
private final String metricDimension; | ||
private final String valueDimension; | ||
private final String metricAttributePrefix; | ||
private final String resourceAttributePrefix; | ||
|
||
public OpenTelemetryMetricsProtobufInputFormat( | ||
@JsonProperty("metricDimension") String metricDimension, | ||
@JsonProperty("valueDimension") String valueDimension, | ||
@JsonProperty("metricAttributePrefix") String metricAttributePrefix, | ||
@JsonProperty("resourceAttributePrefix") String resourceAttributePrefix | ||
) | ||
{ | ||
this.metricDimension = metricDimension != null ? metricDimension : DEFAULT_METRIC_DIMENSION; | ||
this.valueDimension = valueDimension != null ? valueDimension : DEFAULT_VALUE_DIMENSION; | ||
this.metricAttributePrefix = StringUtils.nullToEmptyNonDruidDataString(metricAttributePrefix); | ||
this.resourceAttributePrefix = resourceAttributePrefix != null ? resourceAttributePrefix : 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, | ||
valueDimension, | ||
metricAttributePrefix, | ||
resourceAttributePrefix | ||
); | ||
} | ||
|
||
@JsonProperty | ||
public String getMetricDimension() | ||
{ | ||
return metricDimension; | ||
} | ||
|
||
@JsonProperty | ||
public String getValueDimension() | ||
{ | ||
return valueDimension; | ||
} | ||
|
||
@JsonProperty | ||
public String getMetricAttributePrefix() | ||
{ | ||
return metricAttributePrefix; | ||
} | ||
|
||
@JsonProperty | ||
public String getResourceAttributePrefix() | ||
{ | ||
return resourceAttributePrefix; | ||
} | ||
|
||
@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(valueDimension, that.valueDimension) | ||
&& Objects.equals(metricAttributePrefix, that.metricAttributePrefix) | ||
&& Objects.equals(resourceAttributePrefix, that.resourceAttributePrefix); | ||
} | ||
|
||
@Override | ||
public int hashCode() | ||
{ | ||
return Objects.hash(metricDimension, valueDimension, metricAttributePrefix, resourceAttributePrefix); | ||
} | ||
} |
Oops, something went wrong.