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

IGNITE-17443 Implement OpenTelemetry metric exporter. #4531

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ tree-sitter = "0.24.3"
tree-sitter-json = "0.23.0"
tree-sitter-sql = "gh-pages-a"
tree-sitter-hocon = "master-a"
otel = "1.42.1"

#Tools
pmdTool = "6.55.0"
Expand Down Expand Up @@ -267,3 +268,5 @@ tree-sitter = { module = "io.github.bonede:tree-sitter", version.ref = "tree-sit
tree-sitter-json = { module = "io.github.bonede:tree-sitter-json", version.ref = "tree-sitter-json" }
tree-sitter-sql = { module = "io.github.bonede:tree-sitter-sql", version.ref = "tree-sitter-sql" }
tree-sitter-hocon = { module = "io.github.bonede:tree-sitter-hocon", version.ref = "tree-sitter-hocon" }

opentelemetry-exporter-otlp = { module = "io.opentelemetry:opentelemetry-exporter-otlp", version.ref = "otel" }
51 changes: 51 additions & 0 deletions modules/metrics-exporter-otlp/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* 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.
*/

apply from: "$rootDir/buildscripts/java-core.gradle"
apply from: "$rootDir/buildscripts/publishing.gradle"
apply from: "$rootDir/buildscripts/java-junit5.gradle"

dependencies {
annotationProcessor project(':ignite-configuration-annotation-processor')
annotationProcessor libs.auto.service

implementation project(':ignite-api')
implementation project(':ignite-core')
implementation project(':ignite-configuration')
implementation project(':ignite-configuration-root')
implementation project(':ignite-network')
implementation project(':ignite-metrics')
implementation libs.jetbrains.annotations
implementation libs.auto.service.annotations
implementation(libs.opentelemetry.exporter.otlp) {
// Exclude transitive dependency for exporting logs and traces.
exclude group: 'io.opentelemetry', module: 'opentelemetry-sdk-logs'
exclude group: 'io.opentelemetry', module: 'opentelemetry-sdk-trace'
}

testAnnotationProcessor project(':ignite-configuration-annotation-processor')

testImplementation project(':ignite-configuration')
testImplementation testFixtures(project(':ignite-core'))
testImplementation testFixtures(project(':ignite-configuration'))
testImplementation libs.hamcrest.core
testImplementation libs.mockito.core
testImplementation libs.mockito.junit
testImplementation libs.awaitility
}

description = 'ignite-metrics-exporter-otlp'
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* 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.ignite.internal.metrics.exporters.configuration;

import org.apache.ignite.configuration.annotation.Config;
import org.apache.ignite.configuration.annotation.InjectedName;
import org.apache.ignite.configuration.annotation.Value;
import org.apache.ignite.configuration.validation.NotBlank;

/**
* Connection headers configuration schema.
*/
@Config
public class HeadersConfigurationSchema {
/** Name of the header. */
@InjectedName
public String name;

/** Header value. */
@NotBlank
@Value
public String header;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* 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.ignite.internal.metrics.exporters.configuration;

import com.google.auto.service.AutoService;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import org.apache.ignite.configuration.ConfigurationModule;
import org.apache.ignite.configuration.annotation.ConfigurationType;
import org.apache.ignite.configuration.validation.Validator;
import org.apache.ignite.internal.metrics.exporters.validator.EndpointValidatorImpl;

/**
* {@link ConfigurationModule} for cluster-wide configuration provided by metrics-exporter-otlp.
*/
@AutoService(ConfigurationModule.class)
public class OtlpExporterConfigurationModule implements ConfigurationModule {
@Override
public ConfigurationType type() {
return ConfigurationType.DISTRIBUTED;
}

@Override
public Set<Validator<?, ?>> validators() {
return Set.of(EndpointValidatorImpl.INSTANCE);
}

@Override
public Collection<Class<?>> polymorphicSchemaExtensions() {
return List.of(
OtlpExporterConfigurationSchema.class
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* 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.ignite.internal.metrics.exporters.configuration;

import static io.opentelemetry.exporter.otlp.internal.OtlpConfigUtil.PROTOCOL_GRPC;
import static io.opentelemetry.exporter.otlp.internal.OtlpConfigUtil.PROTOCOL_HTTP_PROTOBUF;

import org.apache.ignite.configuration.annotation.ConfigValue;
import org.apache.ignite.configuration.annotation.NamedConfigValue;
import org.apache.ignite.configuration.annotation.PolymorphicConfigInstance;
import org.apache.ignite.configuration.annotation.Value;
import org.apache.ignite.configuration.validation.OneOf;
import org.apache.ignite.internal.metrics.exporters.otlp.OtlpPushMetricExporter;
import org.apache.ignite.internal.metrics.exporters.validator.EndpointValidator;
import org.apache.ignite.internal.network.configuration.SslConfigurationSchema;
import org.apache.ignite.internal.network.configuration.SslConfigurationValidator;

/**
* Configuration for OTLP push exporter.
*/
@PolymorphicConfigInstance(OtlpPushMetricExporter.EXPORTER_NAME)
public class OtlpExporterConfigurationSchema extends ExporterConfigurationSchema {
/** Export period, in milliseconds. */
@Value(hasDefault = true)
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you pls add a javadoc with the time unit of this value?

public long period = 30_000;

/** String in "host:port" format. */
@Value
@EndpointValidator
public String endpoint;

/** OTLP protocol. */
@OneOf({PROTOCOL_GRPC, PROTOCOL_HTTP_PROTOBUF})
@Value(hasDefault = true)
public String protocol = PROTOCOL_GRPC;

/** Connection headers configuration schema. */
@NamedConfigValue
public HeadersConfigurationSchema headers;

/** SSL configuration schema. */
@ConfigValue
@SslConfigurationValidator
public SslConfigurationSchema ssl;

/** Method used to compress payloads. */
@OneOf({"none", "gzip"})
@Value(hasDefault = true)
public String compression = "gzip";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
/*
* 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.ignite.internal.metrics.exporters.otlp;

import static io.opentelemetry.sdk.metrics.data.MetricDataType.HISTOGRAM;
import static java.util.Collections.emptyList;
import static java.util.Collections.singletonList;

import io.opentelemetry.sdk.common.InstrumentationScopeInfo;
import io.opentelemetry.sdk.internal.PrimitiveLongList;
import io.opentelemetry.sdk.metrics.data.AggregationTemporality;
import io.opentelemetry.sdk.metrics.data.Data;
import io.opentelemetry.sdk.metrics.data.DoubleExemplarData;
import io.opentelemetry.sdk.metrics.data.HistogramData;
import io.opentelemetry.sdk.metrics.data.HistogramPointData;
import io.opentelemetry.sdk.metrics.data.MetricDataType;
import io.opentelemetry.sdk.resources.Resource;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.apache.ignite.internal.metrics.DistributionMetric;

/**
* Metric data that holds distribution metric.
*/
class IgniteDistributionMetricData extends IgniteMetricData<DistributionMetric> {
private final HistogramData data;

IgniteDistributionMetricData(Resource resource, InstrumentationScopeInfo scope, DistributionMetric metric) {
super(resource, scope, metric);

data = new IgniteHistogramData(new IgniteDistributionPointData(metric));
}

@Override
public MetricDataType getType() {
return HISTOGRAM;
}

@Override
public Data<?> getData() {
return data;
}

static class IgniteHistogramData implements HistogramData {
private final Collection<HistogramPointData> points;

IgniteHistogramData(HistogramPointData data) {
points = singletonList(data);
}

@Override
public AggregationTemporality getAggregationTemporality() {
return AggregationTemporality.CUMULATIVE;
}

@Override
public Collection<HistogramPointData> getPoints() {
return points;
}
}

static class IgniteDistributionPointData extends IgnitePointData implements HistogramPointData {
private final DistributionMetric metric;

private final List<Double> boundaries;

IgniteDistributionPointData(DistributionMetric metric) {
this.metric = metric;

boundaries = asDoubleList(metric.bounds());
}

@Override
public double getSum() {
return Double.NaN;
}

@Override
public long getCount() {
long totalCount = 0;

for (long c : metric.value()) {
totalCount += c;
}

return totalCount;
}

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

@Override
public double getMin() {
return Double.NaN;
}

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

@Override
public double getMax() {
return Double.NaN;
}

@Override
public List<Double> getBoundaries() {
return boundaries;
}

@Override
public List<Long> getCounts() {
return PrimitiveLongList.wrap(metric.value());
}

@Override
public List<DoubleExemplarData> getExemplars() {
return emptyList();
}

private static List<Double> asDoubleList(long[] array) {
ArrayList<Double> result = new ArrayList<>(array.length);

for (long el : array) {
result.add((double) el);
}

return result;
}
}
}
Loading