Skip to content

Commit

Permalink
Add missing OTLP gRPC test, simplify ports usage
Browse files Browse the repository at this point in the history
  • Loading branch information
alesj committed Oct 7, 2024
1 parent 9832943 commit dd17fb9
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,23 @@ protected LgtmContainer defaultContainer() {
@Override
public Map<String, String> doStart() {
String host = container.getHost();
int otlpPort = container.getOtlpPort();

//Set non Quarkus properties for convenience and testing.
Map<String, String> 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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String, String> getConfigOverrides() {
return Map.of("quarkus.observability.lgtm.otlp-protocol", "grpc");
}
}
}

0 comments on commit dd17fb9

Please sign in to comment.