Skip to content

SOLR-17798: Integrate SDK OTLP metric exporter #3413

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

Open
wants to merge 22 commits into
base: feature/SOLR-17458
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
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,7 @@ opentelemetry-bom = { module = "io.opentelemetry:opentelemetry-bom", version.ref
opentelemetry-context = { module = "io.opentelemetry:opentelemetry-context", version.ref = "opentelemetry" }
opentelemetry-exporter-otlp = { module = "io.opentelemetry:opentelemetry-exporter-otlp", version.ref = "opentelemetry" }
opentelemetry-exporter-prometheus = { module = "io.opentelemetry:opentelemetry-exporter-prometheus", version.ref = "opentelemetry-prometheus" }
opentelemetry-exporter-sender-okhttp = { module = "io.opentelemetry:opentelemetry-exporter-sender-okhttp", version.ref = "opentelemetry" }
opentelemetry-sdk = { module = "io.opentelemetry:opentelemetry-sdk", version.ref = "opentelemetry" }
opentelemetry-sdkextension-autoconfigure = { module = "io.opentelemetry:opentelemetry-sdk-extension-autoconfigure", version.ref = "opentelemetry" }
opentelemetry-sdktesting = { module = "io.opentelemetry:opentelemetry-sdk-testing", version.ref = "opentelemetry" }
Expand Down
Empty file.
9 changes: 9 additions & 0 deletions solr/api/gradle.lockfile
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ com.google.j2objc:j2objc-annotations:3.0.0=testCompileClasspath
com.google.protobuf:protobuf-java:3.25.3=annotationProcessor,errorprone,testAnnotationProcessor
com.j256.simplemagic:simplemagic:1.17=jarValidation,testRuntimeClasspath
com.jayway.jsonpath:json-path:2.9.0=jarValidation,testRuntimeClasspath
com.squareup.okhttp3:okhttp:4.12.0=jarValidation,testRuntimeClasspath
com.squareup.okio:okio-jvm:3.6.0=jarValidation,testRuntimeClasspath
com.squareup.okio:okio:3.6.0=jarValidation,testRuntimeClasspath
com.sun.activation:jakarta.activation:2.0.1=swaggerBuild
com.tdunning:t-digest:3.3=jarValidation,testRuntimeClasspath
commons-cli:commons-cli:1.9.0=jarValidation,testRuntimeClasspath
Expand Down Expand Up @@ -73,6 +76,7 @@ io.opentelemetry:opentelemetry-api:1.50.0=jarValidation,testCompileClasspath,tes
io.opentelemetry:opentelemetry-context:1.50.0=jarValidation,testCompileClasspath,testRuntimeClasspath
io.opentelemetry:opentelemetry-exporter-common:1.50.0=jarValidation,testRuntimeClasspath
io.opentelemetry:opentelemetry-exporter-prometheus:1.50.0-alpha=jarValidation,testRuntimeClasspath
io.opentelemetry:opentelemetry-exporter-sender-okhttp:1.50.0=jarValidation,testRuntimeClasspath
io.opentelemetry:opentelemetry-sdk-common:1.50.0=jarValidation,testRuntimeClasspath
io.opentelemetry:opentelemetry-sdk-extension-autoconfigure-spi:1.50.0=jarValidation,testRuntimeClasspath
io.opentelemetry:opentelemetry-sdk-logs:1.50.0=jarValidation,testRuntimeClasspath
Expand Down Expand Up @@ -179,6 +183,11 @@ org.glassfish.jersey.inject:jersey-hk2:3.1.9=jarValidation,testRuntimeClasspath
org.glassfish.jersey.media:jersey-media-json-jackson:3.1.9=jarValidation,testRuntimeClasspath
org.hamcrest:hamcrest:3.0=jarValidation,testCompileClasspath,testRuntimeClasspath
org.javassist:javassist:3.30.2-GA=jarValidation,swaggerBuild,swaggerDeps,testRuntimeClasspath
org.jetbrains.kotlin:kotlin-stdlib-common:2.1.10=jarValidation,testRuntimeClasspath
org.jetbrains.kotlin:kotlin-stdlib-jdk7:2.1.10=jarValidation,testRuntimeClasspath
org.jetbrains.kotlin:kotlin-stdlib-jdk8:2.1.10=jarValidation,testRuntimeClasspath
org.jetbrains.kotlin:kotlin-stdlib:2.1.10=jarValidation,testRuntimeClasspath
org.jetbrains:annotations:26.0.2=jarValidation,testRuntimeClasspath
org.jspecify:jspecify:1.0.0=annotationProcessor,errorprone,testAnnotationProcessor
org.junit.jupiter:junit-jupiter-api:5.6.2=jarValidation,testRuntimeClasspath
org.junit.platform:junit-platform-commons:1.6.2=jarValidation,testRuntimeClasspath
Expand Down
9 changes: 9 additions & 0 deletions solr/benchmark/gradle.lockfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ com.google.protobuf:protobuf-java:3.25.3=annotationProcessor,errorprone,testAnno
com.j256.simplemagic:simplemagic:1.17=jarValidation,runtimeClasspath,testRuntimeClasspath
com.jayway.jsonpath:json-path:2.9.0=jarValidation,runtimeClasspath,testRuntimeClasspath
com.lmax:disruptor:3.4.4=jarValidation,runtimeClasspath,testRuntimeClasspath
com.squareup.okhttp3:okhttp:4.12.0=jarValidation,runtimeClasspath,testRuntimeClasspath
com.squareup.okio:okio-jvm:3.6.0=jarValidation,runtimeClasspath,testRuntimeClasspath
com.squareup.okio:okio:3.6.0=jarValidation,runtimeClasspath,testRuntimeClasspath
com.tdunning:t-digest:3.3=jarValidation,runtimeClasspath,testRuntimeClasspath
commons-cli:commons-cli:1.9.0=jarValidation,runtimeClasspath,testRuntimeClasspath
commons-codec:commons-codec:1.17.1=compileClasspath,jarValidation,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
Expand Down Expand Up @@ -59,6 +62,7 @@ io.opentelemetry:opentelemetry-api:1.50.0=compileClasspath,jarValidation,runtime
io.opentelemetry:opentelemetry-context:1.50.0=compileClasspath,jarValidation,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
io.opentelemetry:opentelemetry-exporter-common:1.50.0=jarValidation,runtimeClasspath,testRuntimeClasspath
io.opentelemetry:opentelemetry-exporter-prometheus:1.50.0-alpha=jarValidation,runtimeClasspath,testRuntimeClasspath
io.opentelemetry:opentelemetry-exporter-sender-okhttp:1.50.0=jarValidation,runtimeClasspath,testRuntimeClasspath
io.opentelemetry:opentelemetry-sdk-common:1.50.0=jarValidation,runtimeClasspath,testRuntimeClasspath
io.opentelemetry:opentelemetry-sdk-extension-autoconfigure-spi:1.50.0=jarValidation,runtimeClasspath,testRuntimeClasspath
io.opentelemetry:opentelemetry-sdk-logs:1.50.0=jarValidation,runtimeClasspath,testRuntimeClasspath
Expand Down Expand Up @@ -151,6 +155,11 @@ org.glassfish.jersey.media:jersey-media-json-jackson:3.1.9=jarValidation,runtime
org.hamcrest:hamcrest:3.0=compileClasspath,jarValidation,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
org.javassist:javassist:3.30.2-GA=jarValidation,runtimeClasspath,testRuntimeClasspath
org.jctools:jctools-core:4.0.5=compileClasspath,jarValidation,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
org.jetbrains.kotlin:kotlin-stdlib-common:2.1.10=jarValidation,runtimeClasspath,testRuntimeClasspath
org.jetbrains.kotlin:kotlin-stdlib-jdk7:2.1.10=jarValidation,runtimeClasspath,testRuntimeClasspath
org.jetbrains.kotlin:kotlin-stdlib-jdk8:2.1.10=jarValidation,runtimeClasspath,testRuntimeClasspath
org.jetbrains.kotlin:kotlin-stdlib:2.1.10=jarValidation,runtimeClasspath,testRuntimeClasspath
org.jetbrains:annotations:26.0.2=jarValidation,runtimeClasspath,testRuntimeClasspath
org.jspecify:jspecify:1.0.0=annotationProcessor,errorprone,testAnnotationProcessor
org.junit.jupiter:junit-jupiter-api:5.6.2=jarValidation,runtimeClasspath,testRuntimeClasspath
org.junit.platform:junit-platform-commons:1.6.2=jarValidation,runtimeClasspath,testRuntimeClasspath
Expand Down
3 changes: 3 additions & 0 deletions solr/core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ dependencies {
implementation(libs.opentelemetry.sdk, {
exclude group: "io.opentelemetry", module: "opentelemetry-sdk-logs"
})
runtimeOnly libs.opentelemetry.exporter.sender.okhttp

implementation libs.apache.commons.exec

Expand Down Expand Up @@ -217,4 +218,6 @@ dependencies {
testRuntimeOnly(libs.mockito.subclass, {
exclude group: "net.bytebuddy", module: "byte-buddy-agent"
})

testImplementation libs.opentelemetry.sdktesting
}
12 changes: 11 additions & 1 deletion solr/core/gradle.lockfile
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ com.google.protobuf:protobuf-java:3.25.3=annotationProcessor,errorprone,testAnno
com.ibm.icu:icu4j:74.2=jarValidation,testRuntimeClasspath
com.j256.simplemagic:simplemagic:1.17=compileClasspath,jarValidation,runtimeClasspath,runtimeLibs,testCompileClasspath,testRuntimeClasspath
com.jayway.jsonpath:json-path:2.9.0=compileClasspath,jarValidation,runtimeClasspath,runtimeLibs,testCompileClasspath,testRuntimeClasspath
com.squareup.okhttp3:okhttp:4.12.0=jarValidation,runtimeClasspath,runtimeLibs,testRuntimeClasspath
com.squareup.okio:okio-jvm:3.6.0=jarValidation,runtimeClasspath,runtimeLibs,testRuntimeClasspath
com.squareup.okio:okio:3.6.0=jarValidation,runtimeClasspath,runtimeLibs,testRuntimeClasspath
com.tdunning:t-digest:3.3=compileClasspath,jarValidation,runtimeClasspath,runtimeLibs,testCompileClasspath,testRuntimeClasspath
commons-cli:commons-cli:1.9.0=compileClasspath,jarValidation,runtimeClasspath,runtimeLibs,testCompileClasspath,testRuntimeClasspath
commons-codec:commons-codec:1.17.1=apiHelper,compileClasspath,jarValidation,runtimeClasspath,runtimeLibs,testCompileClasspath,testRuntimeClasspath
Expand Down Expand Up @@ -67,10 +70,12 @@ io.opentelemetry:opentelemetry-api:1.50.0=apiHelper,compileClasspath,jarValidati
io.opentelemetry:opentelemetry-context:1.50.0=apiHelper,compileClasspath,jarValidation,runtimeClasspath,runtimeLibs,testCompileClasspath,testRuntimeClasspath
io.opentelemetry:opentelemetry-exporter-common:1.50.0=jarValidation,runtimeClasspath,runtimeLibs,testRuntimeClasspath
io.opentelemetry:opentelemetry-exporter-prometheus:1.50.0-alpha=compileClasspath,jarValidation,runtimeClasspath,runtimeLibs,testCompileClasspath,testRuntimeClasspath
io.opentelemetry:opentelemetry-exporter-sender-okhttp:1.50.0=jarValidation,runtimeClasspath,runtimeLibs,testRuntimeClasspath
io.opentelemetry:opentelemetry-sdk-common:1.50.0=compileClasspath,jarValidation,runtimeClasspath,runtimeLibs,testCompileClasspath,testRuntimeClasspath
io.opentelemetry:opentelemetry-sdk-extension-autoconfigure-spi:1.50.0=jarValidation,runtimeClasspath,runtimeLibs,testRuntimeClasspath
io.opentelemetry:opentelemetry-sdk-logs:1.50.0=jarValidation,runtimeClasspath,runtimeLibs,testRuntimeClasspath
io.opentelemetry:opentelemetry-sdk-logs:1.50.0=jarValidation,runtimeClasspath,runtimeLibs,testCompileClasspath,testRuntimeClasspath
io.opentelemetry:opentelemetry-sdk-metrics:1.50.0=compileClasspath,jarValidation,runtimeClasspath,runtimeLibs,testCompileClasspath,testRuntimeClasspath
io.opentelemetry:opentelemetry-sdk-testing:1.50.0=jarValidation,testCompileClasspath,testRuntimeClasspath
io.opentelemetry:opentelemetry-sdk-trace:1.50.0=compileClasspath,jarValidation,runtimeClasspath,runtimeLibs,testCompileClasspath,testRuntimeClasspath
io.opentelemetry:opentelemetry-sdk:1.50.0=compileClasspath,jarValidation,runtimeClasspath,runtimeLibs,testCompileClasspath,testRuntimeClasspath
io.prometheus:prometheus-metrics-exposition-formats:1.1.0=compileClasspath,jarValidation,runtimeClasspath,runtimeLibs,testCompileClasspath,testRuntimeClasspath
Expand Down Expand Up @@ -183,6 +188,11 @@ org.glassfish.jersey.inject:jersey-hk2:3.1.9=compileClasspath,jarValidation,perm
org.glassfish.jersey.media:jersey-media-json-jackson:3.1.9=compileClasspath,jarValidation,permitUnusedDeclared,runtimeClasspath,runtimeLibs,testCompileClasspath,testRuntimeClasspath
org.hamcrest:hamcrest:3.0=jarValidation,testCompileClasspath,testRuntimeClasspath
org.javassist:javassist:3.30.2-GA=compileClasspath,jarValidation,permitUnusedDeclared,runtimeClasspath,runtimeLibs,testCompileClasspath,testRuntimeClasspath
org.jetbrains.kotlin:kotlin-stdlib-common:2.1.10=jarValidation,runtimeClasspath,runtimeLibs,testRuntimeClasspath
org.jetbrains.kotlin:kotlin-stdlib-jdk7:2.1.10=jarValidation,runtimeClasspath,runtimeLibs,testRuntimeClasspath
org.jetbrains.kotlin:kotlin-stdlib-jdk8:2.1.10=jarValidation,runtimeClasspath,runtimeLibs,testRuntimeClasspath
org.jetbrains.kotlin:kotlin-stdlib:2.1.10=jarValidation,runtimeClasspath,runtimeLibs,testRuntimeClasspath
org.jetbrains:annotations:26.0.2=jarValidation,runtimeClasspath,runtimeLibs,testRuntimeClasspath
org.jspecify:jspecify:1.0.0=annotationProcessor,errorprone,testAnnotationProcessor
org.junit.jupiter:junit-jupiter-api:5.6.2=jarValidation,testCompileClasspath,testRuntimeClasspath
org.junit.platform:junit-platform-commons:1.6.2=jarValidation,testCompileClasspath,testRuntimeClasspath
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@
import org.apache.solr.common.params.SolrParams;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.SuppressForbidden;
import org.apache.solr.core.MetricsConfig;
import org.apache.solr.core.PluginBag;
import org.apache.solr.core.PluginInfo;
import org.apache.solr.core.SolrInfoBean;
import org.apache.solr.metrics.SolrDelegateRegistryMetricsContext;
import org.apache.solr.metrics.SolrMetricManager;
import org.apache.solr.metrics.SolrMetricProducer;
import org.apache.solr.metrics.SolrMetricsContext;
import org.apache.solr.metrics.otel.NoopMetricExporter;
import org.apache.solr.metrics.otel.instruments.AttributedLongCounter;
import org.apache.solr.metrics.otel.instruments.AttributedLongTimer;
import org.apache.solr.request.SolrQueryRequest;
Expand Down Expand Up @@ -188,10 +188,7 @@ public static class HandlerMetrics {
public static final HandlerMetrics NO_OP =
new HandlerMetrics(
new SolrMetricsContext(
new SolrMetricManager(
null, new MetricsConfig.MetricsConfigBuilder().setEnabled(false).build()),
"NO_OP",
"NO_OP"),
new SolrMetricManager(new NoopMetricExporter()), "NO_OP", "NO_OP"),
Attributes.empty());

public final Meter numErrors;
Expand Down
46 changes: 40 additions & 6 deletions solr/core/src/java/org/apache/solr/metrics/SolrMetricManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
*/
package org.apache.solr.metrics;

import static org.apache.solr.metrics.otel.MetricExporterFactory.OTLP_EXPORTER_ENABLED;
import static org.apache.solr.metrics.otel.MetricExporterFactory.OTLP_EXPORTER_INTERVAL;

import com.codahale.metrics.Counter;
import com.codahale.metrics.Gauge;
import com.codahale.metrics.Histogram;
Expand Down Expand Up @@ -52,6 +55,8 @@
import io.opentelemetry.api.metrics.ObservableLongUpDownCounter;
import io.opentelemetry.exporter.prometheus.PrometheusMetricReader;
import io.opentelemetry.sdk.metrics.SdkMeterProvider;
import io.opentelemetry.sdk.metrics.export.MetricExporter;
import io.opentelemetry.sdk.metrics.export.PeriodicMetricReader;
import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.util.ArrayList;
Expand All @@ -74,6 +79,7 @@
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
import java.util.stream.Collectors;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.core.CoreContainer;
import org.apache.solr.core.MetricsConfig;
Expand All @@ -82,6 +88,8 @@
import org.apache.solr.core.SolrInfoBean;
import org.apache.solr.core.SolrResourceLoader;
import org.apache.solr.logging.MDCLoggingContext;
import org.apache.solr.metrics.otel.MetricExporterFactory;
import org.apache.solr.metrics.otel.NoopMetricExporter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;
Expand Down Expand Up @@ -152,8 +160,11 @@ public class SolrMetricManager {
private final ConcurrentMap<String, MeterProviderAndReaders> meterProviderAndReaders =
new ConcurrentHashMap<>();

public SolrMetricManager() {
private final MetricExporter metricExporter;

public SolrMetricManager(MetricExporter exporter) {
metricsConfig = new MetricsConfig.MetricsConfigBuilder().build();
metricExporter = exporter;
counterSupplier = MetricSuppliers.counterSupplier(null, null);
meterSupplier = MetricSuppliers.meterSupplier(null, null);
timerSupplier = MetricSuppliers.timerSupplier(null, null);
Expand All @@ -162,6 +173,7 @@ public SolrMetricManager() {

public SolrMetricManager(SolrResourceLoader loader, MetricsConfig metricsConfig) {
this.metricsConfig = metricsConfig;
this.metricExporter = loadMetricExporter(loader);
counterSupplier = MetricSuppliers.counterSupplier(loader, metricsConfig.getCounterSupplier());
meterSupplier = MetricSuppliers.meterSupplier(loader, metricsConfig.getMeterSupplier());
timerSupplier = MetricSuppliers.timerSupplier(loader, metricsConfig.getTimerSupplier());
Expand Down Expand Up @@ -723,10 +735,14 @@ public SdkMeterProvider meterProvider(String providerName) {
providerName,
key -> {
var reader = new PrometheusMetricReader(true, null);
// NOCOMMIT: We need to add a Periodic Metric Reader here if we want to push with OTLP
// with an exporter
var provider = SdkMeterProvider.builder().registerMetricReader(reader).build();
return new MeterProviderAndReaders(provider, reader);
var builder =
SdkMeterProvider.builder()
.registerMetricReader(reader)
.registerMetricReader(
PeriodicMetricReader.builder(metricExporter)
.setInterval(OTLP_EXPORTER_INTERVAL, TimeUnit.MILLISECONDS)
.build());
Comment on lines +740 to +744
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We are registering both the prometheus reader for our metrics endpoint and the periodic reader to push metrics to the OTLP exporter.

return new MeterProviderAndReaders(builder.build(), reader);
})
.sdkMeterProvider();
}
Expand Down Expand Up @@ -754,7 +770,7 @@ private static MetricRegistry getOrCreateRegistry(
*
* @param registry name of the registry to remove
*/
// TODO SOLR-17458: You can't delete OTEL meters
// NOCOMMIT: Remove this
public void removeRegistry(String registry) {
// NOCOMMIT Remove all closing Dropwizard registries
// close any reporters for this registry first
Expand Down Expand Up @@ -1670,6 +1686,24 @@ public PrometheusMetricReader getPrometheusMetricReader(String providerName) {
return (mpr != null) ? mpr.prometheusMetricReader() : null;
}

public MetricExporter getMetricExporter() {
return metricExporter;
}

private MetricExporter loadMetricExporter(SolrResourceLoader loader) {
if (!OTLP_EXPORTER_ENABLED) return new NoopMetricExporter();
try {
MetricExporterFactory exporterFactory =
loader.newInstance(
"org.apache.solr.opentelemetry.OtlpExporterFactory", MetricExporterFactory.class);
return exporterFactory.getExporter();
} catch (SolrException e) {
log.error(
"Could not load OTLP exporter. Check that the Open Telemetry module is enabled.", e);
return new NoopMetricExporter();
}
}

private record MeterProviderAndReaders(
SdkMeterProvider sdkMeterProvider, PrometheusMetricReader prometheusMetricReader) {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* 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.solr.metrics.otel;

import io.opentelemetry.sdk.metrics.export.MetricExporter;
import org.apache.solr.common.util.EnvUtils;

public interface MetricExporterFactory {

public static final Boolean OTLP_EXPORTER_ENABLED =
Boolean.parseBoolean(EnvUtils.getProperty("solr.metrics.otlpExporterEnabled", "false"));

public static final String OTLP_EXPORTER_PROTOCOL =
EnvUtils.getProperty("solr.metrics.otlpExporterProtocol", "grpc");

public static final int OTLP_EXPORTER_INTERVAL =
Integer.parseInt(EnvUtils.getProperty("solr.metrics.otlpExporterInterval", "60000"));

MetricExporter getExporter();
}
Loading