Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,15 @@ class OtlpHttpLogExporterTest {
private static final MediaType APPLICATION_PROTOBUF =
MediaType.create("application", "x-protobuf");
private static final HeldCertificate HELD_CERTIFICATE;
private static final String canonicalHostName;

static {
try {
canonicalHostName = InetAddress.getByName("localhost").getCanonicalHostName();
HELD_CERTIFICATE =
new HeldCertificate.Builder()
.commonName("localhost")
.addSubjectAlternativeName(InetAddress.getByName("localhost").getCanonicalHostName())
.addSubjectAlternativeName(canonicalHostName)
.build();
} catch (UnknownHostException e) {
throw new IllegalStateException("Error building certificate.", e);
Expand All @@ -94,7 +96,7 @@ protected void configureServer(ServerBuilder sb) {
void setup() {
builder =
OtlpHttpLogExporter.builder()
.setEndpoint("http://localhost:" + server.httpPort() + "/v1/logs")
.setEndpoint("http://" + canonicalHostName + ":" + server.httpPort() + "/v1/logs")
.addHeader("foo", "bar");
}

Expand All @@ -110,13 +112,20 @@ void validConfig() {
assertThatCode(() -> OtlpHttpLogExporter.builder().setTimeout(Duration.ofMillis(10)))
.doesNotThrowAnyException();

assertThatCode(() -> OtlpHttpLogExporter.builder().setEndpoint("http://localhost:4317"))
assertThatCode(
() ->
OtlpHttpLogExporter.builder().setEndpoint("http://" + canonicalHostName + ":4317"))
.doesNotThrowAnyException();
assertThatCode(() -> OtlpHttpLogExporter.builder().setEndpoint("http://localhost"))
assertThatCode(
() -> OtlpHttpLogExporter.builder().setEndpoint("http://" + canonicalHostName + ""))
.doesNotThrowAnyException();
assertThatCode(() -> OtlpHttpLogExporter.builder().setEndpoint("https://localhost"))
assertThatCode(
() -> OtlpHttpLogExporter.builder().setEndpoint("https://" + canonicalHostName + ""))
.doesNotThrowAnyException();
assertThatCode(() -> OtlpHttpLogExporter.builder().setEndpoint("http://foo:bar@localhost"))
assertThatCode(
() ->
OtlpHttpLogExporter.builder()
.setEndpoint("http://foo:bar@" + canonicalHostName + ""))
.doesNotThrowAnyException();

assertThatCode(() -> OtlpHttpLogExporter.builder().setCompression("gzip"))
Expand Down Expand Up @@ -151,15 +160,21 @@ void invalidConfig() {
assertThatThrownBy(() -> OtlpHttpLogExporter.builder().setEndpoint(null))
.isInstanceOf(NullPointerException.class)
.hasMessage("endpoint");
assertThatThrownBy(() -> OtlpHttpLogExporter.builder().setEndpoint("😺://localhost"))
assertThatThrownBy(
() -> OtlpHttpLogExporter.builder().setEndpoint("😺://" + canonicalHostName + ""))
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("Invalid endpoint, must be a URL: 😺://localhost");
assertThatThrownBy(() -> OtlpHttpLogExporter.builder().setEndpoint("localhost"))
.hasMessage("Invalid endpoint, must be a URL: 😺://" + canonicalHostName + "");
assertThatThrownBy(() -> OtlpHttpLogExporter.builder().setEndpoint("" + canonicalHostName + ""))
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("Invalid endpoint, must start with http:// or https://: localhost");
assertThatThrownBy(() -> OtlpHttpLogExporter.builder().setEndpoint("gopher://localhost"))
.hasMessage(
"Invalid endpoint, must start with http:// or https://: " + canonicalHostName + "");
assertThatThrownBy(
() -> OtlpHttpLogExporter.builder().setEndpoint("gopher://" + canonicalHostName + ""))
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("Invalid endpoint, must start with http:// or https://: gopher://localhost");
.hasMessage(
"Invalid endpoint, must start with http:// or https://: gopher://"
+ canonicalHostName
+ "");

assertThatThrownBy(() -> OtlpHttpLogExporter.builder().setCompression(null))
.isInstanceOf(NullPointerException.class)
Expand Down Expand Up @@ -190,7 +205,7 @@ void testExportTls() {
server.enqueue(successResponse());
OtlpHttpLogExporter exporter =
builder
.setEndpoint("https://localhost:" + server.httpsPort() + "/v1/logs")
.setEndpoint("https://" + canonicalHostName + ":" + server.httpsPort() + "/v1/logs")
.setTrustedCertificates(
HELD_CERTIFICATE.certificatePem().getBytes(StandardCharsets.UTF_8))
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,15 @@ class OtlpHttpMetricExporterTest {
private static final MediaType APPLICATION_PROTOBUF =
MediaType.create("application", "x-protobuf");
private static final HeldCertificate HELD_CERTIFICATE;
private static final String canonicalHostName;

static {
try {
canonicalHostName = InetAddress.getByName("localhost").getCanonicalHostName();
HELD_CERTIFICATE =
new HeldCertificate.Builder()
.commonName("localhost")
.addSubjectAlternativeName(InetAddress.getByName("localhost").getCanonicalHostName())
.addSubjectAlternativeName(canonicalHostName)
.build();
} catch (UnknownHostException e) {
throw new IllegalStateException("Error building certificate.", e);
Expand All @@ -90,7 +92,7 @@ protected void configureServer(ServerBuilder sb) {
void setup() {
builder =
OtlpHttpMetricExporter.builder()
.setEndpoint("https://localhost:" + server.httpsPort() + "/v1/metrics")
.setEndpoint("https://" + canonicalHostName + ":" + server.httpsPort() + "/v1/metrics")
.addHeader("foo", "bar")
.setTrustedCertificates(
HELD_CERTIFICATE.certificatePem().getBytes(StandardCharsets.UTF_8));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,15 @@ class OtlpHttpSpanExporterTest {
private static final MediaType APPLICATION_PROTOBUF =
MediaType.create("application", "x-protobuf");
private static final HeldCertificate HELD_CERTIFICATE;
private static final String canonicalHostName;

static {
try {
canonicalHostName = InetAddress.getByName("localhost").getCanonicalHostName();
HELD_CERTIFICATE =
new HeldCertificate.Builder()
.commonName("localhost")
.addSubjectAlternativeName(InetAddress.getByName("localhost").getCanonicalHostName())
.addSubjectAlternativeName(canonicalHostName)
.build();
} catch (UnknownHostException e) {
throw new IllegalStateException("Error building certificate.", e);
Expand All @@ -93,7 +95,7 @@ protected void configureServer(ServerBuilder sb) {
void setup() {
builder =
OtlpHttpSpanExporter.builder()
.setEndpoint("http://localhost:" + server.httpPort() + "/v1/traces")
.setEndpoint("http://" + canonicalHostName + ":" + server.httpPort() + "/v1/traces")
.addHeader("foo", "bar");
}

Expand Down Expand Up @@ -189,7 +191,7 @@ void testExportTls() {
server.enqueue(successResponse());
OtlpHttpSpanExporter exporter =
builder
.setEndpoint("https://localhost:" + server.httpsPort() + "/v1/traces")
.setEndpoint("https://" + canonicalHostName + ":" + server.httpsPort() + "/v1/traces")
.setTrustedCertificates(
HELD_CERTIFICATE.certificatePem().getBytes(StandardCharsets.UTF_8))
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,15 @@ class OkHttpOnlyExportTest {
.build());

private static final HeldCertificate HELD_CERTIFICATE;
private static final String canonicalHostName;

static {
try {
canonicalHostName = InetAddress.getByName("localhost").getCanonicalHostName();
HELD_CERTIFICATE =
new HeldCertificate.Builder()
.commonName("localhost")
.addSubjectAlternativeName(InetAddress.getByName("localhost").getCanonicalHostName())
.addSubjectAlternativeName(canonicalHostName)
.build();
} catch (UnknownHostException e) {
throw new IllegalStateException("Error building certificate.", e);
Expand Down Expand Up @@ -98,7 +100,7 @@ protected CompletionStage<byte[]> handleMessage(
void gzipCompressionExport() {
OtlpGrpcLogExporter exporter =
OtlpGrpcLogExporter.builder()
.setEndpoint("http://localhost:" + server.httpPort())
.setEndpoint("http://" + canonicalHostName + ":" + server.httpPort())
.setCompression("gzip")
.build();
// See note on test method on why this checks isFalse.
Expand All @@ -108,15 +110,17 @@ void gzipCompressionExport() {
@Test
void plainTextExport() {
OtlpGrpcLogExporter exporter =
OtlpGrpcLogExporter.builder().setEndpoint("http://localhost:" + server.httpPort()).build();
OtlpGrpcLogExporter.builder()
.setEndpoint("http://" + canonicalHostName + ":" + server.httpPort())
.build();
assertThat(exporter.export(LOGS).join(10, TimeUnit.SECONDS).isSuccess()).isTrue();
}

@Test
void authorityWithAuth() {
OtlpGrpcLogExporter exporter =
OtlpGrpcLogExporter.builder()
.setEndpoint("http://foo:bar@localhost:" + server.httpPort())
.setEndpoint("http://foo:bar@" + canonicalHostName + ":" + server.httpPort())
.build();
assertThat(exporter.export(LOGS).join(10, TimeUnit.SECONDS).isSuccess()).isTrue();
}
Expand All @@ -125,7 +129,7 @@ void authorityWithAuth() {
void testTlsExport() {
OtlpGrpcLogExporter exporter =
OtlpGrpcLogExporter.builder()
.setEndpoint("https://localhost:" + server.httpsPort())
.setEndpoint("https://" + canonicalHostName + ":" + server.httpsPort())
.setTrustedCertificates(
HELD_CERTIFICATE.certificatePem().getBytes(StandardCharsets.UTF_8))
.build();
Expand All @@ -136,7 +140,7 @@ void testTlsExport() {
void testTlsExport_untrusted() {
OtlpGrpcLogExporter exporter =
OtlpGrpcLogExporter.builder()
.setEndpoint("https://localhost:" + server.httpsPort())
.setEndpoint("https://" + canonicalHostName + ":" + server.httpsPort())
.build();
assertThat(exporter.export(LOGS).join(10, TimeUnit.SECONDS).isSuccess()).isFalse();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,15 @@ class OkHttpOnlyExportTest {
5)))));

private static final HeldCertificate HELD_CERTIFICATE;
private static final String canonicalHostName;

static {
try {
canonicalHostName = InetAddress.getByName("localhost").getCanonicalHostName();
HELD_CERTIFICATE =
new HeldCertificate.Builder()
.commonName("localhost")
.addSubjectAlternativeName(InetAddress.getByName("localhost").getCanonicalHostName())
.addSubjectAlternativeName(canonicalHostName)
.build();
} catch (UnknownHostException e) {
throw new IllegalStateException("Error building certificate.", e);
Expand Down Expand Up @@ -100,7 +102,7 @@ protected CompletionStage<byte[]> handleMessage(
void gzipCompressionExportButFails() {
OtlpGrpcMetricExporter exporter =
OtlpGrpcMetricExporter.builder()
.setEndpoint("http://localhost:" + server.httpPort())
.setEndpoint("http://" + canonicalHostName + ":" + server.httpPort())
.setCompression("gzip")
.build();
// See note on test method on why this checks isFalse.
Expand All @@ -111,7 +113,7 @@ void gzipCompressionExportButFails() {
void plainTextExport() {
OtlpGrpcMetricExporter exporter =
OtlpGrpcMetricExporter.builder()
.setEndpoint("http://localhost:" + server.httpPort())
.setEndpoint("http://" + canonicalHostName + ":" + server.httpPort())
.build();
assertThat(exporter.export(METRICS).join(10, TimeUnit.SECONDS).isSuccess()).isTrue();
}
Expand All @@ -120,7 +122,7 @@ void plainTextExport() {
void authorityWithAuth() {
OtlpGrpcMetricExporter exporter =
OtlpGrpcMetricExporter.builder()
.setEndpoint("http://foo:bar@localhost:" + server.httpPort())
.setEndpoint("http://foo:bar@" + canonicalHostName + ":" + server.httpPort())
.build();
assertThat(exporter.export(METRICS).join(10, TimeUnit.SECONDS).isSuccess()).isTrue();
}
Expand All @@ -129,7 +131,7 @@ void authorityWithAuth() {
void testTlsExport() {
OtlpGrpcMetricExporter exporter =
OtlpGrpcMetricExporter.builder()
.setEndpoint("https://localhost:" + server.httpsPort())
.setEndpoint("https://" + canonicalHostName + ":" + server.httpsPort())
.setTrustedCertificates(
HELD_CERTIFICATE.certificatePem().getBytes(StandardCharsets.UTF_8))
.build();
Expand All @@ -140,7 +142,7 @@ void testTlsExport() {
void testTlsExport_untrusted() {
OtlpGrpcMetricExporter exporter =
OtlpGrpcMetricExporter.builder()
.setEndpoint("https://localhost:" + server.httpsPort())
.setEndpoint("https://" + canonicalHostName + ":" + server.httpsPort())
.build();
assertThat(exporter.export(METRICS).join(10, TimeUnit.SECONDS).isSuccess()).isFalse();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,15 @@ class OkHttpOnlyExportTest {
.build());

private static final HeldCertificate HELD_CERTIFICATE;
private static final String canonicalHostName;

static {
try {
canonicalHostName = InetAddress.getByName("localhost").getCanonicalHostName();
HELD_CERTIFICATE =
new HeldCertificate.Builder()
.commonName("localhost")
.addSubjectAlternativeName(InetAddress.getByName("localhost").getCanonicalHostName())
.addSubjectAlternativeName(canonicalHostName)
.build();
} catch (UnknownHostException e) {
throw new IllegalStateException("Error building certificate.", e);
Expand Down Expand Up @@ -88,7 +90,7 @@ protected CompletionStage<byte[]> handleMessage(
void gzipCompressionExportAttemptedButFails() {
OtlpGrpcSpanExporter exporter =
OtlpGrpcSpanExporter.builder()
.setEndpoint("http://localhost:" + server.httpPort())
.setEndpoint("http://" + canonicalHostName + ":" + server.httpPort())
.setCompression("gzip")
.build();

Expand All @@ -99,15 +101,17 @@ void gzipCompressionExportAttemptedButFails() {
@Test
void plainTextExport() {
OtlpGrpcSpanExporter exporter =
OtlpGrpcSpanExporter.builder().setEndpoint("http://localhost:" + server.httpPort()).build();
OtlpGrpcSpanExporter.builder()
.setEndpoint("http://" + canonicalHostName + ":" + server.httpPort())
.build();
assertThat(exporter.export(SPANS).join(10, TimeUnit.SECONDS).isSuccess()).isTrue();
}

@Test
void authorityWithAuth() {
OtlpGrpcSpanExporter exporter =
OtlpGrpcSpanExporter.builder()
.setEndpoint("http://foo:bar@localhost:" + server.httpPort())
.setEndpoint("http://foo:bar@" + canonicalHostName + ":" + server.httpPort())
.build();
assertThat(exporter.export(SPANS).join(10, TimeUnit.SECONDS).isSuccess()).isTrue();
}
Expand All @@ -116,7 +120,7 @@ void authorityWithAuth() {
void testTlsExport() throws Exception {
OtlpGrpcSpanExporter exporter =
OtlpGrpcSpanExporter.builder()
.setEndpoint("https://localhost:" + server.httpsPort())
.setEndpoint("https://" + canonicalHostName + ":" + server.httpsPort())
.setTrustedCertificates(
HELD_CERTIFICATE.certificatePem().getBytes(StandardCharsets.UTF_8))
.build();
Expand All @@ -127,7 +131,7 @@ void testTlsExport() throws Exception {
void testTlsExport_untrusted() {
OtlpGrpcSpanExporter exporter =
OtlpGrpcSpanExporter.builder()
.setEndpoint("https://localhost:" + server.httpsPort())
.setEndpoint("https://" + canonicalHostName + ":" + server.httpsPort())
.build();
assertThat(exporter.export(SPANS).join(10, TimeUnit.SECONDS).isSuccess()).isFalse();
}
Expand Down
Loading