-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Add metrics OTLP endpoint skeleton #133296
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
Merged
felixbarny
merged 14 commits into
elastic:main
from
felixbarny:otlp-tsdb-empty-endpoint
Aug 27, 2025
+452
−9
Merged
Changes from 9 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
952608d
Add metrics OTLP endpoint skeleton
felixbarny 1b2b7b3
Remove protobuf for now
felixbarny 7a49f3b
Merge branch 'main' into otlp-tsdb-empty-endpoint
felixbarny 72fc5dd
Remove more proto stuff
felixbarny 4d093df
Fix test dependency declaration
felixbarny 8a17036
Merge remote-tracking branch 'origin/main' into otlp-tsdb-empty-endpoint
felixbarny 342373e
Fix action test
felixbarny 9361f16
Merge remote-tracking branch 'origin/main' into otlp-tsdb-empty-endpoint
felixbarny 0983788
Merge remote-tracking branch 'origin/main' into otlp-tsdb-empty-endpoint
felixbarny a69a7a2
Merge remote-tracking branch 'origin/main' into otlp-tsdb-empty-endpoint
felixbarny 57ea866
Skip tests when feature flag is disabled
felixbarny 3526993
Convert to java rest test
felixbarny 23731f3
Merge remote-tracking branch 'origin/main' into otlp-tsdb-empty-endpoint
felixbarny dd694e8
Use explicit type rater than var for exporter result
felixbarny File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
183 changes: 183 additions & 0 deletions
183
...ata/src/internalClusterTest/java/org/elasticsearch/action/otlp/OTLPMetricsIndexingIT.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,183 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.elasticsearch.action.otlp; | ||
|
||
import io.opentelemetry.api.common.Attributes; | ||
import io.opentelemetry.exporter.internal.FailedExportException; | ||
import io.opentelemetry.exporter.internal.grpc.GrpcExporterUtil; | ||
import io.opentelemetry.exporter.otlp.http.metrics.OtlpHttpMetricExporter; | ||
import io.opentelemetry.sdk.common.Clock; | ||
import io.opentelemetry.sdk.common.InstrumentationScopeInfo; | ||
import io.opentelemetry.sdk.metrics.SdkMeterProvider; | ||
import io.opentelemetry.sdk.metrics.data.MetricData; | ||
import io.opentelemetry.sdk.metrics.export.PeriodicMetricReader; | ||
import io.opentelemetry.sdk.metrics.internal.data.ImmutableDoublePointData; | ||
import io.opentelemetry.sdk.metrics.internal.data.ImmutableGaugeData; | ||
import io.opentelemetry.sdk.metrics.internal.data.ImmutableMetricData; | ||
import io.opentelemetry.sdk.resources.Resource; | ||
|
||
import org.elasticsearch.action.admin.cluster.node.info.NodeInfo; | ||
import org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse; | ||
import org.elasticsearch.action.admin.indices.template.get.GetComposableIndexTemplateAction; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.common.transport.TransportAddress; | ||
import org.elasticsearch.datastreams.DataStreamsPlugin; | ||
import org.elasticsearch.http.HttpInfo; | ||
import org.elasticsearch.index.mapper.extras.MapperExtrasPlugin; | ||
import org.elasticsearch.ingest.common.IngestCommonPlugin; | ||
import org.elasticsearch.painless.PainlessPlugin; | ||
import org.elasticsearch.plugins.Plugin; | ||
import org.elasticsearch.test.ESSingleNodeTestCase; | ||
import org.elasticsearch.test.InternalSettingsPlugin; | ||
import org.elasticsearch.xpack.aggregatemetric.AggregateMetricMapperPlugin; | ||
import org.elasticsearch.xpack.analytics.AnalyticsPlugin; | ||
import org.elasticsearch.xpack.constantkeyword.ConstantKeywordMapperPlugin; | ||
import org.elasticsearch.xpack.core.XPackPlugin; | ||
import org.elasticsearch.xpack.countedkeyword.CountedKeywordMapperPlugin; | ||
import org.elasticsearch.xpack.esql.plugin.EsqlPlugin; | ||
import org.elasticsearch.xpack.ilm.IndexLifecycle; | ||
import org.elasticsearch.xpack.oteldata.OTelPlugin; | ||
import org.elasticsearch.xpack.stack.StackPlugin; | ||
import org.elasticsearch.xpack.versionfield.VersionFieldPlugin; | ||
import org.elasticsearch.xpack.wildcard.Wildcard; | ||
|
||
import java.io.IOException; | ||
import java.net.InetSocketAddress; | ||
import java.time.Duration; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.concurrent.Executors; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import static io.opentelemetry.api.common.AttributeKey.stringKey; | ||
import static org.hamcrest.Matchers.anEmptyMap; | ||
import static org.hamcrest.Matchers.is; | ||
import static org.hamcrest.Matchers.not; | ||
|
||
public class OTLPMetricsIndexingIT extends ESSingleNodeTestCase { | ||
felixbarny marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
private static final Resource TEST_RESOURCE = Resource.create(Attributes.of(stringKey("service.name"), "elasticsearch")); | ||
private static final InstrumentationScopeInfo TEST_SCOPE = InstrumentationScopeInfo.create("io.opentelemetry.example.metrics"); | ||
private OtlpHttpMetricExporter exporter; | ||
private SdkMeterProvider meterProvider; | ||
|
||
@Override | ||
protected Collection<Class<? extends Plugin>> getPlugins() { | ||
return List.of( | ||
DataStreamsPlugin.class, | ||
InternalSettingsPlugin.class, | ||
OTelPlugin.class, | ||
StackPlugin.class, | ||
EsqlPlugin.class, | ||
VersionFieldPlugin.class, | ||
CountedKeywordMapperPlugin.class, | ||
ConstantKeywordMapperPlugin.class, | ||
MapperExtrasPlugin.class, | ||
Wildcard.class, | ||
IndexLifecycle.class, | ||
IngestCommonPlugin.class, | ||
XPackPlugin.class, | ||
PainlessPlugin.class, | ||
AnalyticsPlugin.class, | ||
AggregateMetricMapperPlugin.class | ||
); | ||
} | ||
|
||
@Override | ||
protected Settings nodeSettings() { | ||
Settings.Builder newSettings = Settings.builder(); | ||
newSettings.put(super.nodeSettings()); | ||
// This essentially disables the automatic updates to end_time settings of a data stream's latest backing index. | ||
felixbarny marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
newSettings.put(DataStreamsPlugin.TIME_SERIES_POLL_INTERVAL.getKey(), "10m"); | ||
return newSettings.build(); | ||
} | ||
|
||
@Override | ||
protected boolean addMockHttpTransport() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public void setUp() throws Exception { | ||
super.setUp(); | ||
exporter = OtlpHttpMetricExporter.builder().setEndpoint("http://localhost:" + getHttpPort() + "/_otlp/v1/metrics").build(); | ||
meterProvider = SdkMeterProvider.builder() | ||
.registerMetricReader( | ||
PeriodicMetricReader.builder(exporter) | ||
.setExecutor(Executors.newScheduledThreadPool(0)) | ||
.setInterval(Duration.ofNanos(Long.MAX_VALUE)) | ||
.build() | ||
) | ||
.build(); | ||
assertBusy(() -> { | ||
GetComposableIndexTemplateAction.Request getReq = new GetComposableIndexTemplateAction.Request(TEST_REQUEST_TIMEOUT, "*"); | ||
var templates = client().execute(GetComposableIndexTemplateAction.INSTANCE, getReq).actionGet().indexTemplates(); | ||
assertThat(templates, not(anEmptyMap())); | ||
}); | ||
} | ||
|
||
private int getHttpPort() { | ||
NodesInfoResponse nodesInfoResponse = client().admin().cluster().prepareNodesInfo().get(); | ||
assertFalse(nodesInfoResponse.hasFailures()); | ||
assertEquals(1, nodesInfoResponse.getNodes().size()); | ||
NodeInfo node = nodesInfoResponse.getNodes().getFirst(); | ||
assertNotNull(node.getInfo(HttpInfo.class)); | ||
TransportAddress publishAddress = node.getInfo(HttpInfo.class).address().publishAddress(); | ||
InetSocketAddress address = publishAddress.address(); | ||
return address.getPort(); | ||
} | ||
|
||
@Override | ||
public void tearDown() throws Exception { | ||
meterProvider.close(); | ||
super.tearDown(); | ||
} | ||
|
||
public void testIngestMetricDataViaMetricExporter() throws Exception { | ||
MetricData jvmMemoryMetricData = createDoubleGauge( | ||
felixbarny marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
TEST_RESOURCE, | ||
Attributes.empty(), | ||
"jvm.memory.total", | ||
Runtime.getRuntime().totalMemory(), | ||
"By", | ||
Clock.getDefault().now() | ||
); | ||
|
||
assertThrows("OTLP metrics is not implemented yet", RuntimeException.class, () -> export(List.of(jvmMemoryMetricData))); | ||
} | ||
|
||
private void export(List<MetricData> metrics) throws IOException { | ||
var result = exporter.export(metrics).join(10, TimeUnit.SECONDS); | ||
felixbarny marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
Throwable failure = result.getFailureThrowable(); | ||
if (failure instanceof FailedExportException.HttpExportException httpExportException) { | ||
throw new RuntimeException(GrpcExporterUtil.getStatusMessage(httpExportException.getResponse().responseBody())); | ||
} else if (failure != null) { | ||
throw new RuntimeException("Failed to export metrics", failure); | ||
} | ||
assertThat(result.isSuccess(), is(true)); | ||
admin().indices().prepareRefresh().execute().actionGet(); | ||
} | ||
|
||
private static MetricData createDoubleGauge( | ||
Resource resource, | ||
Attributes attributes, | ||
String name, | ||
double value, | ||
String unit, | ||
long timeEpochNanos | ||
) { | ||
return ImmutableMetricData.createDoubleGauge( | ||
resource, | ||
TEST_SCOPE, | ||
name, | ||
"Your description could be here.", | ||
unit, | ||
ImmutableGaugeData.create(List.of(ImmutableDoublePointData.create(timeEpochNanos, timeEpochNanos, attributes, value))) | ||
); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.