Remove Guava from SDK extensions, except zpages (#2149)
* Remove Guava from SDK extensions, except zpages * Fix
This commit is contained in:
parent
e0989d75e7
commit
ed57751d00
|
|
@ -5,7 +5,6 @@
|
||||||
|
|
||||||
package io.opentelemetry.sdk.extension.trace.export;
|
package io.opentelemetry.sdk.extension.trace.export;
|
||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
|
||||||
import com.lmax.disruptor.SleepingWaitStrategy;
|
import com.lmax.disruptor.SleepingWaitStrategy;
|
||||||
import com.lmax.disruptor.WaitStrategy;
|
import com.lmax.disruptor.WaitStrategy;
|
||||||
import io.opentelemetry.context.Context;
|
import io.opentelemetry.context.Context;
|
||||||
|
|
@ -149,7 +148,9 @@ public final class DisruptorAsyncSpanProcessor implements SpanProcessor {
|
||||||
* @return this.
|
* @return this.
|
||||||
*/
|
*/
|
||||||
public Builder setBufferSize(int bufferSize) {
|
public Builder setBufferSize(int bufferSize) {
|
||||||
Preconditions.checkArgument(bufferSize > 0, "bufferSize must be positive");
|
if (bufferSize <= 0) {
|
||||||
|
throw new IllegalArgumentException("bufferSize must be positive");
|
||||||
|
}
|
||||||
this.bufferSize = bufferSize;
|
this.bufferSize = bufferSize;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,16 +12,10 @@ dependencies {
|
||||||
api project(':opentelemetry-api'),
|
api project(':opentelemetry-api'),
|
||||||
project(':opentelemetry-sdk')
|
project(':opentelemetry-sdk')
|
||||||
|
|
||||||
implementation 'com.fasterxml.jackson.core:jackson-core',
|
implementation 'com.fasterxml.jackson.core:jackson-core'
|
||||||
libraries.guava,
|
implementation 'com.fasterxml.jackson.core:jackson-databind'
|
||||||
platform(boms.guava)
|
|
||||||
|
|
||||||
implementation 'com.fasterxml.jackson.core:jackson-databind',
|
|
||||||
libraries.guava,
|
|
||||||
platform(boms.guava)
|
|
||||||
|
|
||||||
testImplementation 'com.github.tomakehurst:wiremock-jre8:2.27.2',
|
testImplementation 'com.github.tomakehurst:wiremock-jre8:2.27.2',
|
||||||
|
libraries.guava,
|
||||||
libraries.junit
|
libraries.junit
|
||||||
|
|
||||||
signature libraries.android_signature
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,6 @@ package io.opentelemetry.sdk.extension.aws.resource;
|
||||||
import com.fasterxml.jackson.core.JsonFactory;
|
import com.fasterxml.jackson.core.JsonFactory;
|
||||||
import com.fasterxml.jackson.core.JsonParser;
|
import com.fasterxml.jackson.core.JsonParser;
|
||||||
import com.fasterxml.jackson.core.JsonToken;
|
import com.fasterxml.jackson.core.JsonToken;
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
|
||||||
import io.opentelemetry.api.common.Attributes;
|
import io.opentelemetry.api.common.Attributes;
|
||||||
import io.opentelemetry.api.common.AttributesBuilder;
|
import io.opentelemetry.api.common.AttributesBuilder;
|
||||||
import io.opentelemetry.sdk.resources.ResourceAttributes;
|
import io.opentelemetry.sdk.resources.ResourceAttributes;
|
||||||
|
|
@ -42,7 +41,7 @@ public class BeanstalkResource extends ResourceProvider {
|
||||||
this(BEANSTALK_CONF_PATH);
|
this(BEANSTALK_CONF_PATH);
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
// Visible for testing
|
||||||
BeanstalkResource(String configPath) {
|
BeanstalkResource(String configPath) {
|
||||||
this.configPath = configPath;
|
this.configPath = configPath;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@
|
||||||
|
|
||||||
package io.opentelemetry.sdk.extension.aws.resource;
|
package io.opentelemetry.sdk.extension.aws.resource;
|
||||||
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
|
|
@ -25,7 +24,7 @@ class DockerHelper {
|
||||||
this(DEFAULT_CGROUP_PATH);
|
this(DEFAULT_CGROUP_PATH);
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
// Visible for testing
|
||||||
DockerHelper(String cgroupPath) {
|
DockerHelper(String cgroupPath) {
|
||||||
this.cgroupPath = cgroupPath;
|
this.cgroupPath = cgroupPath;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,6 @@ package io.opentelemetry.sdk.extension.aws.resource;
|
||||||
import com.fasterxml.jackson.core.JsonFactory;
|
import com.fasterxml.jackson.core.JsonFactory;
|
||||||
import com.fasterxml.jackson.core.JsonParser;
|
import com.fasterxml.jackson.core.JsonParser;
|
||||||
import com.fasterxml.jackson.core.JsonToken;
|
import com.fasterxml.jackson.core.JsonToken;
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
|
||||||
import com.google.common.io.ByteStreams;
|
|
||||||
import io.opentelemetry.api.common.Attributes;
|
import io.opentelemetry.api.common.Attributes;
|
||||||
import io.opentelemetry.api.common.AttributesBuilder;
|
import io.opentelemetry.api.common.AttributesBuilder;
|
||||||
import io.opentelemetry.sdk.resources.ResourceAttributes;
|
import io.opentelemetry.sdk.resources.ResourceAttributes;
|
||||||
|
|
@ -25,6 +23,7 @@ import java.net.URL;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A {@link ResourceProvider} which provides information about the current EC2 instance if running
|
* A {@link ResourceProvider} which provides information about the current EC2 instance if running
|
||||||
|
|
@ -54,7 +53,7 @@ public class Ec2Resource extends ResourceProvider {
|
||||||
this(System.getProperty("otel.aws.imds.endpointOverride", DEFAULT_IMDS_ENDPOINT));
|
this(System.getProperty("otel.aws.imds.endpointOverride", DEFAULT_IMDS_ENDPOINT));
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
// Visible for testing
|
||||||
Ec2Resource(String endpoint) {
|
Ec2Resource(String endpoint) {
|
||||||
String urlBase = "http://" + endpoint;
|
String urlBase = "http://" + endpoint;
|
||||||
try {
|
try {
|
||||||
|
|
@ -68,6 +67,7 @@ public class Ec2Resource extends ResourceProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generic HTTP fetch function for IMDS.
|
// Generic HTTP fetch function for IMDS.
|
||||||
|
// TODO(anuraaga): Migrate to JdkHttpClient
|
||||||
private static String fetchString(String httpMethod, URL url, String token, boolean includeTtl) {
|
private static String fetchString(String httpMethod, URL url, String token, boolean includeTtl) {
|
||||||
final HttpURLConnection connection;
|
final HttpURLConnection connection;
|
||||||
try {
|
try {
|
||||||
|
|
@ -117,13 +117,13 @@ public class Ec2Resource extends ResourceProvider {
|
||||||
private static String readResponseString(HttpURLConnection connection) {
|
private static String readResponseString(HttpURLConnection connection) {
|
||||||
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||||
try (InputStream is = connection.getInputStream()) {
|
try (InputStream is = connection.getInputStream()) {
|
||||||
ByteStreams.copy(is, os);
|
readTo(is, os);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// Only best effort read if we can.
|
// Only best effort read if we can.
|
||||||
}
|
}
|
||||||
try (InputStream is = connection.getErrorStream()) {
|
try (InputStream is = connection.getErrorStream()) {
|
||||||
if (is != null) {
|
if (is != null) {
|
||||||
ByteStreams.copy(is, os);
|
readTo(is, os);
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// Only best effort read if we can.
|
// Only best effort read if we can.
|
||||||
|
|
@ -206,4 +206,16 @@ public class Ec2Resource extends ResourceProvider {
|
||||||
private String fetchHostname(String token) {
|
private String fetchHostname(String token) {
|
||||||
return fetchString("GET", hostnameUrl, token, /* includeTtl= */ false);
|
return fetchString("GET", hostnameUrl, token, /* includeTtl= */ false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void readTo(@Nullable InputStream is, ByteArrayOutputStream os)
|
||||||
|
throws IOException {
|
||||||
|
if (is == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
byte[] buf = new byte[8192];
|
||||||
|
int read;
|
||||||
|
while ((read = is.read(buf)) > 0) {
|
||||||
|
os.write(buf, 0, read);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,6 @@
|
||||||
|
|
||||||
package io.opentelemetry.sdk.extension.aws.resource;
|
package io.opentelemetry.sdk.extension.aws.resource;
|
||||||
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
|
||||||
import com.google.common.base.Strings;
|
|
||||||
import io.opentelemetry.api.common.Attributes;
|
import io.opentelemetry.api.common.Attributes;
|
||||||
import io.opentelemetry.api.common.AttributesBuilder;
|
import io.opentelemetry.api.common.AttributesBuilder;
|
||||||
import io.opentelemetry.sdk.resources.ResourceAttributes;
|
import io.opentelemetry.sdk.resources.ResourceAttributes;
|
||||||
|
|
@ -39,7 +37,7 @@ public class EcsResource extends ResourceProvider {
|
||||||
this(System.getenv(), new DockerHelper());
|
this(System.getenv(), new DockerHelper());
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
// Visible for testing
|
||||||
EcsResource(Map<String, String> sysEnv, DockerHelper dockerHelper) {
|
EcsResource(Map<String, String> sysEnv, DockerHelper dockerHelper) {
|
||||||
this.sysEnv = sysEnv;
|
this.sysEnv = sysEnv;
|
||||||
this.dockerHelper = dockerHelper;
|
this.dockerHelper = dockerHelper;
|
||||||
|
|
@ -61,7 +59,7 @@ public class EcsResource extends ResourceProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
String containerId = dockerHelper.getContainerId();
|
String containerId = dockerHelper.getContainerId();
|
||||||
if (!Strings.isNullOrEmpty(containerId)) {
|
if (containerId != null && !containerId.isEmpty()) {
|
||||||
attrBuilders.put(ResourceAttributes.CONTAINER_ID, containerId);
|
attrBuilders.put(ResourceAttributes.CONTAINER_ID, containerId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -69,7 +67,7 @@ public class EcsResource extends ResourceProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isOnEcs() {
|
private boolean isOnEcs() {
|
||||||
return (!Strings.isNullOrEmpty(sysEnv.get(ECS_METADATA_KEY_V3))
|
return !sysEnv.getOrDefault(ECS_METADATA_KEY_V3, "").isEmpty()
|
||||||
|| !Strings.isNullOrEmpty(sysEnv.get(ECS_METADATA_KEY_V4)));
|
|| !sysEnv.getOrDefault(ECS_METADATA_KEY_V4, "").isEmpty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,16 +7,15 @@ package io.opentelemetry.sdk.extension.aws.resource;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
|
||||||
import com.google.common.base.Charsets;
|
|
||||||
import com.google.common.base.Strings;
|
|
||||||
import com.google.common.io.Files;
|
|
||||||
import io.opentelemetry.api.common.Attributes;
|
import io.opentelemetry.api.common.Attributes;
|
||||||
import io.opentelemetry.api.common.AttributesBuilder;
|
import io.opentelemetry.api.common.AttributesBuilder;
|
||||||
import io.opentelemetry.sdk.resources.ResourceAttributes;
|
import io.opentelemetry.sdk.resources.ResourceAttributes;
|
||||||
import io.opentelemetry.sdk.resources.ResourceProvider;
|
import io.opentelemetry.sdk.resources.ResourceProvider;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Paths;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
@ -43,7 +42,7 @@ public class EksResource extends ResourceProvider {
|
||||||
this(new JdkHttpClient(), new DockerHelper(), K8S_TOKEN_PATH, K8S_CERT_PATH);
|
this(new JdkHttpClient(), new DockerHelper(), K8S_TOKEN_PATH, K8S_CERT_PATH);
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
// Visible for testing
|
||||||
EksResource(
|
EksResource(
|
||||||
JdkHttpClient jdkHttpClient,
|
JdkHttpClient jdkHttpClient,
|
||||||
DockerHelper dockerHelper,
|
DockerHelper dockerHelper,
|
||||||
|
|
@ -64,12 +63,12 @@ public class EksResource extends ResourceProvider {
|
||||||
AttributesBuilder attrBuilders = Attributes.builder();
|
AttributesBuilder attrBuilders = Attributes.builder();
|
||||||
|
|
||||||
String clusterName = getClusterName();
|
String clusterName = getClusterName();
|
||||||
if (!Strings.isNullOrEmpty(clusterName)) {
|
if (clusterName != null && !clusterName.isEmpty()) {
|
||||||
attrBuilders.put(ResourceAttributes.K8S_CLUSTER, clusterName);
|
attrBuilders.put(ResourceAttributes.K8S_CLUSTER, clusterName);
|
||||||
}
|
}
|
||||||
|
|
||||||
String containerId = dockerHelper.getContainerId();
|
String containerId = dockerHelper.getContainerId();
|
||||||
if (!Strings.isNullOrEmpty(containerId)) {
|
if (containerId != null && !containerId.isEmpty()) {
|
||||||
attrBuilders.put(ResourceAttributes.CONTAINER_ID, containerId);
|
attrBuilders.put(ResourceAttributes.CONTAINER_ID, containerId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -88,7 +87,7 @@ public class EksResource extends ResourceProvider {
|
||||||
jdkHttpClient.fetchString(
|
jdkHttpClient.fetchString(
|
||||||
"GET", K8S_SVC_URL + AUTH_CONFIGMAP_PATH, requestProperties, K8S_CERT_PATH);
|
"GET", K8S_SVC_URL + AUTH_CONFIGMAP_PATH, requestProperties, K8S_CERT_PATH);
|
||||||
|
|
||||||
return !Strings.isNullOrEmpty(awsAuth);
|
return awsAuth != null && !awsAuth.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isK8s() {
|
private boolean isK8s() {
|
||||||
|
|
@ -115,8 +114,8 @@ public class EksResource extends ResourceProvider {
|
||||||
|
|
||||||
private static String getK8sCredHeader() {
|
private static String getK8sCredHeader() {
|
||||||
try {
|
try {
|
||||||
File file = new File(K8S_TOKEN_PATH);
|
String content =
|
||||||
String content = Files.asCharSource(file, Charsets.UTF_8).read();
|
new String(Files.readAllBytes(Paths.get(K8S_TOKEN_PATH)), StandardCharsets.UTF_8);
|
||||||
return "Bearer " + content;
|
return "Bearer " + content;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logger.log(Level.WARNING, "Unable to load K8s client token.", e);
|
logger.log(Level.WARNING, "Unable to load K8s client token.", e);
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@
|
||||||
|
|
||||||
package io.opentelemetry.sdk.extension.aws.resource;
|
package io.opentelemetry.sdk.extension.aws.resource;
|
||||||
|
|
||||||
import com.google.common.io.ByteStreams;
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
@ -21,6 +20,7 @@ import java.util.Collection;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import javax.net.ssl.HttpsURLConnection;
|
import javax.net.ssl.HttpsURLConnection;
|
||||||
import javax.net.ssl.SSLContext;
|
import javax.net.ssl.SSLContext;
|
||||||
import javax.net.ssl.SSLSocketFactory;
|
import javax.net.ssl.SSLSocketFactory;
|
||||||
|
|
@ -80,13 +80,13 @@ class JdkHttpClient {
|
||||||
private static String readResponseString(HttpURLConnection connection) {
|
private static String readResponseString(HttpURLConnection connection) {
|
||||||
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||||
try (InputStream is = connection.getInputStream()) {
|
try (InputStream is = connection.getInputStream()) {
|
||||||
ByteStreams.copy(is, os);
|
readTo(is, os);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// Only best effort read if we can.
|
// Only best effort read if we can.
|
||||||
}
|
}
|
||||||
try (InputStream is = connection.getErrorStream()) {
|
try (InputStream is = connection.getErrorStream()) {
|
||||||
if (is != null) {
|
if (is != null) {
|
||||||
ByteStreams.copy(is, os);
|
readTo(is, os);
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// Only best effort read if we can.
|
// Only best effort read if we can.
|
||||||
|
|
@ -134,4 +134,16 @@ class JdkHttpClient {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void readTo(@Nullable InputStream is, ByteArrayOutputStream os)
|
||||||
|
throws IOException {
|
||||||
|
if (is == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
byte[] buf = new byte[8192];
|
||||||
|
int read;
|
||||||
|
while ((read = is.read(buf)) > 0) {
|
||||||
|
os.write(buf, 0, read);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@
|
||||||
|
|
||||||
package io.opentelemetry.sdk.extension.trace.jaeger.sampler;
|
package io.opentelemetry.sdk.extension.trace.jaeger.sampler;
|
||||||
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
|
||||||
import io.grpc.ManagedChannel;
|
import io.grpc.ManagedChannel;
|
||||||
import io.opentelemetry.api.common.ReadableAttributes;
|
import io.opentelemetry.api.common.ReadableAttributes;
|
||||||
import io.opentelemetry.api.trace.Span.Kind;
|
import io.opentelemetry.api.trace.Span.Kind;
|
||||||
|
|
@ -111,7 +110,7 @@ public class JaegerRemoteSampler implements Sampler {
|
||||||
return getDescription();
|
return getDescription();
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
// Visible for testing
|
||||||
Sampler getSampler() {
|
Sampler getSampler() {
|
||||||
return this.sampler;
|
return this.sampler;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,6 @@ package io.opentelemetry.sdk.extension.trace.jaeger.sampler;
|
||||||
import static io.opentelemetry.api.common.AttributeKey.doubleKey;
|
import static io.opentelemetry.api.common.AttributeKey.doubleKey;
|
||||||
import static io.opentelemetry.api.common.AttributeKey.stringKey;
|
import static io.opentelemetry.api.common.AttributeKey.stringKey;
|
||||||
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
|
||||||
import io.opentelemetry.api.common.AttributeKey;
|
import io.opentelemetry.api.common.AttributeKey;
|
||||||
import io.opentelemetry.api.common.Attributes;
|
import io.opentelemetry.api.common.Attributes;
|
||||||
import io.opentelemetry.api.common.ReadableAttributes;
|
import io.opentelemetry.api.common.ReadableAttributes;
|
||||||
|
|
@ -84,7 +83,7 @@ class RateLimitingSampler implements Sampler {
|
||||||
return getDescription();
|
return getDescription();
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
// Visible for testing
|
||||||
double getMaxTracesPerSecond() {
|
double getMaxTracesPerSecond() {
|
||||||
return maxTracesPerSecond;
|
return maxTracesPerSecond;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue