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 18 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
Empty file.
11 changes: 11 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 @@ -72,7 +75,10 @@ io.netty:netty-transport:4.1.114.Final=jarValidation,testCompileClasspath,testRu
io.opentelemetry:opentelemetry-api:1.50.0=jarValidation,testCompileClasspath,testRuntimeClasspath
io.opentelemetry:opentelemetry-context:1.50.0=jarValidation,testCompileClasspath,testRuntimeClasspath
io.opentelemetry:opentelemetry-exporter-common:1.50.0=jarValidation,testRuntimeClasspath
io.opentelemetry:opentelemetry-exporter-otlp-common:1.50.0=jarValidation,testRuntimeClasspath
io.opentelemetry:opentelemetry-exporter-otlp: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 +185,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
11 changes: 11 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 @@ -58,7 +61,10 @@ io.netty:netty-transport:4.1.114.Final=compileClasspath,jarValidation,runtimeCla
io.opentelemetry:opentelemetry-api:1.50.0=compileClasspath,jarValidation,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
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-otlp-common:1.50.0=jarValidation,runtimeClasspath,testRuntimeClasspath
io.opentelemetry:opentelemetry-exporter-otlp: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 +157,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 @@ -156,6 +156,7 @@ dependencies {
// Distributed Tracing
api libs.opentelemetry.api
implementation libs.opentelemetry.context
implementation libs.opentelemetry.exporter.otlp

implementation(libs.opentelemetry.exporter.prometheus, {
exclude group: "io.prometheus", module: "prometheus-metrics-exporter-httpserver"
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
}
14 changes: 13 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 @@ -66,11 +69,15 @@ io.netty:netty-transport:4.1.114.Final=apiHelper,compileClasspath,jarValidation,
io.opentelemetry:opentelemetry-api:1.50.0=apiHelper,compileClasspath,jarValidation,runtimeClasspath,runtimeLibs,testCompileClasspath,testRuntimeClasspath
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-otlp-common:1.50.0=jarValidation,runtimeClasspath,runtimeLibs,testRuntimeClasspath
io.opentelemetry:opentelemetry-exporter-otlp:1.50.0=compileClasspath,jarValidation,runtimeClasspath,runtimeLibs,testCompileClasspath,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=compileClasspath,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 +190,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
34 changes: 28 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,10 @@
*/
package org.apache.solr.metrics;

import static org.apache.solr.metrics.otel.OtlpExporterFactory.OTLP_EXPORTER_ENABLED;
import static org.apache.solr.metrics.otel.OtlpExporterFactory.OTLP_EXPORTER_INTERVAL;
import static org.apache.solr.metrics.otel.OtlpExporterFactory.OTLP_EXPORTER_PROTOCOL;

import com.codahale.metrics.Counter;
import com.codahale.metrics.Gauge;
import com.codahale.metrics.Histogram;
Expand Down Expand Up @@ -52,6 +56,10 @@
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 io.opentelemetry.sdk.metrics.internal.SdkMeterProviderUtil;
import io.opentelemetry.sdk.metrics.internal.exemplar.ExemplarFilter;
import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.util.ArrayList;
Expand Down Expand Up @@ -82,6 +90,7 @@
import org.apache.solr.core.SolrInfoBean;
import org.apache.solr.core.SolrResourceLoader;
import org.apache.solr.logging.MDCLoggingContext;
import org.apache.solr.metrics.otel.OtlpExporterFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;
Expand Down Expand Up @@ -152,8 +161,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 +174,7 @@ public SolrMetricManager() {

public SolrMetricManager(SolrResourceLoader loader, MetricsConfig metricsConfig) {
this.metricsConfig = metricsConfig;
this.metricExporter = OtlpExporterFactory.getExporter();
counterSupplier = MetricSuppliers.counterSupplier(loader, metricsConfig.getCounterSupplier());
meterSupplier = MetricSuppliers.meterSupplier(loader, metricsConfig.getMeterSupplier());
timerSupplier = MetricSuppliers.timerSupplier(loader, metricsConfig.getTimerSupplier());
Expand Down Expand Up @@ -723,10 +736,15 @@ 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);
if (OTLP_EXPORTER_ENABLED && !OTLP_EXPORTER_PROTOCOL.equals("none")) {
builder.registerMetricReader(
PeriodicMetricReader.builder(metricExporter)
.setInterval(OTLP_EXPORTER_INTERVAL, TimeUnit.MILLISECONDS)
.build());
}
SdkMeterProviderUtil.setExemplarFilter(builder, ExemplarFilter.traceBased());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adding in trace based exemplars. If you have Solr distributed trace on and push with OTLP to something like the OTEL collector, you can get exemplars on the metrics honored across the pipeline like so:

solr_metrics_core_requests_times_milliseconds_bucket{collection="demo",core="demo_shard1_replica_n1",handler="/update",job="unknown_service:java",replica="replica_n1",shard="shard1",le="50.0"} 26 1.751574499605e+09 # {trace_id="4438406367ea8ea60f53e3f6e26a409d",span_id="d797ab840ed14e6d"} 30.0 1.75157449662e+09

But this is directly pinned to your traces sampling rate.

return new MeterProviderAndReaders(builder.build(), reader);
})
.sdkMeterProvider();
}
Expand Down Expand Up @@ -754,7 +772,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 +1688,10 @@ public PrometheusMetricReader getPrometheusMetricReader(String providerName) {
return (mpr != null) ? mpr.prometheusMetricReader() : null;
}

