Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…y-java into propagate-io-exception
  • Loading branch information
jack-berg committed Jan 3, 2024
2 parents bc7a8a9 + 517ef88 commit 9a70faf
Show file tree
Hide file tree
Showing 58 changed files with 2,364 additions and 2,510 deletions.
5 changes: 5 additions & 0 deletions all/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ tasks {
}
}

// Skip OWASP dependencyCheck task on test module
dependencyCheck {
skip = true
}

val testTasks = mutableListOf<Task>()

dependencies {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"resources": {
"includes": [
{
"pattern":"\\Qio/opentelemetry/api/version.properties\\E"
}
]
},
"bundles": []
}
4 changes: 2 additions & 2 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ dependencies {
// When updating, update above in plugins too
implementation("com.diffplug.spotless:spotless-plugin-gradle:6.23.3")
// Needed for japicmp but not automatically brought in for some reason.
implementation("com.google.guava:guava:32.1.3-jre")
implementation("com.google.guava:guava:33.0.0-jre")
implementation("com.squareup:javapoet:1.13.0")
implementation("com.squareup.wire:wire-compiler")
implementation("com.squareup.wire:wire-gradle-plugin")
Expand All @@ -57,7 +57,7 @@ dependencies {
implementation("me.champeau.jmh:jmh-gradle-plugin:0.7.2")
implementation("net.ltgt.gradle:gradle-errorprone-plugin:3.1.0")
implementation("net.ltgt.gradle:gradle-nullaway-plugin:1.6.0")
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.21")
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.22")
implementation("org.owasp:dependency-check-gradle:9.0.7")
implementation("ru.vyarus:gradle-animalsniffer-plugin:1.7.1")
}
Expand Down
11 changes: 8 additions & 3 deletions buildSrc/src/main/kotlin/otel.java-conventions.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,25 @@ java {

checkstyle {
configDirectory.set(file("$rootDir/buildscripts/"))
toolVersion = "10.12.6"
toolVersion = "10.12.7"
isIgnoreFailures = false
configProperties["rootDir"] = rootDir
}

dependencyCheck {
skipConfigurations = listOf(
skipConfigurations = mutableListOf(
"errorprone",
"checkstyle",
"annotationProcessor",
"java9AnnotationProcessor",
"moduleAnnotationProcessor",
"testAnnotationProcessor",
"testJpmsAnnotationProcessor",
"animalsniffer",
"spotless865457264", // spotless865457264 is a weird configuration that's only added in jaeger-proto, jaeger-remote-sampler
"spotless996155815", // spotless996155815 is a weird configuration that's only added in jaeger-proto, jaeger-remote-sampler
"js2p",
"jmhAnnotationProcessor",
"jmhBasedTestAnnotationProcessor",
"jmhCompileClasspath",
"jmhRuntimeClasspath",
"jmhRuntimeOnly")
Expand Down
10 changes: 10 additions & 0 deletions context/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ dependencies {
testImplementation("com.google.guava:guava")
}

dependencyCheck {
skipConfigurations.add("braveInOtelTestAnnotationProcessor")
skipConfigurations.add("grpcInOtelTestAnnotationProcessor")
skipConfigurations.add("otelAsBraveTestAnnotationProcessor")
skipConfigurations.add("otelInBraveTestAnnotationProcessor")
skipConfigurations.add("otelInGrpcTestAnnotationProcessor")
skipConfigurations.add("storageWrappersTestAnnotationProcessor")
skipConfigurations.add("strictContextEnabledTestAnnotationProcessor")
}

testing {
suites {
register<JvmTestSuite>("grpcInOtelTest") {
Expand Down
17 changes: 9 additions & 8 deletions dependencyManagement/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,28 @@ val dependencyVersions = hashMapOf<String, String>()
rootProject.extra["versions"] = dependencyVersions

val DEPENDENCY_BOMS = listOf(
"com.fasterxml.jackson:jackson-bom:2.16.0",
"com.google.guava:guava-bom:32.1.3-jre",
"com.fasterxml.jackson:jackson-bom:2.16.1",
"com.google.guava:guava-bom:33.0.0-jre",
"com.google.protobuf:protobuf-bom:3.25.1",
"com.linecorp.armeria:armeria-bom:1.26.4",
"com.squareup.okhttp3:okhttp-bom:4.12.0",
"com.squareup.okio:okio-bom:3.7.0", // applies to transitive dependencies of okhttp
"io.grpc:grpc-bom:1.60.0",
"io.grpc:grpc-bom:1.60.1",
"io.netty:netty-bom:4.1.104.Final",
"io.zipkin.brave:brave-bom:5.17.0",
"io.zipkin.reporter2:zipkin-reporter-bom:2.17.1",
"org.assertj:assertj-bom:3.24.2",
"org.assertj:assertj-bom:3.25.0",
"org.junit:junit-bom:5.10.1",
"org.testcontainers:testcontainers-bom:1.19.3",
"org.snakeyaml:snakeyaml-engine:2.7"
)

val autoValueVersion = "1.10.4"
val errorProneVersion = "2.23.0"
val errorProneVersion = "2.24.1"
val jmhVersion = "1.37"
// Mockito 5.x.x requires Java 11 https://github.com/mockito/mockito/releases/tag/v5.0.0
val mockitoVersion = "4.11.0"
val slf4jVersion = "2.0.9"
val slf4jVersion = "2.0.10"
val opencensusVersion = "0.31.1"
val prometheusClientVersion = "0.16.0"

Expand Down Expand Up @@ -60,7 +60,7 @@ val DEPENDENCIES = listOf(
"com.google.guava:guava-beta-checker:1.0",
"com.sun.net.httpserver:http:20070405",
"com.tngtech.archunit:archunit-junit5:1.2.1",
"com.uber.nullaway:nullaway:0.10.18",
"com.uber.nullaway:nullaway:0.10.19",
"edu.berkeley.cs.jqf:jqf-fuzz:1.7", // jqf-fuzz version 1.8+ requires Java 11+
"eu.rekawek.toxiproxy:toxiproxy-java:2.1.7",
"io.github.netmikey.logunit:logunit-jul:2.0.0",
Expand All @@ -69,8 +69,9 @@ val DEPENDENCIES = listOf(
"io.opentelemetry.contrib:opentelemetry-aws-xray-propagator:1.29.0-alpha",
"io.opentracing:opentracing-api:0.33.0",
"io.opentracing:opentracing-noop:0.33.0",
"io.prometheus:prometheus-metrics-exporter-httpserver:1.1.0",
"junit:junit:4.13.2",
"nl.jqno.equalsverifier:equalsverifier:3.15.4",
"nl.jqno.equalsverifier:equalsverifier:3.15.5",
"org.awaitility:awaitility:4.2.0",
"org.bouncycastle:bcpkix-jdk15on:1.70",
"org.codehaus.mojo:animal-sniffer-annotations:1.23",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.exporter.internal.compression;

import java.io.IOException;
import java.io.OutputStream;
import javax.annotation.concurrent.ThreadSafe;

/**
* An abstraction for compressing messages. Implementation MUST be thread safe as the same instance
* is expected to be used many times and concurrently. Instances are usually singletons.
*
* <p>This class is internal and is hence not for public use. Its APIs are unstable and can change
* at any time.
*/
@ThreadSafe
public interface Compressor {

/**
* The name of the compressor encoding.
*
* <p>Used to identify the compressor during configuration and to populate the {@code
* Content-Encoding} header.
*/
String getEncoding();

/** Wrap the {@code outputStream} with a compressing output stream. */
OutputStream compress(OutputStream outputStream) throws IOException;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.exporter.internal.compression;

/**
* A service provider interface (SPI) for providing {@link Compressor}s.
*
* <p>This class is internal and is hence not for public use. Its APIs are unstable and can change
* at any time.
*/
public interface CompressorProvider {

/** Return the {@link Compressor}. */
Compressor getInstance();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.exporter.internal.compression;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.ServiceLoader;
import java.util.Set;

/**
* Utilities for resolving SPI {@link Compressor}s.
*
* <p>This class is internal and is hence not for public use. Its APIs are unstable and can change
* at any time.
*
* @see CompressorProvider
*/
public final class CompressorUtil {

private static final Map<String, Compressor> compressorRegistry = buildCompressorRegistry();

private CompressorUtil() {}

/** Get list of loaded compressors, named according to {@link Compressor#getEncoding()}. */
public static Set<String> supportedCompressors() {
return Collections.unmodifiableSet(compressorRegistry.keySet());
}

/**
* Resolve the {@link Compressor} with the {@link Compressor#getEncoding()} equal to the {@code
* encoding}.
*
* @throws IllegalArgumentException if no match is found
*/
public static Compressor resolveCompressor(String encoding) {
Compressor compressor = compressorRegistry.get(encoding);
if (compressor == null) {
throw new IllegalArgumentException(
"Could not resolve compressor for encoding \"" + encoding + "\".");
}
return compressor;
}

private static Map<String, Compressor> buildCompressorRegistry() {
Map<String, Compressor> compressors = new HashMap<>();
for (CompressorProvider spi :
ServiceLoader.load(CompressorProvider.class, CompressorUtil.class.getClassLoader())) {
Compressor compressor = spi.getInstance();
compressors.put(compressor.getEncoding(), compressor);
}
// Hardcode gzip compressor
compressors.put(GzipCompressor.getInstance().getEncoding(), GzipCompressor.getInstance());
return compressors;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.exporter.internal.compression;

import java.io.IOException;
import java.io.OutputStream;
import java.util.zip.GZIPOutputStream;

/**
* Gzip {@link Compressor}.
*
* <p>This class is internal and is hence not for public use. Its APIs are unstable and can change
* at any time.
*/
public final class GzipCompressor implements Compressor {

private static final GzipCompressor INSTANCE = new GzipCompressor();

private GzipCompressor() {}

public static GzipCompressor getInstance() {
return INSTANCE;
}

@Override
public String getEncoding() {
return "gzip";
}

@Override
public OutputStream compress(OutputStream outputStream) throws IOException {
return new GZIPOutputStream(outputStream);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import io.opentelemetry.exporter.internal.ExporterBuilderUtil;
import io.opentelemetry.exporter.internal.TlsConfigHelper;
import io.opentelemetry.exporter.internal.auth.Authenticator;
import io.opentelemetry.exporter.internal.compression.Compressor;
import io.opentelemetry.exporter.internal.marshal.Marshaler;
import io.opentelemetry.sdk.common.export.RetryPolicy;
import java.net.URI;
Expand All @@ -19,6 +20,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.ServiceLoader;
import java.util.StringJoiner;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -48,8 +50,8 @@ public final class HttpExporterBuilder<T extends Marshaler> {
private String endpoint;

private long timeoutNanos = TimeUnit.SECONDS.toNanos(DEFAULT_TIMEOUT_SECS);
@Nullable private Compressor compressor;
private long connectTimeoutNanos = TimeUnit.SECONDS.toNanos(DEFAULT_CONNECT_TIMEOUT_SECS);
private boolean compressionEnabled = false;
private boolean exportAsJson = false;
private final Map<String, String> constantHeaders = new HashMap<>();
private Supplier<Map<String, String>> headerSupplier = Collections::emptyMap;
Expand Down Expand Up @@ -82,8 +84,8 @@ public HttpExporterBuilder<T> setEndpoint(String endpoint) {
return this;
}

public HttpExporterBuilder<T> setCompression(String compressionMethod) {
this.compressionEnabled = compressionMethod.equals("gzip");
public HttpExporterBuilder<T> setCompression(@Nullable Compressor compressor) {
this.compressor = compressor;
return this;
}

Expand Down Expand Up @@ -141,7 +143,7 @@ public HttpExporterBuilder<T> copy() {
copy.timeoutNanos = timeoutNanos;
copy.connectTimeoutNanos = connectTimeoutNanos;
copy.exportAsJson = exportAsJson;
copy.compressionEnabled = compressionEnabled;
copy.compressor = compressor;
copy.constantHeaders.putAll(constantHeaders);
copy.headerSupplier = headerSupplier;
copy.tlsConfigHelper = tlsConfigHelper.copy();
Expand Down Expand Up @@ -179,7 +181,7 @@ public HttpExporter<T> build() {
HttpSender httpSender =
httpSenderProvider.createSender(
endpoint,
compressionEnabled,
compressor,
exportAsJson,
exportAsJson ? "application/json" : "application/x-protobuf",
timeoutNanos,
Expand All @@ -203,8 +205,10 @@ public String toString(boolean includePrefixAndSuffix) {
joiner.add("type=" + type);
joiner.add("endpoint=" + endpoint);
joiner.add("timeoutNanos=" + timeoutNanos);
joiner.add(
"compressorEncoding="
+ Optional.ofNullable(compressor).map(Compressor::getEncoding).orElse(null));
joiner.add("connectTimeoutNanos=" + connectTimeoutNanos);
joiner.add("compressionEnabled=" + compressionEnabled);
joiner.add("exportAsJson=" + exportAsJson);
StringJoiner headersJoiner = new StringJoiner(", ", "Headers{", "}");
constantHeaders.forEach((key, value) -> headersJoiner.add(key + "=OBFUSCATED"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package io.opentelemetry.exporter.internal.http;

import io.opentelemetry.exporter.internal.auth.Authenticator;
import io.opentelemetry.exporter.internal.compression.Compressor;
import io.opentelemetry.sdk.common.export.RetryPolicy;
import java.util.List;
import java.util.Map;
Expand All @@ -27,7 +28,7 @@ public interface HttpSenderProvider {
@SuppressWarnings("TooManyParameters")
HttpSender createSender(
String endpoint,
boolean compressionEnabled,
@Nullable Compressor compressor,
boolean exportAsJson,
String contentType,
long timeoutNanos,
Expand Down
Loading

0 comments on commit 9a70faf

Please sign in to comment.