Repository navigation
Conversation
…g files PR 1 of 6 in the diagnostic logging series (b/584840147, part 1 of 3). Replaces java.util.logging.FileHandler inside PerConnectionFileHandler with an NIO SeekableByteChannel writer enforcing 0700/0600 POSIX permissions, symlink rejection, collision-safe exclusive creation, literal % path handling, and graceful ErrorManager degradation.
…tionLogContext PR 2 of 6 in the diagnostic logging series (b/584840147, part 2 of 3). Adds bounded 1 GiB two-file (.log + .1.log 0600 backup) rotation with graceful ErrorManager fallback to PerConnectionFileHandler, and replaces raw String LogRecord parameter stamping with typed ConnectionLogContext across BigQueryJdbcResultSetLogger and OpenTelemetryJulHandler.
…ion lifecycle PR 3 of 6 in the diagnostic logging series (b/584840147, part 3 of 3). Tracks active connections in BigQueryJdbcRootLogger with BigQueryConnection constructor finally cleanup and wraps per-connection writers in synchronized ConnectionFileSlot entries so post-close ResultSet/Struct calls and concurrent close() vs publish() calls do not reopen closed writers.
…UrlLogPath option PR 4 of 6 in the diagnostic logging series (b/584840083, part 1 of 2). Applies BigQueryConnection.SAFE_TO_LOG_PROPERTIES allowlist masking in BigQueryJdbcUrlUtility.appendPropertiesToURL, binds reentrant BigQueryJdbcMdc context at the start of BigQueryDriver.connect with failure cleanup, and adds -Dcom.google.cloud.bigquery.jdbc.allowUrlLogPath.
… path degradation PR 5 of 6 in the diagnostic logging series (b/584840083, part 2 of 2). Isolates per-connection LogLevel and LogPath slots inside a single persistent PerConnectionFileHandler without stripping OpenTelemetryJulHandler or external JUL handlers on LogLevel=0, degrades gracefully on unwritable/invalid/symlinked LogPath without failing Driver.connect, and computes the root logger threshold dynamically across open connections.
PR 6 of 6 in the diagnostic logging series. Tracks external JUL handlers and parent-handler delegation on com.google.cloud.bigquery without per-call Handler[] allocations, propagates ConnectionLogContext through BigQueryJdbcMdc and BigQueryJdbcContextProxy, and short-circuits disabled or higher-threshold connection logs at Gate 1 (isLoggable) across BigQueryJdbcCustomLogger and BigQueryJdbcResultSetLogger.
…tation-and-context
…log-handler-lifecycle
…ate1-log-filtering
There was a problem hiding this comment.
Code Review
This pull request refactors the logging mechanism in the BigQuery JDBC driver to use connection-specific logging contexts (ConnectionLogContext) and improves MDC context propagation across threads. It introduces a custom logger (BigQueryJdbcCustomLogger) to handle context-aware loggability checks and adds comprehensive tests to verify short-circuiting behavior. However, a critical issue was identified in BigQueryJdbcCustomLogger where connections defaulting to INHERIT_VALUE immediately bypass the threshold check. This defeats the Gate-1 short-circuiting optimization when another connection is configured with FINEST logging, leading to unnecessary log evaluation and allocations on hot paths. It is recommended to resolve INHERIT_VALUE to the explicit global level instead.
63f8a7c to
3b01d92
Compare
8194a83 to
5a4ae22
Compare
…tation-and-context # Conflicts: # java-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/PerConnectionFileHandler.java
…log-handler-lifecycle # Conflicts: # java-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/PerConnectionFileHandler.java
…ate1-log-filtering
3b01d92 to
a209aeb
Compare
5a4ae22 to
238c473
Compare
|
/gcbrun |
…tation-and-context # Conflicts: # java-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/PerConnectionFileHandler.java
…log-handler-lifecycle
…ate1-log-filtering
…log-handler-lifecycle
…ate1-log-filtering
|
/gcbrun |
keshavdandeva
left a comment
There was a problem hiding this comment.
The gate works. Repro: with connections at FINEST, INFO and OFF, only the FINEST one evaluated its message suppliers, and a disabled trace call on a quiet connection dropped from ~162 ns to ~8 ns (rough timing loop, not JMH). Two minors inline. On the bot comment: agree with "n/a", since connect() always registers an explicit level.
cad2b7c to
b585440
Compare
…short-circuit Gate 1 (#15255) Stack: PR 6 of 6 (base: `fix/bq-jdbc-per-conn-log-isolation`; consolidates #15166, #15167, and #15169) Bug: b/584840147, b/584840083 ### Summary Consolidates the final three diagnostic logging layers and incorporates review feedback across the stack: synchronizes per-connection writer slot close-vs-publish lifecycle and constructor failure rollback, masks non-allowlisted URL/connection secrets with ASCII control-character sanitization and fail-closed `-Dcom.google.cloud.bigquery.jdbc.allowUrlLogPath`, and adds Gate-1 `isLoggable` short-circuiting with external JUL `Handler` preservation. ### Environment Variables & System Properties - **Added System Property:** `-Dcom.google.cloud.bigquery.jdbc.allowUrlLogPath=<true|false|1|0>` (default: `true`; fail-closed allowing unset/blank, `true`, or `1`). When disabled, URL/Properties `LogPath` values are ignored with both a log `WARNING` and a JDBC `SQLWarning` on `Connection`. Documented in `docs/USER_GUIDE.md`. ### Design Decisions & Review Feedback Addressed - **Race-free `ConnectionWriterSlot` & `ReentrantLock` I/O locking:** Guards writer lifecycle and handler coordination with `ReentrantLock` (avoiding virtual-thread pinning across file I/O), disarms closed `ConnectionLogContext`s to `OFF_VALUE`, and cleans up executors/OTel resources on failed construction. - **Secret masking & log-injection sanitization:** Removes `BYOID_CredentialSource` from case-insensitive `SAFE_TO_LOG_PROPERTIES` and replaces ASCII control characters (`< 0x20`, `0x7F`) with `?` in logged property keys and allowlisted values. - **Fast-path Gate-1 filtering:** Checks `super.isLoggable(level)` ahead of thread-local MDC lookup (`~0.6 ns` disabled path) and preserves externally attached JUL handlers via `RootDriverLogger`. - **Channel & rotation refinements:** Opens exclusive channels with `APPEND`, writes `ByteBuffer`s in 8 KiB slices, emits `[LOG TRUNCATED: ...]` markers on fallback truncation, removes redundant backup UID checks before atomic `Files.move`, reports invalid `maxLogFileBytes` once, and installs a bounded `DeduplicatingErrorManager`.
Summary
PR 6 of 6 in the diagnostic logging stack (stacked on
fix/bq-jdbc-per-conn-log-isolation). Adds per-connection Gate-1isLoggable(Level)short-circuiting so connections atLogLevel=0(OFF) or higher thresholds avoidSupplier<String>evaluation andLogRecordallocation even when a concurrent connection raises the shared root logger toFINEST.Environment Variables & System Properties
Design Decisions
ConnectionLogContext): With per-connection handler isolation (PR 5), the sharedcom.google.cloud.bigquerylogger runs at the minimum active level across open connections. Checking the active connection'sConnectionLogContext.isLoggable(levelValue)directly insideBigQueryJdbcCustomLogger.isLoggableandBigQueryJdbcResultSetLogger.isLoggablerestores zero-allocation fast-path filtering for quiet connections on hotResultSetread paths.RootDriverLogger): SubclassesLoggerforcom.google.cloud.bigqueryto update avolatile boolean externalHandlerAttachedflag only whenaddHandler,removeHandler, orsetUseParentHandlersis called, avoidingLogger.getHandlers()array cloning on everyisLoggablecheck while ensuring externally attached JUL handlers still receive all records allowed by the root logger.InheritableThreadLocalpropagation: CachesConnectionLogContextonBigQueryJdbcContextProxy, propagates it acrossMdcThreadPoolExecutortasks, and flips closed connections toOFF_VALUEimmediately uponcloseConnectionHandler.