Skip to content

Commit

Permalink
Adds Brave Encoding support for v2 (#208)
Browse files Browse the repository at this point in the history
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
codefromthecrypt authored Jan 9, 2024
1 parent 269a5f1 commit 0142330
Show file tree
Hide file tree
Showing 40 changed files with 1,056 additions and 200 deletions.
31 changes: 21 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,52 @@
[![Maven Central](https://img.shields.io/maven-central/v/io.zipkin.gcp/zipkin-module-gcp.svg)](https://search.maven.org/search?q=g:io.zipkin.gcp%20AND%20a:zipkin-module-gcp)

# zipkin-gcp
Shared libraries that provide Zipkin integration with the Google Cloud Platform. Requires JRE 8 or later.
Shared libraries that provide Zipkin integration with the Google Cloud Platform. Requires JRE 11 or later.

# Usage
These components integrate traced applications and servers through Google Cloud services
via interfaces defined in [Zipkin](https://github.com/openzipkin/zipkin)
and [zipkin-reporter-java](https://github.com/openzipkin/zipkin-reporter-java).

## Senders
The component in an traced application that sends timing data (spans)
The component in a traced application that sends timing data (spans)
out of process is called a Sender. Senders are called on interval by an
[async reporter](https://github.com/openzipkin/zipkin-reporter-java#asyncreporter).

NOTE: Applications can be written in any language, while we currently
only have senders in Java, senders in other languages are welcome.

Sender | Description
--- | ---
[Stackdriver Trace](./sender/stackdriver) | Free cloud service provider
| Sender | Description |
|-------------------------------------------|-----------------------------|
| [Stackdriver Trace](./sender-stackdriver) | Free cloud service provider |

### Encoders

Encoding is library-specific, as some libraries use `zipkin2.Span` and others
`brave.handler.MutableSpan`. Both options are available to encode to the
StackDriver Trave V2 format.

| Encoder | Description |
|---------------------------------------------------------|------------------------------------------------|
| [`StackdriverEncoder.V2`](./encoder-stackdriver-zipkin) | zipkin-reporter `AsyncReporter<Span>` |
| [`StackdriverV2Encoder`](./encoder-stackdriver-brave) | zipkin-reporter-brave `AsyncZipkinSpanHandler` |

## Collectors
The component in a zipkin server that receives trace data is called a
collector. This decodes spans reported by applications and persists them
to a configured storage component.

Collector | Description
--- | ---
| Collector | Description |
|-----------|-------------|

## Storage
The component in a zipkin server that persists and queries collected
data is called `StorageComponent`. This primarily supports the Zipkin
Api and all collector components.

Storage | Description
--- | ---
[Stackdriver Trace](./storage/stackdriver) | Free cloud service provider
| Storage | Description |
|--------------------------------------------|-----------------------------|
| [Stackdriver Trace](./storage/stackdriver) | Free cloud service provider |

## Server integration
In order to integrate with zipkin-server, you need to use properties
Expand Down
17 changes: 16 additions & 1 deletion benchmarks/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<parent>
<artifactId>zipkin-gcp-parent</artifactId>
<groupId>io.zipkin.gcp</groupId>
<version>1.1.2-SNAPSHOT</version>
<version>2.0.0-SNAPSHOT</version>
</parent>

<artifactId>benchmarks</artifactId>
Expand All @@ -38,6 +38,16 @@
<artifactId>zipkin-storage-stackdriver</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>zipkin-encoder-stackdriver</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>brave-encoder-stackdriver</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>zipkin-sender-stackdriver</artifactId>
Expand All @@ -49,6 +59,11 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>${brave.groupId}</groupId>
<artifactId>brave</artifactId>
<version>${brave.version}</version>
</dependency>

<dependency>
<groupId>org.openjdk.jmh</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2019 The OpenZipkin Authors
* 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
Expand Down Expand Up @@ -31,9 +31,10 @@
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import zipkin2.reporter.stackdriver.zipkin.StackdriverEncoder;

import static zipkin2.reporter.stackdriver.StackdriverEncoderBenchmarks.CLIENT_SPAN;
import static zipkin2.reporter.stackdriver.StackdriverSender.SPAN_ID_PREFIX;
import static zipkin2.reporter.stackdriver.zipkin.StackdriverEncoderBenchmarks.CLIENT_SPAN;

@Measurement(iterations = 5, time = 1)
@Warmup(iterations = 10, time = 1)
Expand Down
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();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2019 The OpenZipkin Authors
* 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
Expand All @@ -11,7 +11,7 @@
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
package zipkin2.reporter.stackdriver;
package zipkin2.reporter.stackdriver.zipkin;

import java.util.concurrent.TimeUnit;
import org.openjdk.jmh.annotations.Benchmark;
Expand Down Expand Up @@ -40,7 +40,7 @@
@State(Scope.Thread)
@Threads(1)
public class StackdriverEncoderBenchmarks {
static final Span CLIENT_SPAN =
public static final Span CLIENT_SPAN =
Span.newBuilder()
.traceId("7180c278b62e8f6a216a2aea45d08fc9")
.parentId("6b221d5bc9e6496c")
Expand Down
2 changes: 1 addition & 1 deletion collector-pubsub/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<parent>
<artifactId>zipkin-gcp-parent</artifactId>
<groupId>io.zipkin.gcp</groupId>
<version>1.1.2-SNAPSHOT</version>
<version>2.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
8 changes: 8 additions & 0 deletions encoder-stackdriver-brave/README.md
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));
```
68 changes: 68 additions & 0 deletions encoder-stackdriver-brave/pom.xml
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>
Loading

0 comments on commit 0142330

Please sign in to comment.