Repository navigation
Conversation
There was a problem hiding this comment.
Code Review
This pull request refactors connection property validation and normalization in the BigQuery JDBC driver. It introduces a structured validation phase that avoids flattening properties onto the JDBC URL, preserves inherited defaults, and handles custom OpenTelemetry instances. Additionally, DataSource is updated to use boxed Boolean fields to properly distinguish unset values, and configured fields are passed directly to the driver. The review feedback recommends improving the robustness of customOpenTelemetry validation by ensuring that invalid types are not silently ignored.
| * targetDataSource}, preserving typed {@link Map} values and explicit {@code false} flags without | ||
| * serializing back into a flat URL string. | ||
| */ | ||
| void applyConfiguredFieldsTo(DataSource targetDataSource) { |
There was a problem hiding this comment.
That looks very fragile.
How can we ensure that when new property is added, we update it?
(note that maybe it is ok to keep as-is for this stack, but refactor it later. Right now we have like 7 different lists that should be updated when we add new property. We should have single source of truth instead)
There was a problem hiding this comment.
Agreed that the hand-maintained lists are fragile. For this PR, the guardrail DataSourceTest#testSnapshotConfiguredFields_coversEveryNonUrlDataSourceField fails CI if a non-URL DataSource field is not copied. The root fix is a single declarative property registry that replaces the seven hand-maintained lists; I filed b/592620248 for that and am keeping it out of this stack to limit scope.
| String propertyValue, | ||
| Map<String, String> canonicalProperties, | ||
| List<String> unknownPropertyKeys) { | ||
| if (propertyValue == null || propertyValue.isEmpty()) { |
There was a problem hiding this comment.
Do we want to allow empty strings? What would be an example when empty string is valid value?
There was a problem hiding this comment.
Empty means unset here, intentionally. It matches the legacy appendPropertiesToURL behaviour, which skipped empty values, and BI tools commonly send "" for fields the user left blank, so keeping it avoids a behaviour change for Properties callers. You did point at a real inconsistency on the DataSource path: setLogLevel("") used to make the connection fail. As of 0618a55 the DataSource path also treats empty strings as unset, covered by DataSourceTest#testGetConnection_emptyStringSettersAreTreatedAsUnset.
…ns connect pipeline Stack: PR 2 of 3 (base: fix/g01-url-parsing-and-sanitization) Bug: b/584841439, b/584840529, b/584840728, b/584839495 - Replace DataSource.getConnection() createProperties/DriverManager URL round-trip with a defensive typed DataSource snapshot passed directly to BigQueryDriver.connectWithDataSource(). - Preserve all 15 previously dropped security bean fields, explicit false on boxed telemetry/OTel flags, unset enableDiagnosticTelemetry, and raw ImmutableMap queryProperties/labels. - Unify BigQueryDriver.connect() onto two-phase single-pass tokenization with last-wins precedence (Properties/DataSource > URL) for LogLevel, LogPath, enableGcpLogExporter, and EnableDiagnosticTelemetry. - Redact invalid-URL exceptions in DataSource.getConnection() and fix single-read URL TOCTOU.
…pt-out always wins
…ty and not an OpenTelemetry instance
…nd empty DataSource strings as unset Address review feedback on #15290: an EndpointOverrides or PrivateServiceConnectUris value from a DataSource setter or Properties now replaces both aliases from the URL, empty-string DataSource setters are treated as unset like empty Properties values, and invalid Properties keys are ignored with a warning via extractValidPropertyKey.
When one EndpointOverrides/PrivateServiceConnectUris alias is configured and the other is an empty string, copy the empty alias as null so it is not surfaced in diagnostic logs.
e5d9f1d to
91e68a2
Compare
Stack: PR 2 of 3 (base:
fix/g01-url-parsing-and-sanitization)Bug: b/584840728, b/584841439, b/584840529, b/584839379
Summary
Eliminates URL string round-tripping in
DataSource.getConnection()andBigQueryDriver.connect()by passing typedDataSourcefield snapshots and validatedPropertiesdirectly into a unified last-wins connect pipeline.What Changed & Why
DataSourcesnapshot & overlay (b/584841439,b/584840529):DataSource's three primitivebooleanOTel flags (enableGcpTraceExporter,enableGcpLogExporter,useGlobalOpenTelemetry) internally while preserving publicbooleangetter/setter API signatures, allowing explicitfalseoverrides to win over URL settings while leaving unset fieldsnull.DataSource.fromCanonicalProperties(),snapshotConfiguredFields(), andapplyConfiguredFieldsTo()covering every non-URL field (verified by a reflection parity test inDataSourceTest), fixing 15 previously dropped security bean properties (oAuthSAImpersonation*,privateServiceConnect,endpointOverrides,gcpTelemetry*,oAuthP12Password,byoid*) and preserving typedqueryProperties/labelsmaps containing,or=without sibling-key injection.DataSourcestrings are treated as unset, matching thePropertiespath (previouslysetLogLevel("")madegetConnection()fail).EndpointOverridesandPrivateServiceConnectUrisare aliases: a value for either, from aDataSourcesetter or fromProperties, replaces both, so a URL-supplied alias can never shadow it. An empty alias is copied as unset.DataSource.getConnection()URL TOCTOU via singlegetURL()read, redacts invalid-URL exception messages, and delegates directly toBigQueryDriver.connectWithDataSource().b/584840728,b/584839379):BigQueryDriver.ValidatedConnectionPropertiesandvalidateAndCanonicalizeProperties()with a defensiveProperties.clone()snapshot and deterministic two-passProperties(defaults)handling (inherited String defaults in Pass 1, direct child String/non-String/case-variant overrides in Pass 2). Invalid keys are skipped, and one warning that does not echo the key is logged once logging is active.resolvePreConnectProperty()enforcingDataSource>Properties> URL precedence for pre-connect ("bootstrap") logging properties (LogLevel,LogPath,enableGcpLogExporter), while ensuring an explicitEnableDiagnosticTelemetryopt-out (0/false) in any source always wins.BigQueryJdbcRuntimeException | IllegalArgumentExceptionthrown during URL/property parsing intoBigQueryJdbcException(SQLException) while leavingnew BigQueryConnection(...)outside that catch block (preservingITProxyBigQueryTest).How It Was Tested
JAVA_HOME=/usr/lib/jvm/java-21-openjdk-amd64 make lint— 0 reformatted.mvn -B -ntp clean test— Enforcer, Checkstyle (0 violations), Java 8animal-sniffer, and 1,485 unit tests (1 skipped, 0 errors; only the known pre-existing local failureBigQueryJdbcOAuthUtilityTest.testPrivateKeyFromP12Bytes).BigQueryDriverTest,DataSourceTest, andPooledConnectionDataSourceTestcoveringLogPathprecedence (DataSource>Properties> URL), telemetry opt-out-always-wins across all sources,Properties(defaults)overrides, ignored injection keys (warning does not echo the key), endpoint-override aliases (setter andProperties), empty-string setters treated as unset, every-field snapshot parity, delimiter-bearing maps,PartnerTokenoverlay parity, andIllegalArgumentExceptionwrapping.