Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test coverage for openTelemetry management endpoint traces #1615

Merged
merged 1 commit into from
Jan 16, 2024
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
4 changes: 4 additions & 0 deletions monitoring/opentelemetry/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-grpc</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-health</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus.qe</groupId>
<artifactId>quarkus-test-service-jaeger</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package io.quarkus.ts.opentelemetry;

import static io.restassured.RestAssured.given;
import static org.awaitility.Awaitility.await;
import static org.hamcrest.Matchers.containsString;

import java.util.concurrent.TimeUnit;

import org.apache.http.HttpStatus;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

import io.quarkus.test.bootstrap.JaegerService;
import io.quarkus.test.bootstrap.RestService;
import io.quarkus.test.scenarios.QuarkusScenario;
import io.quarkus.test.services.JaegerContainer;
import io.quarkus.test.services.QuarkusApplication;

@QuarkusScenario
public class OpenTelemetryManagementIT {
@JaegerContainer
static final JaegerService jaeger = new JaegerService();

@QuarkusApplication
static RestService pong = new RestService()
.withProperty("quarkus.application.name", "pong")
.withProperty("quarkus.management.enabled", "true")
.withProperty("quarkus.otel.exporter.otlp.traces.endpoint", jaeger::getCollectorUrl);

private static final String PONG_ENDPOINT = "/hello";
private static final String MANAGEMENT_ENDPOINT = "/q/health/ready";

/**
* Test openTelemetry not sending traces from management endpoints
*/
@Test
@Tag("https://github.com/quarkusio/quarkus/pull/37218")
public void managementEndpointExcludedFromTracesTest() {
// invoke management endpoint, so service is prone to send trace from it
// if fix is already in place, it should not send any
pong.management().get(MANAGEMENT_ENDPOINT)
.then().statusCode(HttpStatus.SC_OK);

// invoke normal endpoint, so we can check that traces are uploading correctly
given()
.when().get(PONG_ENDPOINT)
.then()
.statusCode(HttpStatus.SC_OK)
.body(containsString("pong"));

// wait for pong endpoint to be logged in traces
await().atMost(10, TimeUnit.SECONDS).untilAsserted(() -> given()
.when()
.queryParam("service", pong.getName())
.get(jaeger.getTraceUrl())
.then().statusCode(HttpStatus.SC_OK)
.and().body(containsString(PONG_ENDPOINT)));

String traces = given().when()
.queryParam("service", pong.getName())
.get(jaeger.getTraceUrl())
.thenReturn().body().asString();

// check that management endpoint is not present in traces, while correct trace is there
Assertions.assertTrue(traces.contains(PONG_ENDPOINT), "Pong endpoint should be logged in traces");
Assertions.assertFalse(traces.contains(MANAGEMENT_ENDPOINT), "Management endpoint should not be logged in traces");
}
}