-
Notifications
You must be signed in to change notification settings - Fork 858
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Unify compression configuration for exporters (#4775)
* Fix handling of compressionMethod `none` in GrpcExporterBuilder * Fix handling of compressionMethod `none` in OkHttpExporterBuilder * Add compression configuration assertions to AbstractGrpcTelemetryExporterTest * Add compression configuration to JaegerGrpcSpanExporterBuilder * Add compression configuration to ZipkinSpanExporterBuilder * Specify that zipkin default compression is gzip Co-authored-by: Jack Berg <[email protected]>
- Loading branch information
1 parent
b6c58c5
commit fa46f19
Showing
13 changed files
with
445 additions
and
9 deletions.
There are no files selected for viewing
4 changes: 3 additions & 1 deletion
4
docs/apidiffs/current_vs_latest/opentelemetry-exporter-jaeger.txt
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 |
---|---|---|
@@ -1,2 +1,4 @@ | ||
Comparing source compatibility of against | ||
No changes. | ||
*** MODIFIED CLASS: PUBLIC FINAL io.opentelemetry.exporter.jaeger.JaegerGrpcSpanExporterBuilder (not serializable) | ||
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0 | ||
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.exporter.jaeger.JaegerGrpcSpanExporterBuilder setCompression(java.lang.String) |
4 changes: 3 additions & 1 deletion
4
docs/apidiffs/current_vs_latest/opentelemetry-exporter-zipkin.txt
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 |
---|---|---|
@@ -1,2 +1,4 @@ | ||
Comparing source compatibility of against | ||
No changes. | ||
*** MODIFIED CLASS: PUBLIC FINAL io.opentelemetry.exporter.zipkin.ZipkinSpanExporterBuilder (not serializable) | ||
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0 | ||
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.exporter.zipkin.ZipkinSpanExporterBuilder setCompression(java.lang.String) |
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
183 changes: 183 additions & 0 deletions
183
...common/src/test/java/io/opentelemetry/exporter/internal/grpc/GrpcExporterBuilderTest.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,183 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.exporter.internal.grpc; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
import com.google.common.util.concurrent.Futures; | ||
import com.google.common.util.concurrent.ListenableFuture; | ||
import io.grpc.CallOptions; | ||
import io.grpc.Channel; | ||
import io.grpc.Codec; | ||
import io.grpc.ManagedChannel; | ||
import io.opentelemetry.exporter.internal.marshal.Marshaler; | ||
import java.net.URI; | ||
import java.util.function.BiFunction; | ||
import java.util.function.Supplier; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class GrpcExporterBuilderTest { | ||
|
||
private final ManagedChannel channel = mock(ManagedChannel.class); | ||
|
||
private GrpcExporterBuilder<Marshaler> builder; | ||
|
||
@BeforeEach | ||
@SuppressWarnings("unchecked") | ||
void setUp() { | ||
Supplier<BiFunction<Channel, String, MarshalerServiceStub<Marshaler, ?, ?>>> grpcStubFactory = | ||
mock(Supplier.class); | ||
when(grpcStubFactory.get()) | ||
.thenReturn((c, s) -> new TestMarshalerServiceStub(c, CallOptions.DEFAULT)); | ||
|
||
builder = | ||
GrpcExporter.builder( | ||
"otlp", "span", 0, URI.create("http://localhost:4317"), grpcStubFactory, "/test"); | ||
} | ||
|
||
@Test | ||
void compressionDefault() { | ||
GrpcExporter<Marshaler> exporter = builder.build(); | ||
try { | ||
assertThat(exporter) | ||
.isInstanceOfSatisfying( | ||
OkHttpGrpcExporter.class, | ||
otlp -> assertThat(otlp).extracting("compressionEnabled").isEqualTo(false)); | ||
} finally { | ||
exporter.shutdown(); | ||
} | ||
} | ||
|
||
@Test | ||
void compressionNone() { | ||
GrpcExporter<Marshaler> exporter = builder.setCompression("none").build(); | ||
try { | ||
assertThat(exporter) | ||
.isInstanceOfSatisfying( | ||
OkHttpGrpcExporter.class, | ||
otlp -> assertThat(otlp).extracting("compressionEnabled").isEqualTo(false)); | ||
} finally { | ||
exporter.shutdown(); | ||
} | ||
} | ||
|
||
@Test | ||
void compressionGzip() { | ||
GrpcExporter<Marshaler> exporter = builder.setCompression("gzip").build(); | ||
try { | ||
assertThat(exporter) | ||
.isInstanceOfSatisfying( | ||
OkHttpGrpcExporter.class, | ||
otlp -> assertThat(otlp).extracting("compressionEnabled").isEqualTo(true)); | ||
} finally { | ||
exporter.shutdown(); | ||
} | ||
} | ||
|
||
@Test | ||
void compressionEnabledAndDisabled() { | ||
GrpcExporter<Marshaler> exporter = | ||
builder.setCompression("gzip").setCompression("none").build(); | ||
try { | ||
assertThat(exporter) | ||
.isInstanceOfSatisfying( | ||
OkHttpGrpcExporter.class, | ||
otlp -> assertThat(otlp).extracting("compressionEnabled").isEqualTo(false)); | ||
} finally { | ||
exporter.shutdown(); | ||
} | ||
} | ||
|
||
@Test | ||
void compressionDefaultWithChannel() { | ||
GrpcExporter<Marshaler> exporter = builder.setChannel(channel).build(); | ||
try { | ||
assertThat(exporter) | ||
.isInstanceOfSatisfying( | ||
UpstreamGrpcExporter.class, | ||
otlp -> | ||
assertThat(otlp) | ||
.extracting("stub") | ||
.extracting("callOptions.compressorName") | ||
.isEqualTo(Codec.Identity.NONE.getMessageEncoding())); | ||
} finally { | ||
exporter.shutdown(); | ||
} | ||
} | ||
|
||
@Test | ||
void compressionNoneWithChannel() { | ||
GrpcExporter<Marshaler> exporter = builder.setChannel(channel).setCompression("none").build(); | ||
try { | ||
assertThat(exporter) | ||
.isInstanceOfSatisfying( | ||
UpstreamGrpcExporter.class, | ||
otlp -> | ||
assertThat(otlp) | ||
.extracting("stub") | ||
.extracting("callOptions.compressorName") | ||
.isEqualTo(Codec.Identity.NONE.getMessageEncoding())); | ||
} finally { | ||
exporter.shutdown(); | ||
} | ||
} | ||
|
||
@Test | ||
void compressionGzipWithChannel() { | ||
GrpcExporter<Marshaler> exporter = builder.setChannel(channel).setCompression("gzip").build(); | ||
try { | ||
assertThat(exporter) | ||
.isInstanceOfSatisfying( | ||
UpstreamGrpcExporter.class, | ||
otlp -> | ||
assertThat(otlp) | ||
.extracting("stub") | ||
.extracting("callOptions.compressorName") | ||
.isEqualTo(new Codec.Gzip().getMessageEncoding())); | ||
} finally { | ||
exporter.shutdown(); | ||
} | ||
} | ||
|
||
@Test | ||
void compressionEnabledAndDisabledWithChannel() { | ||
GrpcExporter<Marshaler> exporter = | ||
builder.setChannel(channel).setCompression("gzip").setCompression("none").build(); | ||
try { | ||
assertThat(exporter) | ||
.isInstanceOfSatisfying( | ||
UpstreamGrpcExporter.class, | ||
otlp -> | ||
assertThat(otlp) | ||
.extracting("stub") | ||
.extracting("callOptions.compressorName") | ||
.isEqualTo(Codec.Identity.NONE.getMessageEncoding())); | ||
} finally { | ||
exporter.shutdown(); | ||
} | ||
} | ||
|
||
private final class TestMarshalerServiceStub | ||
extends MarshalerServiceStub<Marshaler, Void, TestMarshalerServiceStub> { | ||
|
||
private TestMarshalerServiceStub(Channel channel, CallOptions callOptions) { | ||
super(channel, callOptions); | ||
} | ||
|
||
@Override | ||
protected TestMarshalerServiceStub build(Channel channel, CallOptions callOptions) { | ||
return new TestMarshalerServiceStub(channel, callOptions); | ||
} | ||
|
||
@Override | ||
public ListenableFuture<Void> export(Marshaler request) { | ||
return Futures.immediateVoidFuture(); | ||
} | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
...on/src/test/java/io/opentelemetry/exporter/internal/okhttp/OkHttpExporterBuilderTest.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,70 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.exporter.internal.okhttp; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import io.opentelemetry.exporter.internal.marshal.Marshaler; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class OkHttpExporterBuilderTest { | ||
|
||
private final OkHttpExporterBuilder<Marshaler> builder = | ||
new OkHttpExporterBuilder<>("otlp", "span", "http://localhost:4318/v1/traces"); | ||
|
||
@Test | ||
void compressionDefault() { | ||
OkHttpExporter<Marshaler> exporter = builder.build(); | ||
try { | ||
assertThat(exporter) | ||
.isInstanceOfSatisfying( | ||
OkHttpExporter.class, | ||
otlp -> assertThat(otlp).extracting("compressionEnabled").isEqualTo(false)); | ||
} finally { | ||
exporter.shutdown(); | ||
} | ||
} | ||
|
||
@Test | ||
void compressionNone() { | ||
OkHttpExporter<Marshaler> exporter = builder.setCompression("none").build(); | ||
try { | ||
assertThat(exporter) | ||
.isInstanceOfSatisfying( | ||
OkHttpExporter.class, | ||
otlp -> assertThat(otlp).extracting("compressionEnabled").isEqualTo(false)); | ||
} finally { | ||
exporter.shutdown(); | ||
} | ||
} | ||
|
||
@Test | ||
void compressionGzip() { | ||
OkHttpExporter<Marshaler> exporter = builder.setCompression("gzip").build(); | ||
try { | ||
assertThat(exporter) | ||
.isInstanceOfSatisfying( | ||
OkHttpExporter.class, | ||
otlp -> assertThat(otlp).extracting("compressionEnabled").isEqualTo(true)); | ||
} finally { | ||
exporter.shutdown(); | ||
} | ||
} | ||
|
||
@Test | ||
void compressionEnabledAndDisabled() { | ||
OkHttpExporter<Marshaler> exporter = | ||
builder.setCompression("gzip").setCompression("none").build(); | ||
try { | ||
assertThat(exporter) | ||
.isInstanceOfSatisfying( | ||
OkHttpExporter.class, | ||
otlp -> assertThat(otlp).extracting("compressionEnabled").isEqualTo(false)); | ||
} finally { | ||
exporter.shutdown(); | ||
} | ||
} | ||
} |
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.