Skip to content

Commit fa6641b

Browse files
fix(bigquery-jdbc): enable ITOpenTelemetryTest (#13991)
b/540093018 #### **Problem** * `ITOpenTelemetryTest` was failing when run in the nightly test suite because an earlier test in `ITBigQueryJDBCTest` stripped all handlers from the `"com.google.cloud.bigquery"` logger in its `finally` block, including `OpenTelemetryJulHandler`. #### **Changes** * **`ITBigQueryJDBCTest.java`**: Restrict logger cleanup in `testLogPathWithLogLevel` to preserve `OpenTelemetryJulHandler` * **`BigQueryConnection.java`**: Defensively call `BigQueryJdbcOpenTelemetry.ensureGlobalHandlerAttached()` in `getOpenTelemetryInstance()` so any new connection re-attaches `OpenTelemetryJulHandler` if removed. * **`OpenTelemetryJulHandler.java`**: * Use `ErrorManager.reportError(...)` in `publish(...)` and `flush()` instead of empty catch blocks. * **`ITOpenTelemetryTest.java`**: * Remove `@Tag("known_issue")` to re-enable `ITOpenTelemetryTest` in CI/nightly builds. * Reduce `maxAttempts` in `pollWithRetry(...)` from `24` back down to `10`. * **`pom.xml`**: Remove obsolete IPv4 test properties (`preferIpv4.test.argLine`) from surefire and failsafe configurations.
1 parent 613a074 commit fa6641b

5 files changed

Lines changed: 13 additions & 12 deletions

File tree

java-bigquery-jdbc/pom.xml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
<github.global.server>github</github.global.server>
3333
<site.installationModule>google-cloud-bigquery-jdbc</site.installationModule>
3434
<skipShade>false</skipShade>
35-
<preferIpv4.test.argLine>-Djava.net.preferIPv4Stack=true</preferIpv4.test.argLine>
3635
</properties>
3736

3837
<build>
@@ -48,7 +47,6 @@
4847
<artifactId>maven-surefire-plugin</artifactId>
4948
<version>3.5.2</version>
5049
<configuration>
51-
<argLine>@{argLine} ${preferIpv4.test.argLine}</argLine>
5250
<skip>${skipSurefire}</skip>
5351
<systemPropertyVariables>
5452
<JDBC_TESTS>true</JDBC_TESTS>
@@ -59,7 +57,6 @@
5957
<groupId>org.apache.maven.plugins</groupId>
6058
<artifactId>maven-failsafe-plugin</artifactId>
6159
<configuration>
62-
<argLine>@{argLine} ${preferIpv4.test.argLine}</argLine>
6360
<systemPropertyVariables>
6461
<JDBC_TESTS>true</JDBC_TESTS>
6562
</systemPropertyVariables>
@@ -480,14 +477,14 @@
480477
<groupId>org.apache.maven.plugins</groupId>
481478
<artifactId>maven-surefire-plugin</artifactId>
482479
<configuration>
483-
<argLine>@{argLine} ${preferIpv4.test.argLine} --add-opens=java.base/java.nio=org.apache.arrow.memory.core,ALL-UNNAMED</argLine>
480+
<argLine>--add-opens=java.base/java.nio=org.apache.arrow.memory.core,ALL-UNNAMED</argLine>
484481
</configuration>
485482
</plugin>
486483
<plugin>
487484
<groupId>org.apache.maven.plugins</groupId>
488485
<artifactId>maven-failsafe-plugin</artifactId>
489486
<configuration>
490-
<argLine>@{argLine} ${preferIpv4.test.argLine} --add-opens=java.base/java.nio=org.apache.arrow.memory.core,ALL-UNNAMED</argLine>
487+
<argLine>--add-opens=java.base/java.nio=org.apache.arrow.memory.core,ALL-UNNAMED</argLine>
491488
</configuration>
492489
</plugin>
493490
</plugins>

java-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryConnection.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,6 +1185,7 @@ void removeStatement(Statement statement) {
11851185
}
11861186

11871187
private OpenTelemetry getOpenTelemetryInstance() {
1188+
BigQueryJdbcOpenTelemetry.ensureGlobalHandlerAttached();
11881189

11891190
String effectiveProjectId =
11901191
(this.gcpTelemetryProjectId != null) ? this.gcpTelemetryProjectId : this.catalog;

java-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/OpenTelemetryJulHandler.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import io.opentelemetry.context.Context;
3131
import java.time.Instant;
3232
import java.util.Collections;
33+
import java.util.logging.ErrorManager;
3334
import java.util.logging.Handler;
3435
import java.util.logging.Level;
3536
import java.util.logging.LogRecord;
@@ -78,7 +79,8 @@ public void publish(LogRecord record) {
7879
publishToOTel(record, connectionId, config.openTelemetry);
7980
}
8081
} catch (Throwable t) {
81-
// Ignore exceptions to prevent breaking application logging or other handlers
82+
Exception ex = (t instanceof Exception) ? (Exception) t : new Exception(t);
83+
reportError("Error publishing log to OpenTelemetry/GCP", ex, ErrorManager.WRITE_FAILURE);
8284
}
8385
}
8486

@@ -182,7 +184,7 @@ public void flush() {
182184
try {
183185
config.loggingClient.flush();
184186
} catch (Exception e) {
185-
// Ignore failures during flush to protect other connections
187+
reportError("Error flushing log to OpenTelemetry/GCP", e, ErrorManager.FLUSH_FAILURE);
186188
}
187189
}
188190
}

java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITBigQueryJDBCTest.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import com.google.cloud.bigquery.jdbc.BigQueryConnection;
3737
import com.google.cloud.bigquery.jdbc.BigQueryDriver;
3838
import com.google.cloud.bigquery.jdbc.DataSource;
39+
import com.google.cloud.bigquery.jdbc.OpenTelemetryJulHandler;
3940
import com.google.common.collect.ImmutableMap;
4041
import java.io.File;
4142
import java.io.IOException;
@@ -2808,8 +2809,10 @@ public void testPerConnectionLoggingE2E() throws SQLException, IOException {
28082809
java.util.logging.Logger bqLogger =
28092810
java.util.logging.Logger.getLogger("com.google.cloud.bigquery");
28102811
for (java.util.logging.Handler h : bqLogger.getHandlers()) {
2811-
h.close();
2812-
bqLogger.removeHandler(h);
2812+
if (!(h instanceof OpenTelemetryJulHandler)) {
2813+
h.close();
2814+
bqLogger.removeHandler(h);
2815+
}
28132816
}
28142817

28152818
// Verify physical connection-specific log file creation

java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITOpenTelemetryTest.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,8 @@
4545
import java.sql.Statement;
4646
import java.util.ArrayList;
4747
import java.util.List;
48-
import org.junit.jupiter.api.Tag;
4948
import org.junit.jupiter.api.Test;
5049

51-
@Tag("known_issue") // b/539615312
5250
public class ITOpenTelemetryTest extends ITBase {
5351

5452
private static final String PROJECT_ID = ServiceOptions.getDefaultProjectId();
@@ -309,7 +307,7 @@ private Trace verifyAndFetchTrace(String traceId) throws Exception {
309307

310308
private <T> T pollWithRetry(java.util.concurrent.Callable<T> task) throws InterruptedException {
311309
int attempts = 0;
312-
int maxAttempts = 24;
310+
int maxAttempts = 10;
313311
long delayMs = 10000;
314312

315313
// 10 second wait for GCP to ingest data

0 commit comments

Comments
 (0)