-
Notifications
You must be signed in to change notification settings - Fork 895
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
Add tracing support for internals and JSON-RPC #1557
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
017596e
Add tracing support for internals and JSON-RPC
atoulme 8ef03ea
Remove rocksdb tracing as it slows down execution too much
atoulme edea3bb
Add B3 headers extraction on JSON-RPC requests
atoulme 710bd02
Remove traces around trie tree as they slow down syncing significantly
atoulme 6efba27
Add tracing to fast sync pipeline
atoulme 22f2e97
Add tracing for all pipelines
atoulme 6fcc971
Address code review
atoulme 38a2fe3
Add acceptance tests and break out the shaded dependency
atoulme 7568778
Fix tracer id
atoulme f8afca1
Revert changes to trie
atoulme c6f2ccd
Upgrade otel to latest, remove old tracing
atoulme 80f7348
Code review comments
atoulme 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 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 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
171 changes: 171 additions & 0 deletions
171
...ests/src/test/java/org/hyperledger/besu/tests/acceptance/OpenTelemetryAcceptanceTest.java
This file contains 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,171 @@ | ||
/* | ||
* 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.tests.acceptance; | ||
|
||
import static java.util.Collections.singletonList; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import org.hyperledger.besu.metrics.MetricsProtocol; | ||
import org.hyperledger.besu.metrics.prometheus.MetricsConfiguration; | ||
import org.hyperledger.besu.tests.acceptance.dsl.AcceptanceTestBase; | ||
import org.hyperledger.besu.tests.acceptance.dsl.WaitUtils; | ||
import org.hyperledger.besu.tests.acceptance.dsl.node.BesuNode; | ||
import org.hyperledger.besu.tests.acceptance.dsl.node.configuration.BesuNodeConfigurationBuilder; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import com.google.common.io.Closer; | ||
import io.grpc.Server; | ||
import io.grpc.Status; | ||
import io.grpc.netty.NettyServerBuilder; | ||
import io.grpc.stub.StreamObserver; | ||
import io.opentelemetry.proto.collector.metrics.v1.ExportMetricsServiceRequest; | ||
import io.opentelemetry.proto.collector.metrics.v1.ExportMetricsServiceResponse; | ||
import io.opentelemetry.proto.collector.metrics.v1.MetricsServiceGrpc; | ||
import io.opentelemetry.proto.collector.trace.v1.ExportTraceServiceRequest; | ||
import io.opentelemetry.proto.collector.trace.v1.ExportTraceServiceResponse; | ||
import io.opentelemetry.proto.collector.trace.v1.TraceServiceGrpc; | ||
import io.opentelemetry.proto.metrics.v1.ResourceMetrics; | ||
import io.opentelemetry.proto.trace.v1.ResourceSpans; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
public class OpenTelemetryAcceptanceTest extends AcceptanceTestBase { | ||
|
||
private static final class FakeCollector extends TraceServiceGrpc.TraceServiceImplBase { | ||
private final List<ResourceSpans> receivedSpans = new ArrayList<>(); | ||
private Status returnedStatus = Status.OK; | ||
|
||
@Override | ||
public void export( | ||
final ExportTraceServiceRequest request, | ||
final StreamObserver<ExportTraceServiceResponse> responseObserver) { | ||
receivedSpans.addAll(request.getResourceSpansList()); | ||
responseObserver.onNext(ExportTraceServiceResponse.newBuilder().build()); | ||
if (!returnedStatus.isOk()) { | ||
if (returnedStatus.getCode() == Status.Code.DEADLINE_EXCEEDED) { | ||
// Do not call onCompleted to simulate a deadline exceeded. | ||
return; | ||
} | ||
responseObserver.onError(returnedStatus.asRuntimeException()); | ||
return; | ||
} | ||
responseObserver.onCompleted(); | ||
} | ||
|
||
List<ResourceSpans> getReceivedSpans() { | ||
return receivedSpans; | ||
} | ||
|
||
void setReturnedStatus(final Status returnedStatus) { | ||
this.returnedStatus = returnedStatus; | ||
} | ||
} | ||
|
||
private static final class FakeMetricsCollector | ||
extends MetricsServiceGrpc.MetricsServiceImplBase { | ||
private final List<ResourceMetrics> receivedMetrics = new ArrayList<>(); | ||
private Status returnedStatus = Status.OK; | ||
|
||
@Override | ||
public void export( | ||
final ExportMetricsServiceRequest request, | ||
final StreamObserver<ExportMetricsServiceResponse> responseObserver) { | ||
|
||
receivedMetrics.addAll(request.getResourceMetricsList()); | ||
responseObserver.onNext(ExportMetricsServiceResponse.newBuilder().build()); | ||
if (!returnedStatus.isOk()) { | ||
if (returnedStatus.getCode() == Status.Code.DEADLINE_EXCEEDED) { | ||
// Do not call onCompleted to simulate a deadline exceeded. | ||
return; | ||
} | ||
responseObserver.onError(returnedStatus.asRuntimeException()); | ||
return; | ||
} | ||
responseObserver.onCompleted(); | ||
} | ||
|
||
List<ResourceMetrics> getReceivedMetrics() { | ||
return receivedMetrics; | ||
} | ||
|
||
void setReturnedStatus(final Status returnedStatus) { | ||
this.returnedStatus = returnedStatus; | ||
} | ||
} | ||
|
||
private final FakeMetricsCollector fakeMetricsCollector = new FakeMetricsCollector(); | ||
private final FakeCollector fakeTracesCollector = new FakeCollector(); | ||
private final Closer closer = Closer.create(); | ||
|
||
private BesuNode metricsNode; | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
Server server = | ||
NettyServerBuilder.forPort(4317) | ||
.addService(fakeTracesCollector) | ||
.addService(fakeMetricsCollector) | ||
.build() | ||
.start(); | ||
closer.register(server::shutdownNow); | ||
|
||
MetricsConfiguration configuration = | ||
MetricsConfiguration.builder() | ||
.protocol(MetricsProtocol.OPENTELEMETRY) | ||
.enabled(true) | ||
.port(0) | ||
.hostsAllowlist(singletonList("*")) | ||
.build(); | ||
metricsNode = | ||
besu.create( | ||
new BesuNodeConfigurationBuilder() | ||
.name("metrics-node") | ||
.jsonRpcEnabled() | ||
.metricsConfiguration(configuration) | ||
.build()); | ||
cluster.start(metricsNode); | ||
} | ||
|
||
@After | ||
public void tearDown() throws Exception { | ||
closer.close(); | ||
} | ||
|
||
@Test | ||
public void metricsReporting() { | ||
WaitUtils.waitFor( | ||
30, | ||
() -> { | ||
List<ResourceMetrics> resourceMetrics = fakeMetricsCollector.getReceivedMetrics(); | ||
assertThat(resourceMetrics.isEmpty()).isFalse(); | ||
}); | ||
} | ||
|
||
@Test | ||
public void traceReporting() { | ||
|
||
WaitUtils.waitFor( | ||
30, | ||
() -> { | ||
// call the json RPC endpoint to generate a trace. | ||
net.netVersion().verify(metricsNode); | ||
List<ResourceSpans> spans = fakeTracesCollector.getReceivedSpans(); | ||
assertThat(spans.isEmpty()).isFalse(); | ||
}); | ||
} | ||
} |
This file contains 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 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 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 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 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 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 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 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
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.
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.
What changed so that we no longer need the java agent for OTEL? I'm not seeing anything code-wise so I'm concerned this is an accidental deletion.
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.
The agent inspects the code and injects changes at runtime to create traces from well-known libraries such as SQL querying or HTTP. We now do this manually and in a much more targeted fashion. We no longer need to use automatic instrumentation. Automatic instrumentation could also create extra traces that don't provide as much value.