From dd17fb95251f377b5eafe93a2e911a3628cd1c3a Mon Sep 17 00:00:00 2001 From: Ales Justin Date: Mon, 7 Oct 2024 11:11:08 +0200 Subject: [PATCH] Add missing OTLP gRPC test, simplify ports usage --- .../common/ContainerConstants.java | 1 + .../testcontainers/LgtmContainer.java | 13 +++++++--- .../devresource/lgtm/LgtmResource.java | 10 ++++--- .../observability/test/LgtmGrpcTest.java | 26 +++++++++++++++++++ 4 files changed, 43 insertions(+), 7 deletions(-) create mode 100644 integration-tests/observability-lgtm/src/test/java/io/quarkus/observability/test/LgtmGrpcTest.java diff --git a/extensions/observability-devservices/common/src/main/java/io/quarkus/observability/common/ContainerConstants.java b/extensions/observability-devservices/common/src/main/java/io/quarkus/observability/common/ContainerConstants.java index f815c77415331..bb50ac4513475 100644 --- a/extensions/observability-devservices/common/src/main/java/io/quarkus/observability/common/ContainerConstants.java +++ b/extensions/observability-devservices/common/src/main/java/io/quarkus/observability/common/ContainerConstants.java @@ -13,5 +13,6 @@ public final class ContainerConstants { public static final int OTEL_GRPC_EXPORTER_PORT = 4317; public static final int OTEL_HTTP_EXPORTER_PORT = 4318; + public static final String OTEL_GRPC_PROTOCOL = "grpc"; public static final String OTEL_HTTP_PROTOCOL = "http/protobuf"; } diff --git a/extensions/observability-devservices/testcontainers/src/main/java/io/quarkus/observability/testcontainers/LgtmContainer.java b/extensions/observability-devservices/testcontainers/src/main/java/io/quarkus/observability/testcontainers/LgtmContainer.java index f218711b137cc..a56d503128121 100644 --- a/extensions/observability-devservices/testcontainers/src/main/java/io/quarkus/observability/testcontainers/LgtmContainer.java +++ b/extensions/observability-devservices/testcontainers/src/main/java/io/quarkus/observability/testcontainers/LgtmContainer.java @@ -41,7 +41,8 @@ public LgtmContainer() { public LgtmContainer(LgtmConfig config) { super(config); - addExposedPorts(getOtlpPortInternal()); + // always expose both -- since the LGTM image already does that as well + addExposedPorts(ContainerConstants.OTEL_GRPC_EXPORTER_PORT, ContainerConstants.OTEL_HTTP_EXPORTER_PORT); // cannot override grafana-dashboards.yaml in the container because it's on a version dependent path: // ./grafana-v11.0.0/conf/provisioning/dashboards/grafana-dashboards.yaml // will replace contents of current dashboards @@ -69,8 +70,14 @@ public int getOtlpPort() { } private int getOtlpPortInternal() { - return ContainerConstants.OTEL_HTTP_PROTOCOL.equals(getOtlpProtocol()) ? ContainerConstants.OTEL_HTTP_EXPORTER_PORT - : ContainerConstants.OTEL_GRPC_EXPORTER_PORT; + // use ignore-case here; grpc == gRPC + if (ContainerConstants.OTEL_GRPC_PROTOCOL.equalsIgnoreCase(getOtlpProtocol())) { + return ContainerConstants.OTEL_GRPC_EXPORTER_PORT; + } else if (ContainerConstants.OTEL_HTTP_PROTOCOL.equals(getOtlpProtocol())) { + return ContainerConstants.OTEL_HTTP_EXPORTER_PORT; + } else { + throw new IllegalArgumentException("Unsupported OTEL protocol: " + getOtlpProtocol()); + } } private String getPrometheusConfig() { diff --git a/extensions/observability-devservices/testlibs/devresource-lgtm/src/main/java/io/quarkus/observability/devresource/lgtm/LgtmResource.java b/extensions/observability-devservices/testlibs/devresource-lgtm/src/main/java/io/quarkus/observability/devresource/lgtm/LgtmResource.java index 281e5ac26ebe5..2c835036c789d 100644 --- a/extensions/observability-devservices/testlibs/devresource-lgtm/src/main/java/io/quarkus/observability/devresource/lgtm/LgtmResource.java +++ b/extensions/observability-devservices/testlibs/devresource-lgtm/src/main/java/io/quarkus/observability/devresource/lgtm/LgtmResource.java @@ -53,21 +53,23 @@ protected LgtmContainer defaultContainer() { @Override public Map doStart() { String host = container.getHost(); + int otlpPort = container.getOtlpPort(); //Set non Quarkus properties for convenience and testing. Map containerConfigs = new HashMap<>(); containerConfigs.put("grafana.endpoint", String.format("http://%s:%s", host, container.getGrafanaPort())); - containerConfigs.put("otel-collector.url", String.format("%s:%s", host, container.getOtlpPort())); + containerConfigs.put("otel-collector.url", String.format("%s:%s", host, otlpPort)); // set relevant properties for Quarkus extensions directly if (catalog != null && catalog.hasOpenTelemetry()) { - containerConfigs.put("quarkus.otel.exporter.otlp.endpoint", - String.format("http://%s:%s", host, container.getOtlpPort())); + containerConfigs.put("quarkus.otel.exporter.otlp.endpoint", String.format("http://%s:%s", host, otlpPort)); containerConfigs.put("quarkus.otel.exporter.otlp.protocol", container.getOtlpProtocol()); } if (catalog != null && catalog.hasMicrometerOtlp()) { + // always use http -- as that's what Micrometer supports containerConfigs.put("quarkus.micrometer.export.otlp.url", - String.format("http://%s:%s/v1/metrics", host, container.getOtlpPort())); + String.format("http://%s:%s/v1/metrics", host, + container.getMappedPort(ContainerConstants.OTEL_HTTP_EXPORTER_PORT))); } return containerConfigs; } diff --git a/integration-tests/observability-lgtm/src/test/java/io/quarkus/observability/test/LgtmGrpcTest.java b/integration-tests/observability-lgtm/src/test/java/io/quarkus/observability/test/LgtmGrpcTest.java new file mode 100644 index 0000000000000..ef7cf1595f4aa --- /dev/null +++ b/integration-tests/observability-lgtm/src/test/java/io/quarkus/observability/test/LgtmGrpcTest.java @@ -0,0 +1,26 @@ +package io.quarkus.observability.test; + +import java.util.Map; + +import org.junit.jupiter.api.condition.DisabledOnOs; +import org.junit.jupiter.api.condition.OS; + +import io.quarkus.test.junit.QuarkusTest; +import io.quarkus.test.junit.QuarkusTestProfile; +import io.quarkus.test.junit.TestProfile; + +/** + * Simple case were we use gRPC as a OTLP protocol + */ +@QuarkusTest +@TestProfile(LgtmGrpcTest.GrpcTestProfileOnly.class) +@DisabledOnOs(OS.WINDOWS) +public class LgtmGrpcTest extends LgtmTestBase { + + public static class GrpcTestProfileOnly implements QuarkusTestProfile { + @Override + public Map getConfigOverrides() { + return Map.of("quarkus.observability.lgtm.otlp-protocol", "grpc"); + } + } +}