Skip to content

fix(bigquery-jdbc): gate log writer lifecycle, mask URL secrets, and short-circuit Gate 1 - #15255

Open
Neenu1995 wants to merge 1 commit into
fix/bq-jdbc-per-conn-log-isolationfrom
fix/bq-jdbc-log-lifecycle-masking-filtering
Open

Neenu1995 wants to merge 1 commit into
fix/bq-jdbc-per-conn-log-isolationfrom
fix/bq-jdbc-log-lifecycle-masking-filtering

Conversation

@Neenu1995

Copy link
Copy Markdown
Contributor

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 ConnectionLogContexts 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 ByteBuffers 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.

@Neenu1995
Neenu1995 requested review from a team as code owners November 26, 2026 20:48

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a system property restriction (com.google.cloud.bigquery.jdbc.allowUrlLogPath) to ignore URL-supplied log paths, enhances log sanitization and sensitive property masking, and refactors the logging system to use ReentrantLock and a slot-based connection writer mechanism. Feedback on these changes includes addressing an issue where explicitly configured external root log levels are ignored during effective level updates, and simplifying redundant slot-clearing loops in the file handler's close method.

String connectionId = context != null ? context.connectionId() : null;

if (connectionLevels != null) {
if (managed) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor. Production only constructs this handler with managed = true (BigQueryJdbcRootLogger L654), so the non-managed branch below and the two shorter constructors are reachable only from tests; 16 of 17 constructions in PerConnectionFileHandlerTest use them. Likewise BigQueryJdbcRootLogger.setLevel(Level, String) now ignores both arguments, but BigQueryDriver L185 still calls it and BigQueryDriverTest mocks it to throw. Please remove both and move the tests to the managed mode.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two reasons we kept these as-is in PR 6 rather than folding a broad cleanup into the top of the stack:

  1. BigQueryDriver IOException contract & main test coverage: BigQueryJdbcRootLogger.setLevel(Level, String) throws IOException is the only checked IOException source inside BigQueryDriver.connect()'s try block (BigQueryDriver.java:241), which BigQueryDriverTest.testConnect_ioExceptionThrowsInsteadOfReturningNull (BigQueryDriverTest.java:285) mocks directly to verify JDBC SQLException wrapping instead of returning null. Removing setLevel makes catch (IOException) an unreachable-catch compile error in javac.
  2. Isolated NIO unit testing & PR size: PerConnectionFileHandler is package-private, and the 2-/3-arg constructors let PerConnectionFileHandlerTest exercise low-level NIO permissions, symlink checks, sentinel locks, interrupt recovery, and 1 GiB rotation deterministically without mutating JVM-global LogManager / BigQueryJdbcRootLogger state across 16 tests (~250 lines of test churn). Happy to follow up in a standalone post-stack test-cleanup PR if we want to consolidate those later.

return Collections.unmodifiableMap(map);
}

static boolean isUrlLogPathAllowed() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question (carried over from #15167). With the switch off, LogLevel still comes from the URL, so a caller can still raise it to FINEST. Should the switch also pin the level to BIGQUERY_JDBC_LOG_LEVEL?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keeping allowUrlLogPath=false scoped strictly to filesystem path resolution (LogPath) is intentional for two production workflows:

  1. Cloud Logging / OpenTelemetry (EnableGcpLogExporter=1 / customOpenTelemetry): Cloud-native deployments that set -Dcom.google.cloud.bigquery.jdbc.allowUrlLogPath=false to forbid local container disk writes still rely on per-connection LogLevel to control OTel / Cloud Logging export verbosity.
  2. Targeted per-DataSource diagnostics in an admin-pinned directory: When an operator configures BIGQUERY_JDBC_LOG_PATH=/var/log/bq + allowUrlLogPath=false to lock where files go, keeping URL LogLevel independent lets them set LogLevel=5/6 on one troubled DataSource without raising verbosity across every connection in the JVM (while PR 3's 1 GiB cap + PR 6's secret masking + Gate 1 isolation bound disk and cross-connection impact). If a hard verbosity ceiling is ever needed, a separate dedicated property would be cleaner than overloading allowUrlLogPath.

@Neenu1995
Neenu1995 force-pushed the fix/bq-jdbc-log-lifecycle-masking-filtering branch from ea42927 to e137414 Compare November 27, 2026 16:11

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants