mirror of https://github.com/hyperledger/besu
Upgrade OpenTelemetry (#3675)
* Upgrade OpenTelemetry Signed-off-by: Antoine Toulme <antoine@lunar-ocean.com> * remove a single sleep, poll with a for loop instead Signed-off-by: Antoine Toulme <antoine@lunar-ocean.com> * use the new approach to send trace requests Signed-off-by: Antoine Toulme <antoine@lunar-ocean.com> Co-authored-by: Sally MacFarlane <sally.macfarlane@consensys.net>pull/4005/head
parent
a0ac0ebad8
commit
78717ade1d
@ -0,0 +1,57 @@ |
||||
/* |
||||
* Copyright Besu Contributors |
||||
* |
||||
* Licensed 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. |
||||
* |
||||
* SPDX-License-Identifier: Apache-2.0 |
||||
*/ |
||||
package org.hyperledger.besu.metrics.opentelemetry; |
||||
|
||||
import java.util.Collection; |
||||
|
||||
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.CollectionRegistration; |
||||
import io.opentelemetry.sdk.metrics.export.MetricReader; |
||||
import io.opentelemetry.sdk.metrics.internal.export.MetricProducer; |
||||
import org.jetbrains.annotations.NotNull; |
||||
|
||||
class DebugMetricReader implements MetricReader { |
||||
private CollectionRegistration registration; |
||||
|
||||
public DebugMetricReader() {} |
||||
|
||||
public Collection<MetricData> getAllMetrics() { |
||||
return MetricProducer.asMetricProducer(this.registration).collectAllMetrics(); |
||||
} |
||||
|
||||
@Override |
||||
public void register(final @NotNull CollectionRegistration registration) { |
||||
this.registration = registration; |
||||
} |
||||
|
||||
@Override |
||||
public CompletableResultCode forceFlush() { |
||||
return CompletableResultCode.ofSuccess(); |
||||
} |
||||
|
||||
@Override |
||||
public CompletableResultCode shutdown() { |
||||
return CompletableResultCode.ofSuccess(); |
||||
} |
||||
|
||||
@Override |
||||
public AggregationTemporality getAggregationTemporality( |
||||
final @NotNull InstrumentType instrumentType) { |
||||
return AggregationTemporality.CUMULATIVE; |
||||
} |
||||
} |
@ -1,88 +0,0 @@ |
||||
/* |
||||
* Copyright ConsenSys AG. |
||||
* |
||||
* Licensed 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. |
||||
* |
||||
* SPDX-License-Identifier: Apache-2.0 |
||||
* |
||||
*/ |
||||
package org.hyperledger.besu.metrics.opentelemetry; |
||||
|
||||
import org.hyperledger.besu.metrics.MetricsService; |
||||
import org.hyperledger.besu.metrics.prometheus.MetricsConfiguration; |
||||
|
||||
import java.util.Collections; |
||||
import java.util.Optional; |
||||
import java.util.concurrent.CompletableFuture; |
||||
|
||||
import io.opentelemetry.exporter.otlp.metrics.OtlpGrpcMetricExporter; |
||||
import io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporter; |
||||
import io.opentelemetry.sdk.OpenTelemetrySdk; |
||||
import io.opentelemetry.sdk.common.CompletableResultCode; |
||||
import io.opentelemetry.sdk.metrics.export.IntervalMetricReader; |
||||
import io.opentelemetry.sdk.metrics.export.IntervalMetricReaderBuilder; |
||||
import io.opentelemetry.sdk.trace.SdkTracerProvider; |
||||
import io.opentelemetry.sdk.trace.SpanProcessor; |
||||
import io.opentelemetry.sdk.trace.export.BatchSpanProcessor; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
|
||||
public class MetricsOtelGrpcPushService implements MetricsService { |
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(MetricsOtelGrpcPushService.class); |
||||
|
||||
private final MetricsConfiguration configuration; |
||||
private final OpenTelemetrySystem metricsSystem; |
||||
private IntervalMetricReader periodicReader; |
||||
private SpanProcessor spanProcessor; |
||||
|
||||
public MetricsOtelGrpcPushService( |
||||
final MetricsConfiguration configuration, final OpenTelemetrySystem metricsSystem) { |
||||
|
||||
this.configuration = configuration; |
||||
this.metricsSystem = metricsSystem; |
||||
} |
||||
|
||||
@Override |
||||
public CompletableFuture<?> start() { |
||||
LOG.info("Starting OpenTelemetry push service"); |
||||
OtlpGrpcMetricExporter exporter = OtlpGrpcMetricExporter.getDefault(); |
||||
IntervalMetricReaderBuilder builder = |
||||
IntervalMetricReader.builder() |
||||
.setExportIntervalMillis(configuration.getPushInterval() * 1000L) |
||||
.setMetricProducers(Collections.singleton(metricsSystem.getMeterSdkProvider())) |
||||
.setMetricExporter(exporter); |
||||
this.periodicReader = builder.buildAndStart(); |
||||
this.spanProcessor = BatchSpanProcessor.builder(OtlpGrpcSpanExporter.builder().build()).build(); |
||||
OpenTelemetrySdk.builder() |
||||
.setTracerProvider(SdkTracerProvider.builder().addSpanProcessor(spanProcessor).build()) |
||||
.buildAndRegisterGlobal(); |
||||
return CompletableFuture.completedFuture(null); |
||||
} |
||||
|
||||
@Override |
||||
public CompletableFuture<?> stop() { |
||||
if (periodicReader != null) { |
||||
periodicReader.shutdown(); |
||||
} |
||||
if (spanProcessor != null) { |
||||
CompletableResultCode result = spanProcessor.shutdown(); |
||||
CompletableFuture<?> future = new CompletableFuture<>(); |
||||
result.whenComplete(() -> future.complete(null)); |
||||
return future; |
||||
} |
||||
return CompletableFuture.completedFuture(null); |
||||
} |
||||
|
||||
@Override |
||||
public Optional<Integer> getPort() { |
||||
return Optional.empty(); |
||||
} |
||||
} |
@ -0,0 +1,48 @@ |
||||
/* |
||||
* Copyright Hyperledger Besu Contributors |
||||
* |
||||
* Licensed 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. |
||||
* |
||||
* SPDX-License-Identifier: Apache-2.0 |
||||
* |
||||
*/ |
||||
package org.hyperledger.besu.metrics.opentelemetry; |
||||
|
||||
import org.hyperledger.besu.metrics.MetricsService; |
||||
|
||||
import java.util.Optional; |
||||
import java.util.concurrent.CompletableFuture; |
||||
|
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
|
||||
public class MetricsOtelPushService implements MetricsService { |
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(MetricsOtelPushService.class); |
||||
|
||||
public MetricsOtelPushService() {} |
||||
|
||||
@Override |
||||
public CompletableFuture<?> start() { |
||||
LOG.info("Starting OpenTelemetry push service"); |
||||
|
||||
return CompletableFuture.completedFuture(null); |
||||
} |
||||
|
||||
@Override |
||||
public CompletableFuture<?> stop() { |
||||
return CompletableFuture.completedFuture(null); |
||||
} |
||||
|
||||
@Override |
||||
public Optional<Integer> getPort() { |
||||
return Optional.empty(); |
||||
} |
||||
} |
Loading…
Reference in new issue