-
Notifications
You must be signed in to change notification settings - Fork 739
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
base: feature/SOLR-17458
Are you sure you want to change the base?
Changes from all commits
e93f977
50ad1b4
c416429
6b5a01f
2b2095a
a3365b0
2a21a55
7eab317
6d4f77b
006e308
d9762c6
3630cc4
1e7943f
9bd2deb
e3f2a58
d33a85d
96435eb
b594327
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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")); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doing some testing, since we use the |
||
case "none" -> new NoopMetricExporter(); | ||
default -> { | ||
log.warn( | ||
"Unknown OTLP exporter type: {}. Defaulting to NO-OP exporter.", | ||
OTLP_EXPORTER_PROTOCOL); | ||
yield new NoopMetricExporter(); | ||
} | ||
}; | ||
} | ||
} |
There was a problem hiding this comment.
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:
But this is directly pinned to your traces sampling rate.