public MetricExporter getMetricExporter() {
return metricExporter;
}

private record MeterProviderAndReaders(
SdkMeterProvider sdkMeterProvider, PrometheusMetricReader prometheusMetricReader) {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* 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.common.CompletableResultCode;
import io.opentelemetry.sdk.metrics.InstrumentType;
import io.opentelemetry.sdk.metrics.data.AggregationTemporality;
import io.opentelemetry.sdk.metrics.data.MetricData;
import io.opentelemetry.sdk.metrics.export.MetricExporter;
import java.util.Collection;

public class NoopMetricExporter implements MetricExporter {
@Override
public CompletableResultCode export(Collection<MetricData> metrics) {
return CompletableResultCode.ofSuccess();
}

@Override
public CompletableResultCode flush() {
return CompletableResultCode.ofSuccess();
}

@Override
public CompletableResultCode shutdown() {
return CompletableResultCode.ofSuccess();
}

@Override
public AggregationTemporality getAggregationTemporality(InstrumentType instrumentType) {
return AggregationTemporality.CUMULATIVE;
}
}
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.solr.metrics.otel;

import io.opentelemetry.exporter.otlp.http.metrics.OtlpHttpMetricExporter;
import io.opentelemetry.exporter.otlp.metrics.OtlpGrpcMetricExporter;
import io.opentelemetry.sdk.metrics.export.MetricExporter;
import java.lang.invoke.MethodHandles;
import org.apache.solr.common.util.EnvUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Factory class for creating OpenTelemetry OTLP metric exporters and its configuration properties.
*
* @see io.opentelemetry.exporter.otlp.http.metrics.OtlpHttpMetricExporter
* @see io.opentelemetry.exporter.otlp.metrics.OtlpGrpcMetricExporter
* @see NoopMetricExporter
*/
public class OtlpExporterFactory {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's debatable if this should be here in Core. Should we actually move this into the Open Telemetry module for the OTLP exporter? OTLP tracing exporter is enabled with module only so maybe metrics as well.


private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());

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

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

public static final int OTLP_EXPORTER_INTERVAL =
Integer.parseInt(EnvUtils.getProperty("solr.otlpMetricExporterInterval", "60000"));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

60 seconds is the default according to otel spec so copied it here but users can change the interval as they wish.


public static MetricExporter getExporter() {
if (!OTLP_EXPORTER_ENABLED) {
log.info("OTLP metric exporter is disabled.");
return new NoopMetricExporter();
}

return switch (OTLP_EXPORTER_PROTOCOL) {
case "grpc" -> OtlpGrpcMetricExporter.getDefault();
case "http" -> OtlpHttpMetricExporter.getDefault();
Comment on lines +54 to +55
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Doing some testing, since we use the getDefault for both grpc and http, it actually reads some default env variables without us having to instrument our own read and configure for the exporter. For example, OTEL_EXPORTER_OTLP_ENDPOINT can change the endpoint where the metrics are pushed but I need to find all the different parameters that this picks up from documentation somewhere.

case "none" -> new NoopMetricExporter();
default -> {
log.warn(
"Unknown OTLP exporter type: {}. Defaulting to NO-OP exporter.",
OTLP_EXPORTER_PROTOCOL);
yield new NoopMetricExporter();
}
};
}
}
Loading