-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds Brave Encoding support for v2 (#208)
This adds two new artifacts to allow StackdriverSender to have no zipkin dependency: * zipkin-encoder-stackdriver: zipkin2.Span encoder from before * brave-encoder-stackdriver: new brave.handler.MutableSpan encoder The main change is `StackdriverEncoder.V2` is moved to a new package: `zipkin2.reporter.stackdriver.zipkin`, where it was formerly one level up. This is the part that decouples the classpath. Most won't use this encoder anymore as you can use Brave directly like so: ```java spanHandler = AsyncZipkinSpanHandler.newBuilder(sender).build(new StackdriverV2Encoder(Tags.ERROR)); ``` Signed-off-by: Adrian Cole <[email protected]>
- Loading branch information
1 parent
269a5f1
commit 0142330
Showing
40 changed files
with
1,056 additions
and
200 deletions.
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
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
97 changes: 97 additions & 0 deletions
97
...arks/src/main/java/zipkin2/reporter/stackdriver/brave/StackdriverV2EncoderBenchmarks.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,97 @@ | ||
/* | ||
* Copyright 2016-2024 The OpenZipkin Authors | ||
* | ||
* 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. | ||
*/ | ||
package zipkin2.reporter.stackdriver.brave; | ||
|
||
import brave.Tags; | ||
import brave.handler.MutableSpan; | ||
import brave.handler.MutableSpanBytesEncoder; | ||
import java.util.concurrent.TimeUnit; | ||
import org.openjdk.jmh.annotations.Benchmark; | ||
import org.openjdk.jmh.annotations.BenchmarkMode; | ||
import org.openjdk.jmh.annotations.Fork; | ||
import org.openjdk.jmh.annotations.Measurement; | ||
import org.openjdk.jmh.annotations.Mode; | ||
import org.openjdk.jmh.annotations.OutputTimeUnit; | ||
import org.openjdk.jmh.annotations.Scope; | ||
import org.openjdk.jmh.annotations.State; | ||
import org.openjdk.jmh.annotations.Threads; | ||
import org.openjdk.jmh.annotations.Warmup; | ||
import org.openjdk.jmh.runner.Runner; | ||
import org.openjdk.jmh.runner.RunnerException; | ||
import org.openjdk.jmh.runner.options.Options; | ||
import org.openjdk.jmh.runner.options.OptionsBuilder; | ||
|
||
@Measurement(iterations = 5, time = 1) | ||
@Warmup(iterations = 10, time = 1) | ||
@Fork(3) | ||
@BenchmarkMode(Mode.AverageTime) | ||
@OutputTimeUnit(TimeUnit.MICROSECONDS) | ||
@State(Scope.Thread) | ||
@Threads(1) | ||
public class StackdriverV2EncoderBenchmarks { | ||
static final StackdriverV2Encoder encoder = new StackdriverV2Encoder(Tags.ERROR); | ||
static final MutableSpanBytesEncoder braveEncoder = | ||
MutableSpanBytesEncoder.zipkinJsonV2(Tags.ERROR); | ||
static final MutableSpan CLIENT_SPAN = clientSpan(); | ||
|
||
static MutableSpan clientSpan() { | ||
MutableSpan braveSpan = new MutableSpan(); | ||
braveSpan.traceId("7180c278b62e8f6a216a2aea45d08fc9"); | ||
braveSpan.parentId("6b221d5bc9e6496c"); | ||
braveSpan.id("5b4185666d50f68b"); | ||
braveSpan.name("get"); | ||
braveSpan.kind(brave.Span.Kind.CLIENT); | ||
braveSpan.localServiceName("frontend"); | ||
braveSpan.localIp("127.0.0.1"); | ||
braveSpan.remoteServiceName("backend"); | ||
braveSpan.remoteIpAndPort("192.168.99.101", 9000); | ||
braveSpan.startTimestamp(1472470996199000L); | ||
braveSpan.finishTimestamp(1472470996199000L + 207000L); | ||
braveSpan.annotate(1472470996238000L, "foo"); | ||
braveSpan.annotate(1472470996403000L, "bar"); | ||
braveSpan.tag("clnt/finagle.version", "6.45.0"); | ||
braveSpan.tag("http.path", "/api"); | ||
return braveSpan; | ||
} | ||
|
||
@Benchmark | ||
public int sizeInBytesClientSpan_json_zipkin_json() { | ||
return braveEncoder.sizeInBytes(CLIENT_SPAN); | ||
} | ||
|
||
@Benchmark | ||
public int sizeInBytesClientSpan_json_stackdriver_proto3() { | ||
return encoder.sizeInBytes(CLIENT_SPAN); | ||
} | ||
|
||
@Benchmark | ||
public byte[] encodeClientSpan_json_zipkin_json() { | ||
return braveEncoder.encode(CLIENT_SPAN); | ||
} | ||
|
||
@Benchmark | ||
public byte[] encodeClientSpan_json_stackdriver_proto3() { | ||
return encoder.encode(CLIENT_SPAN); | ||
} | ||
|
||
// Convenience main entry-point | ||
public static void main(String[] args) throws RunnerException { | ||
Options opt = | ||
new OptionsBuilder() | ||
.include(".*" + StackdriverV2EncoderBenchmarks.class.getSimpleName() + ".*") | ||
.build(); | ||
|
||
new Runner(opt).run(); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# encoder-stackdriver-brave | ||
|
||
This encodes brave spans into Stackdriver proto3 format. | ||
|
||
```java | ||
// connect the sender to the correct encoding | ||
spanHandler = AsyncZipkinSpanHandler.newBuilder(sender).build(new StackdriverV2Encoder(Tags.ERROR)); | ||
``` |
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,68 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright 2016-2024 The OpenZipkin Authors | ||
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. | ||
--> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>zipkin-gcp-parent</artifactId> | ||
<groupId>io.zipkin.gcp</groupId> | ||
<version>2.0.0-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>brave-encoder-stackdriver</artifactId> | ||
<name>Brave Encoder: Google Stackdriver Trace</name> | ||
|
||
<properties> | ||
<main.basedir>${project.basedir}/..</main.basedir> | ||
</properties> | ||
|
||
<dependencies> | ||
<!-- Translation deps --> | ||
<dependency> | ||
<groupId>com.google.api.grpc</groupId> | ||
<artifactId>proto-google-common-protos</artifactId> | ||
<version>${proto-google-common-protos.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.google.api.grpc</groupId> | ||
<artifactId>proto-google-cloud-trace-v2</artifactId> | ||
<version>${grpc-google-cloud-trace.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.google.protobuf</groupId> | ||
<artifactId>protobuf-java</artifactId> | ||
<version>${protobuf.version}</version> | ||
<!-- We use provided scope to avoid pinning a protobuf version --> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<!-- Encoder/Data type deps --> | ||
<dependency> | ||
<groupId>io.zipkin.reporter2</groupId> | ||
<artifactId>zipkin-reporter-brave</artifactId> | ||
<version>${zipkin-reporter.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>${brave.groupId}</groupId> | ||
<artifactId>brave</artifactId> | ||
<version>${brave.version}</version> | ||
<!-- Don't pin Brave --> | ||
<scope>provided</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
Oops, something went wrong.