From d84a111273801a3b1be13dc7312379a2fc7266f6 Mon Sep 17 00:00:00 2001 From: jack-berg <34418638+jack-berg@users.noreply.github.com> Date: Tue, 19 Jul 2022 10:04:54 -0500 Subject: [PATCH] Cache HttpUrl for exporters that use OkHttp (#4616) --- .../exporter/internal/grpc/OkHttpGrpcExporter.java | 7 ++++--- .../exporter/internal/okhttp/OkHttpExporter.java | 7 ++++--- .../extension/trace/jaeger/sampler/OkHttpGrpcService.java | 7 ++++--- .../jaeger/sampler/JaegerRemoteSamplerProviderTest.java | 6 ++++-- 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/exporters/otlp/common/src/main/java/io/opentelemetry/exporter/internal/grpc/OkHttpGrpcExporter.java b/exporters/otlp/common/src/main/java/io/opentelemetry/exporter/internal/grpc/OkHttpGrpcExporter.java index 2041bbd9494..6a19265f053 100644 --- a/exporters/otlp/common/src/main/java/io/opentelemetry/exporter/internal/grpc/OkHttpGrpcExporter.java +++ b/exporters/otlp/common/src/main/java/io/opentelemetry/exporter/internal/grpc/OkHttpGrpcExporter.java @@ -39,6 +39,7 @@ import okhttp3.Call; import okhttp3.Callback; import okhttp3.Headers; +import okhttp3.HttpUrl; import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; @@ -65,7 +66,7 @@ public final class OkHttpGrpcExporter implements GrpcExport private final String type; private final ExporterMetrics exporterMetrics; private final OkHttpClient client; - private final String endpoint; + private final HttpUrl url; private final Headers headers; private final boolean compressionEnabled; @@ -81,7 +82,7 @@ public final class OkHttpGrpcExporter implements GrpcExport this.type = type; this.exporterMetrics = ExporterMetrics.createGrpcOkHttp(exporterName, type, meterProvider); this.client = client; - this.endpoint = endpoint; + this.url = HttpUrl.get(endpoint); this.headers = headers; this.compressionEnabled = compressionEnabled; } @@ -90,7 +91,7 @@ public final class OkHttpGrpcExporter implements GrpcExport public CompletableResultCode export(T exportRequest, int numItems) { exporterMetrics.addSeen(numItems); - Request.Builder requestBuilder = new Request.Builder().url(endpoint).headers(headers); + Request.Builder requestBuilder = new Request.Builder().url(url).headers(headers); RequestBody requestBody = new GrpcRequestBody(exportRequest, compressionEnabled); requestBuilder.post(requestBody); diff --git a/exporters/otlp/common/src/main/java/io/opentelemetry/exporter/internal/okhttp/OkHttpExporter.java b/exporters/otlp/common/src/main/java/io/opentelemetry/exporter/internal/okhttp/OkHttpExporter.java index b5dd386bc96..28daa712598 100644 --- a/exporters/otlp/common/src/main/java/io/opentelemetry/exporter/internal/okhttp/OkHttpExporter.java +++ b/exporters/otlp/common/src/main/java/io/opentelemetry/exporter/internal/okhttp/OkHttpExporter.java @@ -20,6 +20,7 @@ import okhttp3.Call; import okhttp3.Callback; import okhttp3.Headers; +import okhttp3.HttpUrl; import okhttp3.MediaType; import okhttp3.OkHttpClient; import okhttp3.Request; @@ -45,7 +46,7 @@ public final class OkHttpExporter { private final String type; private final OkHttpClient client; - private final String endpoint; + private final HttpUrl url; @Nullable private final Headers headers; private final boolean compressionEnabled; private final Function requestBodyCreator; @@ -63,7 +64,7 @@ public final class OkHttpExporter { boolean exportAsJson) { this.type = type; this.client = client; - this.endpoint = endpoint; + this.url = HttpUrl.get(endpoint); this.headers = headers; this.compressionEnabled = compressionEnabled; this.requestBodyCreator = exportAsJson ? JsonRequestBody::new : ProtoRequestBody::new; @@ -73,7 +74,7 @@ public final class OkHttpExporter { public CompletableResultCode export(T exportRequest, int numItems) { exporterMetrics.addSeen(numItems); - Request.Builder requestBuilder = new Request.Builder().url(endpoint); + Request.Builder requestBuilder = new Request.Builder().url(url); if (headers != null) { requestBuilder.headers(headers); } diff --git a/sdk-extensions/jaeger-remote-sampler/src/main/java/io/opentelemetry/sdk/extension/trace/jaeger/sampler/OkHttpGrpcService.java b/sdk-extensions/jaeger-remote-sampler/src/main/java/io/opentelemetry/sdk/extension/trace/jaeger/sampler/OkHttpGrpcService.java index beeb58bab17..8d91b48807f 100644 --- a/sdk-extensions/jaeger-remote-sampler/src/main/java/io/opentelemetry/sdk/extension/trace/jaeger/sampler/OkHttpGrpcService.java +++ b/sdk-extensions/jaeger-remote-sampler/src/main/java/io/opentelemetry/sdk/extension/trace/jaeger/sampler/OkHttpGrpcService.java @@ -19,6 +19,7 @@ import java.util.logging.Logger; import javax.annotation.Nullable; import okhttp3.Headers; +import okhttp3.HttpUrl; import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; @@ -37,7 +38,7 @@ final class OkHttpGrpcService