Repository navigation
Conversation
There was a problem hiding this comment.
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.
80a4d01 to
24e99d2
Compare
24e99d2 to
039c500
Compare
| String connectionId = context != null ? context.connectionId() : null; | ||
|
|
||
| if (connectionLevels != null) { | ||
| if (managed) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Two reasons we kept these as-is in PR 6 rather than folding a broad cleanup into the top of the stack:
BigQueryDriverIOExceptioncontract &maintest coverage:BigQueryJdbcRootLogger.setLevel(Level, String) throws IOExceptionis the only checkedIOExceptionsource insideBigQueryDriver.connect()'stryblock (BigQueryDriver.java:241), whichBigQueryDriverTest.testConnect_ioExceptionThrowsInsteadOfReturningNull(BigQueryDriverTest.java:285) mocks directly to verify JDBCSQLExceptionwrapping instead of returningnull. RemovingsetLevelmakescatch (IOException)an unreachable-catch compile error injavac.- Isolated NIO unit testing & PR size:
PerConnectionFileHandleris package-private, and the 2-/3-arg constructors letPerConnectionFileHandlerTestexercise low-level NIO permissions, symlink checks, sentinel locks, interrupt recovery, and 1 GiB rotation deterministically without mutating JVM-globalLogManager/BigQueryJdbcRootLoggerstate 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() { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Keeping allowUrlLogPath=false scoped strictly to filesystem path resolution (LogPath) is intentional for two production workflows:
- Cloud Logging / OpenTelemetry (
EnableGcpLogExporter=1/customOpenTelemetry): Cloud-native deployments that set-Dcom.google.cloud.bigquery.jdbc.allowUrlLogPath=falseto forbid local container disk writes still rely on per-connectionLogLevelto control OTel / Cloud Logging export verbosity. - Targeted per-DataSource diagnostics in an admin-pinned directory: When an operator configures
BIGQUERY_JDBC_LOG_PATH=/var/log/bq+allowUrlLogPath=falseto lock where files go, keeping URLLogLevelindependent lets them setLogLevel=5/6on 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 overloadingallowUrlLogPath.
…add open-retry backoff
ea42927 to
e137414
Compare
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-1isLoggableshort-circuiting with external JULHandlerpreservation.Environment Variables & System Properties
-Dcom.google.cloud.bigquery.jdbc.allowUrlLogPath=<true|false|1|0>(default:true; fail-closed allowing unset/blank,true, or1). When disabled, URL/PropertiesLogPathvalues are ignored with both a logWARNINGand a JDBCSQLWarningonConnection. Documented indocs/USER_GUIDE.md.Design Decisions & Review Feedback Addressed
ConnectionWriterSlot&ReentrantLockI/O locking: Guards writer lifecycle and handler coordination withReentrantLock(avoiding virtual-thread pinning across file I/O), disarms closedConnectionLogContexts toOFF_VALUE, and cleans up executors/OTel resources on failed construction.BYOID_CredentialSourcefrom case-insensitiveSAFE_TO_LOG_PROPERTIESand replaces ASCII control characters (< 0x20,0x7F) with?in logged property keys and allowlisted values.super.isLoggable(level)ahead of thread-local MDC lookup (~0.6 nsdisabled path) and preserves externally attached JUL handlers viaRootDriverLogger.APPEND, writesByteBuffers in 8 KiB slices, emits[LOG TRUNCATED: ...]markers on fallback truncation, removes redundant backup UID checks before atomicFiles.move, reports invalidmaxLogFileBytesonce, and installs a boundedDeduplicatingErrorManager.