Repository navigation
fix(bigquery-jdbc): harden Clearcut opt-out lifecycle and preserve DataSource URL opt-out - #15394
keshavdandeva wants to merge 5 commits into
Conversation
…yConfiguration.toBuilder()
There was a problem hiding this comment.
Code Review
This pull request updates the BigQuery JDBC telemetry system to support discarding pending metrics on close or opt-out without flushing. It introduces a discardPending flag in TelemetryBatcher, adds a toBuilder() method to TelemetryConfiguration, and refactors TelemetryManager for safer lifecycle and shutdown hook management. The review comments correctly point out that reassigning metricsMap to a new ConcurrentHashMap in TelemetryBatcher can cause thread-safety or compilation issues, and suggest using metricsMap.clear() instead.
| connectionProperties.setProperty( | ||
| BigQueryJdbcUrlUtility.ENABLE_DIAGNOSTIC_TELEMETRY_PROPERTY_NAME, | ||
| String.valueOf(getEnableDiagnosticTelemetry())); | ||
| if (this.enableDiagnosticTelemetry != null) { |
There was a problem hiding this comment.
Careful when merging with @Neenu1995 changes around datasource
| } | ||
|
|
||
| if (!result.isSuccess()) { | ||
| if (discardPending) { |
There was a problem hiding this comment.
This is unreachable? Line 255 should return
There was a problem hiding this comment.
Also reachable under concurrency: if close(false) fires while flush() is blocked inside transport.send(...) (including when executorService.shutdownNow() interrupts the in-flight send, causing !result.isSuccess()), discardPending flips to true after line 255. Re-checking here skips remergeFailedMetrics(snapMetrics) so discarded metrics aren't re-inserted into metricsMap after close(false) cleared it. Added an inline comment and a test for this path.
| accumulator.addToPayload(payloadBuilder); | ||
| } | ||
|
|
||
| if (discardPending) { |
There was a problem hiding this comment.
Actually this is also unreachable? Line 226
There was a problem hiding this comment.
Reachable under concurrency: close(false) does not acquire flushLock, so another thread can set discardPending = true after the background flush() thread passed line 226 while it is assembling the payload. Re-checking here aborts before transport.send(...) sends an outbound request. Added an inline comment clarifying this.
| private volatile boolean backoffActive; | ||
|
|
||
| private final AtomicBoolean isClosed = new AtomicBoolean(false); | ||
| private volatile boolean discardPending = false; |
There was a problem hiding this comment.
I'd suggest just passing it as argument since it is only 2 methods
There was a problem hiding this comment.
discardPending can't be a method argument because close(false) doesn't call flush() — flush() is already running asynchronously on the background jdbc-telemetry-batcher thread holding flushLock, while close(false) runs on a JDBC connecting thread without acquiring flushLock (so connect never blocks on an in-flight upload).
volatile boolean discardPending is the cross-thread cancellation signal from close(false) to an in-flight flush(). Added comments explaining this and a concurrency unit test
| * Stops background flushing. When {@code flush} is {@code false}, buffered metrics are discarded | ||
| * immediately without attempting an outbound upload for queued events. | ||
| */ | ||
| void close(boolean flush) { |
There was a problem hiding this comment.
When do we call it with false?
There was a problem hiding this comment.
It's called via TelemetryManager.closeQuietly(manager, false) in three places:
TelemetryManager.disableGlobally(...)— opt-out in this PR, custom universe/endpoint suppression in fix(bigquery-jdbc): suppress Clearcut diagnostic telemetry for custom universes and endpoint overrides #15395, and conflicting transport profiles in fix(bigquery-jdbc): propagate proxy and SSL TrustStore settings to Clearcut transport #15396 (must discard buffered metrics without uploading to play.googleapis.com or blocking connect for up to 2 s).- Closing a losing race candidate in
TelemetryManager.getInstance(...) - Test teardown
(TelemetryTestUtils.reset()).
Updated the close(boolean flush) Javadoc to call this out explicitly.
… add in-flight close(false) test
Summary
Hardens Clearcut diagnostic telemetry lifecycle and opt-out teardown in
java-bigquery-jdbcso opting out drops buffered metrics without blocking on an outbound upload, and fixesDataSourceclobbering URL-levelEnableDiagnosticTelemetry=0settings.Key changes
TelemetryBatcher.close(boolean flush)and adiscardPendingcheck underflushLockbeforetransport.send()and failed-flush requeueing soclose(false)discards queued metrics immediately without initiating a flush.TelemetryManagerto runDriverEnvironmentDetector.build()and teardown (closeQuietly) outsidesynchronized (TelemetryManager.class), log global disable once atLevel.FINE, honorBIGQUERY_JDBC_TELEMETRY_ENABLEDongetInstance(), and register the JVM shutdown hook at most once viaAtomicBoolean.TelemetryConfiguration.toBuilder(): AddedtoBuilder()so preliminary opt-out evaluation can be extended withDriverEnvironmentwithout re-reading configuration sources.DataSourceopt-out preservation: GuardedEnableDiagnosticTelemetryserialization inDataSource.createProperties()withif (this.enableDiagnosticTelemetry != null)so an unsetDataSourcedoes not emitEnableDiagnosticTelemetry=trueand overrideEnableDiagnosticTelemetry=0in the connection URL.TelemetryBatcher.close(false),TelemetryConfiguration.toBuilder(), non-flushing opt-out teardown, system-property opt-out ongetInstance(), andDataSourceURL opt-out preservation.Decisions made
close(false)discards queued batches and shuts down the batcher executor immediately.DataSourcefix scoped toenableDiagnosticTelemetry:DataSource.enableDiagnosticTelemetrywas already a nullableBoolean, butcreateProperties()unconditionally calledgetEnableDiagnosticTelemetry()(which defaults totrue). Guarding on the raw field fixes URL opt-out precedence without expanding scope to unrelatedDataSourceproperties.