-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This adds `MutableSpanEncoder.PROTO3` similar to what's available for `zipkin2.Span`. The code and tests are based on similar inside zipkin and brave. This is added to the reporter, not brave, to reduce version lock-up for a useful, but more rare encoding type. Fixes #178 Signed-off-by: Adrian Cole <[email protected]>
- Loading branch information
1 parent
bb3f5b7
commit be50820
Showing
28 changed files
with
2,317 additions
and
161 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
92 changes: 92 additions & 0 deletions
92
benchmarks/src/main/java/zipkin2/reporter/brave/MutableSpanBytesEncoderBenchmarks.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,92 @@ | ||
/* | ||
* 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.brave; | ||
|
||
import brave.handler.MutableSpan; | ||
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; | ||
import zipkin2.reporter.BytesEncoder; | ||
|
||
import static zipkin2.reporter.brave.MutableSpans.newBigClientSpan; | ||
import static zipkin2.reporter.brave.MutableSpans.newServerSpan; | ||
|
||
@Measurement(iterations = 5, time = 1) | ||
@Warmup(iterations = 10, time = 1) | ||
@Fork(3) | ||
@BenchmarkMode(Mode.SampleTime) | ||
@OutputTimeUnit(TimeUnit.MICROSECONDS) | ||
@State(Scope.Thread) | ||
@Threads(1) | ||
public class MutableSpanBytesEncoderBenchmarks { | ||
|
||
static final BytesEncoder<MutableSpan> jsonEncoder = MutableSpanBytesEncoder.JSON_V2; | ||
static final BytesEncoder<MutableSpan> protoEncoder = MutableSpanBytesEncoder.PROTO3; | ||
static final MutableSpan serverSpan = newServerSpan(); | ||
static final MutableSpan bigClientSpan = newBigClientSpan(); | ||
|
||
@Benchmark public int sizeInBytes_serverSpan_json() { | ||
return jsonEncoder.sizeInBytes(serverSpan); | ||
} | ||
|
||
@Benchmark public int sizeInBytes_serverSpan_proto() { | ||
return protoEncoder.sizeInBytes(serverSpan); | ||
} | ||
|
||
@Benchmark public byte[] encode_serverSpan_json() { | ||
return jsonEncoder.encode(serverSpan); | ||
} | ||
|
||
@Benchmark public byte[] encode_serverSpan_proto() { | ||
return protoEncoder.encode(serverSpan); | ||
} | ||
|
||
@Benchmark public int sizeInBytes_bigClientSpan_json() { | ||
return jsonEncoder.sizeInBytes(bigClientSpan); | ||
} | ||
|
||
@Benchmark public int sizeInBytes_bigClientSpan_proto() { | ||
return protoEncoder.sizeInBytes(bigClientSpan); | ||
} | ||
|
||
@Benchmark public byte[] encode_bigClientSpan_json() { | ||
return jsonEncoder.encode(bigClientSpan); | ||
} | ||
|
||
@Benchmark public byte[] encode_bigClientSpan_proto() { | ||
return protoEncoder.encode(bigClientSpan); | ||
} | ||
|
||
// Convenience main entry-point | ||
public static void main(String[] args) throws RunnerException { | ||
Options opt = new OptionsBuilder() | ||
.addProfiler("gc") | ||
.include(".*" + MutableSpanBytesEncoderBenchmarks.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
43 changes: 43 additions & 0 deletions
43
brave/src/main/java/zipkin2/reporter/brave/ZipkinProto3Encoder.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,43 @@ | ||
/* | ||
* 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.brave; | ||
|
||
import brave.Tag; | ||
import brave.Tags; | ||
import brave.handler.MutableSpan; | ||
import zipkin2.reporter.BytesEncoder; | ||
import zipkin2.reporter.Encoding; | ||
import zipkin2.reporter.brave.internal.ZipkinProto3Writer; | ||
|
||
final class ZipkinProto3Encoder implements BytesEncoder<MutableSpan> { | ||
static final BytesEncoder<MutableSpan> INSTANCE = new ZipkinProto3Encoder(Tags.ERROR); | ||
final ZipkinProto3Writer delegate; | ||
|
||
ZipkinProto3Encoder(Tag<Throwable> errorTag) { | ||
if (errorTag == null) throw new NullPointerException("errorTag == null"); | ||
this.delegate = new ZipkinProto3Writer(errorTag); | ||
} | ||
|
||
@Override public Encoding encoding() { | ||
return Encoding.PROTO3; | ||
} | ||
|
||
@Override public int sizeInBytes(MutableSpan span) { | ||
return delegate.sizeInBytes(span); | ||
} | ||
|
||
@Override public byte[] encode(MutableSpan span) { | ||
return delegate.write(span); | ||
} | ||
} |
Oops, something went wrong.