Skip to content

Commit

Permalink
adapt IT tests and improve their resilience
Browse files Browse the repository at this point in the history
  • Loading branch information
brunobat committed Dec 22, 2022
1 parent 68c6abb commit 42dd7ff
Show file tree
Hide file tree
Showing 13 changed files with 54 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public void accept(String value) {
.getOpenTelemetrySdk();
}

return (OpenTelemetry) AutoConfiguredOpenTelemetrySdk.builder()
AutoConfiguredOpenTelemetrySdk autoConfiguredOpenTelemetrySdk = AutoConfiguredOpenTelemetrySdk.builder()
.setResultAsGlobal(true)
.registerShutdownHook(false)
.addPropertiesSupplier(() -> oTelConfigs)
Expand Down Expand Up @@ -195,8 +195,9 @@ public SdkTracerProviderBuilder apply(SdkTracerProviderBuilder builder,
return builder;
}
})
.build()
.getOpenTelemetrySdk();
.build();
// return GlobalOpenTelemetry.get();
return autoConfiguredOpenTelemetrySdk.getOpenTelemetrySdk();
}

private String transformPropertyName(String propertyName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public RuntimeValue<OpenTelemetry> createOpenTelemetry(ShutdownContext shutdownC
OpenTelemetry openTelemetry = beanManager.createInstance()
.select(OpenTelemetry.class, Any.Literal.INSTANCE).get();

// FIXME brunobat because we are producing the ObfuscatedOpenTelemetry these methods might not be available.
// Register shutdown tasks, because we are using CDI beans
shutdownContext.addShutdownTask(() -> {
((OpenTelemetrySdk) openTelemetry).getSdkTracerProvider().forceFlush();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public OtelConfigRelocateConfigSourceInterceptor() {
super(RELOCATIONS);
}

// FIXME not needed
@Override
public Iterator<String> iterateNames(final ConfigSourceInterceptorContext context) {
final Set<String> names = new HashSet<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import io.quarkus.runtime.annotations.ConfigPhase;
import io.quarkus.runtime.annotations.ConfigRoot;

@ConfigRoot(prefix = "otel.exporter.otlp", phase = ConfigPhase.BUILD_TIME)
@ConfigRoot(prefix = "otel.exporter.otlp", phase = ConfigPhase.BUILD_AND_RUN_TIME_FIXED)
public class OtlpExporterBuildConfig {
/**
* Legacy property kept for compatibility reasons. Just the defining the right exporter is enough.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
quarkus.grpc.clients.hello.host=localhost
%test.quarkus.grpc.clients.hello.port=9001

quarkus.otel.bsp.schedule.delay=100
quarkus.otel.bsp.export.timeout=5s
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ mp.messaging.incoming.traces-in.topic=traces
mp.messaging.incoming.traces-in.auto.offset.reset=earliest
mp.messaging.incoming.traces-in2.topic=traces2
mp.messaging.incoming.traces-in2.auto.offset.reset=earliest

quarkus.otel.bsp.schedule.delay=100
quarkus.otel.bsp.export.timeout=5s
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
quarkus.rest-client.client.url=${test.url}

quarkus.otel.bsp.schedule.delay=100
quarkus.otel.bsp.export.timeout=5s
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
quarkus.micrometer.enabled=true
quarkus.micrometer.binder-enabled-default=false

quarkus.otel.bsp.schedule.delay=100
quarkus.otel.bsp.export.timeout=5s
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import io.opentelemetry.api.trace.SpanKind;
Expand All @@ -39,7 +39,7 @@

@QuarkusTest
class HelloRouterTest {
@BeforeEach

@AfterEach
void reset() {
given().get("/reset").then().statusCode(HTTP_OK);
Expand Down Expand Up @@ -94,7 +94,7 @@ void post() {
.statusCode(HTTP_OK)
.body(equalTo("hello Naruto"));

await().atMost(5, TimeUnit.SECONDS).until(() -> getSpans().size() == 1);
await().atMost(5, TimeUnit.SECONDS).until(() -> spanSize(1));
List<Map<String, Object>> spans = getSpans();
assertEquals(1, spans.size());

Expand All @@ -121,9 +121,9 @@ void bus() {
assertEquals(1, messages.size());
assertEquals("hello to bus", messages.get(0));

await().atMost(5, TimeUnit.SECONDS).until(() -> getSpans().size() == 3);
await().atMost(50, TimeUnit.SECONDS).until(() -> spanSize(3));
List<Map<String, Object>> spans = getSpans();
assertEquals(3, spans.size());
assertEquals(3, spans.size(), "found:" + printSpans(spans));
assertEquals(1, spans.stream().map(map -> map.get("traceId")).collect(toSet()).size());

Map<String, Object> server = getSpanByKindAndParentId(spans, SERVER, "0000000000000000");
Expand All @@ -149,6 +149,28 @@ void bus() {
assertEquals(consumer.get("parentSpanId"), producer.get("spanId"));
}

private String printSpans(List<Map<String, Object>> spans) {
if (spans.isEmpty()) {
return "empty";
}
return spans.stream()
.map(stringObjectMap -> stringObjectMap.get("spanId") + " - " +
stringObjectMap.get("kind") + " - " +
stringObjectMap.get("http.route") + "\n")
.collect(Collectors.joining());
}

private Boolean spanSize(int expected) {
List<Map<String, Object>> spans = getSpans();
int size = spans.size();
if (size == expected) {
return true;
} else {
System.out.println("Reset but span remain: " + printSpans(spans));
return false;
}
}

private static List<Map<String, Object>> getSpans() {
return get("/export").body().as(new TypeRef<>() {
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
quarkus.application.name=opentelemetry-integration-test
quarkus.application.version=999-SNAPSHOT

#quarkus.otel.bsp.schedule.delay=100
#quarkus.otel.bsp.export.timeout=5s
quarkus.otel.traces.exporter=cdi
quarkus.otel.bsp.schedule.delay=100
quarkus.otel.bsp.export.timeout=5s
#quarkus.otel.bsp.max.export.batch.size=1
#quarkus.otel.traces.exporter=cdi

pingpong/mp-rest/url=${test.url}
simple/mp-rest/url=${test.url}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public void testOTelInjections() {
.when().get("/otel/injection")
.then()
.statusCode(200);
await().atMost(5, SECONDS).until(() -> getSpans().size() == 1);
}

@Test
Expand All @@ -43,5 +44,6 @@ public void testOTelInjectionsAsync() {
.when().get("/otel/injection/async")
.then()
.statusCode(200);
await().atMost(5, SECONDS).until(() -> getSpans().size() == 1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,7 @@ void testWrongHTTPVersion() {
} catch (IOException e) {
fail("Not failing graciously. Got: " + e.getMessage());
}
await().atMost(5, TimeUnit.SECONDS).until(() -> getSpans().size() == 1);
}

private void verifyResource(Map<String, Object> spanData) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import org.junit.jupiter.api.Assertions;

import io.opentelemetry.api.GlobalOpenTelemetry;
import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.api.baggage.Baggage;
import io.opentelemetry.api.trace.Span;
Expand Down Expand Up @@ -50,7 +49,7 @@ private void verifyInjections() {
Assertions.assertNotNull(span, "Span cannot be injected");
Assertions.assertNotNull(openTelemetry, "Baggage cannot be injected");

Assertions.assertEquals(GlobalOpenTelemetry.get(), openTelemetry);
// Assertions.assertEquals(GlobalOpenTelemetry.get(), openTelemetry);
Assertions.assertEquals(Span.current().getSpanContext(), span.getSpanContext());
Assertions.assertEquals(Baggage.current().size(), baggage.size());
baggage.asMap().forEach((s, baggageEntry) -> Assertions.assertEquals(baggageEntry, baggage.asMap().get(s)));
Expand Down

0 comments on commit 42dd7ff

Please sign in to comment.