kgusakov commented on code in PR #4531: URL: https://github.com/apache/ignite-3/pull/4531#discussion_r1822883916
########## modules/metrics-exporter-otlp/src/main/java/org/apache/ignite/internal/metrics/exporters/configuration/OtlpExporterConfigurationSchema.java: ########## @@ -0,0 +1,64 @@ +/* + * 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.OtlpExporter; +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(OtlpExporter.EXPORTER_NAME) +public class OtlpExporterConfigurationSchema extends ExporterConfigurationSchema { + @Value(hasDefault = true) Review Comment: Could you pls add a javadoc with the time unit of this value? ########## modules/metrics-exporter-otlp/src/main/java/org/apache/ignite/internal/metrics/exporters/otlp/MetricProducer.java: ########## @@ -0,0 +1,157 @@ +/* + * 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.AggregationTemporality.CUMULATIVE; +import static java.util.Collections.emptyList; +import static java.util.Collections.singleton; +import static java.util.stream.Collectors.toUnmodifiableList; + +import io.opentelemetry.api.common.Attributes; +import io.opentelemetry.sdk.common.Clock; +import io.opentelemetry.sdk.common.InstrumentationScopeInfo; +import io.opentelemetry.sdk.metrics.data.MetricData; +import io.opentelemetry.sdk.metrics.export.CollectionRegistration; +import io.opentelemetry.sdk.metrics.internal.data.ImmutableDoublePointData; +import io.opentelemetry.sdk.metrics.internal.data.ImmutableGaugeData; +import io.opentelemetry.sdk.metrics.internal.data.ImmutableHistogramData; +import io.opentelemetry.sdk.metrics.internal.data.ImmutableHistogramPointData; +import io.opentelemetry.sdk.metrics.internal.data.ImmutableLongPointData; +import io.opentelemetry.sdk.metrics.internal.data.ImmutableMetricData; +import io.opentelemetry.sdk.resources.Resource; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.UUID; +import java.util.function.Supplier; +import org.apache.ignite.internal.lang.IgniteBiTuple; +import org.apache.ignite.internal.metrics.DistributionMetric; +import org.apache.ignite.internal.metrics.DoubleMetric; +import org.apache.ignite.internal.metrics.IntMetric; +import org.apache.ignite.internal.metrics.LongMetric; +import org.apache.ignite.internal.metrics.Metric; +import org.apache.ignite.internal.metrics.MetricProvider; +import org.apache.ignite.internal.metrics.MetricSet; +import org.jetbrains.annotations.Nullable; + +/** + * Metrics producer which collect metrics in OpenTelemetry format. + */ +class MetricProducer implements CollectionRegistration { + private final MetricProvider metricsProvider; + + private final Supplier<UUID> clusterIdSupplier; + + private final String nodeName; + + MetricProducer(MetricProvider metricsProvider, Supplier<UUID> clusterIdSupplier, String nodeName) { + this.metricsProvider = metricsProvider; + this.clusterIdSupplier = clusterIdSupplier; + this.nodeName = nodeName; + } + + @Override + public Collection<MetricData> collectAllMetrics() { + IgniteBiTuple<Map<String, MetricSet>, Long> snapshot = metricsProvider.metrics(); + @Nullable Long metricCount = snapshot.getValue(); + + if (metricCount == null || Objects.equals(metricCount, 0L)) { + return emptyList(); + } + + long epochNanos = Clock.getDefault().now(); + + Resource resource = Resource.builder() + .put("service.name", clusterIdSupplier.get().toString()) + .put("service.instance.id", nodeName) + .build(); + + Collection<MetricData> result = new ArrayList<>(Math.toIntExact(metricCount)); + + for (MetricSet metricSet : snapshot.getKey().values()) { + InstrumentationScopeInfo scope = InstrumentationScopeInfo.builder(metricSet.name()) + .build(); + + for (Metric metric : metricSet) { + if (metric instanceof IntMetric) { + IntMetric intMetric = (IntMetric) metric; + + result.add(ImmutableMetricData.createLongGauge( + resource, + scope, + metric.name(), + metric.description(), + "", + ImmutableGaugeData.create( + singleton(ImmutableLongPointData.create(epochNanos, epochNanos, Attributes.empty(), intMetric.value())) + ) + )); + } else if (metric instanceof LongMetric) { + LongMetric longMetric = (LongMetric) metric; + + result.add(ImmutableMetricData.createLongGauge( + resource, + scope, + metric.name(), + metric.description(), + "", + ImmutableGaugeData.create( + singleton(ImmutableLongPointData.create(epochNanos, epochNanos, Attributes.empty(), longMetric.value())) + ) + )); + } else if (metric instanceof DoubleMetric) { + DoubleMetric metric0 = (DoubleMetric) metric; + + result.add(ImmutableMetricData.createDoubleGauge( + resource, + scope, + metric.name(), + metric.description(), + "", + ImmutableGaugeData.create( + singleton(ImmutableDoublePointData.create(epochNanos, epochNanos, Attributes.empty(), metric0.value())) + ) + )); + } else if (metric instanceof DistributionMetric) { + DistributionMetric metric0 = (DistributionMetric) metric; + + result.add(ImmutableMetricData.createDoubleHistogram( + resource, + scope, + metric.name(), + metric.description(), + "", + ImmutableHistogramData.create( + CUMULATIVE, + List.of(ImmutableHistogramPointData.create( + epochNanos, epochNanos, Attributes.empty(), Double.NaN, false, Double.NaN, false, Double.NaN, + Arrays.stream(metric0.bounds()).asDoubleStream().boxed().collect(toUnmodifiableList()), + Arrays.stream(metric0.value()).boxed().collect(toUnmodifiableList()) + )) + ) + )); + } Review Comment: It will be useful to add the DEBUG/TRACE level log at least, for the cases, when occasionally we receive unknown metric type here. ########## modules/metrics-exporter-otlp/src/main/java/org/apache/ignite/internal/metrics/exporters/otlp/MetricProducer.java: ########## @@ -0,0 +1,157 @@ +/* + * 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.AggregationTemporality.CUMULATIVE; +import static java.util.Collections.emptyList; +import static java.util.Collections.singleton; +import static java.util.stream.Collectors.toUnmodifiableList; + +import io.opentelemetry.api.common.Attributes; +import io.opentelemetry.sdk.common.Clock; +import io.opentelemetry.sdk.common.InstrumentationScopeInfo; +import io.opentelemetry.sdk.metrics.data.MetricData; +import io.opentelemetry.sdk.metrics.export.CollectionRegistration; +import io.opentelemetry.sdk.metrics.internal.data.ImmutableDoublePointData; +import io.opentelemetry.sdk.metrics.internal.data.ImmutableGaugeData; +import io.opentelemetry.sdk.metrics.internal.data.ImmutableHistogramData; +import io.opentelemetry.sdk.metrics.internal.data.ImmutableHistogramPointData; +import io.opentelemetry.sdk.metrics.internal.data.ImmutableLongPointData; +import io.opentelemetry.sdk.metrics.internal.data.ImmutableMetricData; +import io.opentelemetry.sdk.resources.Resource; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.UUID; +import java.util.function.Supplier; +import org.apache.ignite.internal.lang.IgniteBiTuple; +import org.apache.ignite.internal.metrics.DistributionMetric; +import org.apache.ignite.internal.metrics.DoubleMetric; +import org.apache.ignite.internal.metrics.IntMetric; +import org.apache.ignite.internal.metrics.LongMetric; +import org.apache.ignite.internal.metrics.Metric; +import org.apache.ignite.internal.metrics.MetricProvider; +import org.apache.ignite.internal.metrics.MetricSet; +import org.jetbrains.annotations.Nullable; + +/** + * Metrics producer which collect metrics in OpenTelemetry format. + */ +class MetricProducer implements CollectionRegistration { + private final MetricProvider metricsProvider; + + private final Supplier<UUID> clusterIdSupplier; + + private final String nodeName; + + MetricProducer(MetricProvider metricsProvider, Supplier<UUID> clusterIdSupplier, String nodeName) { + this.metricsProvider = metricsProvider; + this.clusterIdSupplier = clusterIdSupplier; + this.nodeName = nodeName; + } + + @Override + public Collection<MetricData> collectAllMetrics() { + IgniteBiTuple<Map<String, MetricSet>, Long> snapshot = metricsProvider.metrics(); + @Nullable Long metricCount = snapshot.getValue(); + + if (metricCount == null || Objects.equals(metricCount, 0L)) { + return emptyList(); + } + + long epochNanos = Clock.getDefault().now(); + + Resource resource = Resource.builder() + .put("service.name", clusterIdSupplier.get().toString()) + .put("service.instance.id", nodeName) + .build(); + + Collection<MetricData> result = new ArrayList<>(Math.toIntExact(metricCount)); + + for (MetricSet metricSet : snapshot.getKey().values()) { + InstrumentationScopeInfo scope = InstrumentationScopeInfo.builder(metricSet.name()) + .build(); + + for (Metric metric : metricSet) { + if (metric instanceof IntMetric) { + IntMetric intMetric = (IntMetric) metric; + + result.add(ImmutableMetricData.createLongGauge( + resource, + scope, + metric.name(), + metric.description(), + "", + ImmutableGaugeData.create( + singleton(ImmutableLongPointData.create(epochNanos, epochNanos, Attributes.empty(), intMetric.value())) + ) + )); + } else if (metric instanceof LongMetric) { + LongMetric longMetric = (LongMetric) metric; + + result.add(ImmutableMetricData.createLongGauge( + resource, + scope, + metric.name(), + metric.description(), + "", + ImmutableGaugeData.create( + singleton(ImmutableLongPointData.create(epochNanos, epochNanos, Attributes.empty(), longMetric.value())) + ) + )); + } else if (metric instanceof DoubleMetric) { + DoubleMetric metric0 = (DoubleMetric) metric; + + result.add(ImmutableMetricData.createDoubleGauge( + resource, + scope, + metric.name(), + metric.description(), + "", + ImmutableGaugeData.create( + singleton(ImmutableDoublePointData.create(epochNanos, epochNanos, Attributes.empty(), metric0.value())) + ) + )); + } else if (metric instanceof DistributionMetric) { + DistributionMetric metric0 = (DistributionMetric) metric; + + result.add(ImmutableMetricData.createDoubleHistogram( + resource, + scope, + metric.name(), + metric.description(), + "", + ImmutableHistogramData.create( + CUMULATIVE, + List.of(ImmutableHistogramPointData.create( + epochNanos, epochNanos, Attributes.empty(), Double.NaN, false, Double.NaN, false, Double.NaN, + Arrays.stream(metric0.bounds()).asDoubleStream().boxed().collect(toUnmodifiableList()), Review Comment: It's a pretty often (every X seconds, I guess) executable piece of code. By the our https://cwiki.apache.org/confluence/display/IGNITE/Coding+Guidelines we are trying to ban stream APIs in this type of places. ########## modules/metrics-exporter-otlp/src/main/java/org/apache/ignite/internal/metrics/exporters/otlp/MetricProducer.java: ########## @@ -0,0 +1,157 @@ +/* + * 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.AggregationTemporality.CUMULATIVE; +import static java.util.Collections.emptyList; +import static java.util.Collections.singleton; +import static java.util.stream.Collectors.toUnmodifiableList; + +import io.opentelemetry.api.common.Attributes; +import io.opentelemetry.sdk.common.Clock; +import io.opentelemetry.sdk.common.InstrumentationScopeInfo; +import io.opentelemetry.sdk.metrics.data.MetricData; +import io.opentelemetry.sdk.metrics.export.CollectionRegistration; +import io.opentelemetry.sdk.metrics.internal.data.ImmutableDoublePointData; +import io.opentelemetry.sdk.metrics.internal.data.ImmutableGaugeData; +import io.opentelemetry.sdk.metrics.internal.data.ImmutableHistogramData; +import io.opentelemetry.sdk.metrics.internal.data.ImmutableHistogramPointData; +import io.opentelemetry.sdk.metrics.internal.data.ImmutableLongPointData; +import io.opentelemetry.sdk.metrics.internal.data.ImmutableMetricData; +import io.opentelemetry.sdk.resources.Resource; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.UUID; +import java.util.function.Supplier; +import org.apache.ignite.internal.lang.IgniteBiTuple; +import org.apache.ignite.internal.metrics.DistributionMetric; +import org.apache.ignite.internal.metrics.DoubleMetric; +import org.apache.ignite.internal.metrics.IntMetric; +import org.apache.ignite.internal.metrics.LongMetric; +import org.apache.ignite.internal.metrics.Metric; +import org.apache.ignite.internal.metrics.MetricProvider; +import org.apache.ignite.internal.metrics.MetricSet; +import org.jetbrains.annotations.Nullable; + +/** + * Metrics producer which collect metrics in OpenTelemetry format. + */ +class MetricProducer implements CollectionRegistration { + private final MetricProvider metricsProvider; + + private final Supplier<UUID> clusterIdSupplier; + + private final String nodeName; + + MetricProducer(MetricProvider metricsProvider, Supplier<UUID> clusterIdSupplier, String nodeName) { + this.metricsProvider = metricsProvider; + this.clusterIdSupplier = clusterIdSupplier; + this.nodeName = nodeName; + } + + @Override + public Collection<MetricData> collectAllMetrics() { + IgniteBiTuple<Map<String, MetricSet>, Long> snapshot = metricsProvider.metrics(); + @Nullable Long metricCount = snapshot.getValue(); + + if (metricCount == null || Objects.equals(metricCount, 0L)) { + return emptyList(); + } + + long epochNanos = Clock.getDefault().now(); + + Resource resource = Resource.builder() + .put("service.name", clusterIdSupplier.get().toString()) + .put("service.instance.id", nodeName) + .build(); + + Collection<MetricData> result = new ArrayList<>(Math.toIntExact(metricCount)); + + for (MetricSet metricSet : snapshot.getKey().values()) { + InstrumentationScopeInfo scope = InstrumentationScopeInfo.builder(metricSet.name()) + .build(); + + for (Metric metric : metricSet) { + if (metric instanceof IntMetric) { + IntMetric intMetric = (IntMetric) metric; + + result.add(ImmutableMetricData.createLongGauge( Review Comment: We've spent some effort to prepare the metrics infra, which is not producing significant amount of gargabe for GC. Looks like with this approach we will generate new objects on every metric push. At the same time, the list of metrics from call to call will be pretty stable. Doesn't this sdk has for example mutable APIs with prepared set of objects or anything like this? ########## modules/metrics-exporter-otlp/build.gradle: ########## @@ -0,0 +1,47 @@ +/* + * 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 Review Comment: I don't want to be annoying :), just want to clarify: we have a pretty strict policy about external deps, does this solution passed appropriate discussions? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@ignite.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org