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

Adjust expectations regarding OpenTelemetry JDBC operation names after Hibernate ORM bump to 6.5 #1783

Merged
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 @@ -57,8 +57,12 @@ protected boolean isDatabaseTableLockedWhenTransactionFailed() {
}

@Override
protected String[] getExpectedJdbcOperationNames() {
return new String[] { "SELECT msdb.account", "INSERT msdb.journal", "UPDATE msdb.account" };
protected Operation[] getExpectedJdbcOperations() {
return new Operation[] { new Operation("SELECT msdb.account"), new Operation("INSERT msdb.journal"),
// here we are looking for UPDATE msdb.ae1_0 because currently DB statement is
// update ae1_0 set amount=?,updatedAt=? from account ae1_0 where ae1_0.accountNumber=?
// however we shouldn't rely on alias generation logic, therefore we test the UPDATE statement is there
new Operation(actualOperationName -> actualOperationName.startsWith("UPDATE msdb.")) };
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ protected TransactionExecutor getTransactionExecutorUsedForRecovery() {
}

@Override
protected String[] getExpectedJdbcOperationNames() {
return new String[] { "SELECT mydb.dual", "INSERT mydb.journal", "UPDATE mydb.account" };
protected Operation[] getExpectedJdbcOperations() {
return new Operation[] { new Operation("SELECT mydb.dual"), new Operation("INSERT mydb.journal"),
new Operation("UPDATE mydb.account") };
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.function.Predicate;
import java.util.stream.Collectors;

import org.apache.http.HttpStatus;
import org.hamcrest.Matchers;
Expand All @@ -37,6 +38,8 @@
public abstract class TransactionCommons {

private static final String ENABLE_TRANSACTION_RECOVERY = "quarkus.transaction-manager.enable-recovery";
private static final int SERVICE_TRACES_LIMIT = 1000;
private static final String NARAYANA_SERVICE_NAME = "narayanaTransactions";
static final String ACCOUNT_NUMBER_MIGUEL = "SK0389852379529966291984";
static final String ACCOUNT_NUMBER_GARCILASO = "FR9317569000409377431694J37";
static final String ACCOUNT_NUMBER_LUIS = "ES8521006742088984966816";
Expand Down Expand Up @@ -172,13 +175,49 @@ public void smokeTestNarayanaProgrammaticTransactionTrace() {
@Order(6)
@Test
public void verifyJdbcTraces() {
for (String operationName : getExpectedJdbcOperationNames()) {
verifyRequestTraces(operationName);
var serviceTraces = retrieveServiceTraces(NARAYANA_SERVICE_NAME);
var operationNames = serviceTraces.jsonPath().getList("data.spans.operationName.flatten()", String.class);
for (var operation : getExpectedJdbcOperations()) {
verifyTracesForOperationArePresent(operation, operationNames);
}
}

protected String[] getExpectedJdbcOperationNames() {
return new String[] { "SELECT mydb.account", "INSERT mydb.journal", "UPDATE mydb.account" };
private static void verifyTracesForOperationArePresent(Operation operation, List<String> operationNames) {
var matchedOperationNames = operationNames.stream().filter(operation.operationNameMatcher())
.collect(Collectors.toSet());
if (matchedOperationNames.isEmpty()) {
Assertions.fail("Failed to find operation %s, known operation names are: %s".formatted(operation, operationNames));
}
if (matchedOperationNames.size() > 1) {
throw new IllegalStateException(
"Operation %s matched more than one operation names, therefore the test cannot be executed reliably: %s"
.formatted(operation, matchedOperationNames));
}
}

/**
* @param operationNameMatcher matches found operation names with expected operation name
*/
protected record Operation(Predicate<String> operationNameMatcher) {

Operation(String operationName) {
this(operationName::equals);
}

}

private Response retrieveServiceTraces(String serviceName) {
return given().when()
.log().uri()
.queryParam("service", serviceName)
.queryParam("lookback", "1h")
.queryParam("limit", SERVICE_TRACES_LIMIT)
.get(jaeger.getTraceUrl());
}

protected Operation[] getExpectedJdbcOperations() {
return new Operation[] { new Operation("SELECT mydb.account"), new Operation("INSERT mydb.journal"),
new Operation("UPDATE mydb.account") };
}

@Order(7)
Expand Down