-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat(bqjdbc): Per connection logs - Add BigQueryJdbcMdc #12748
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
69 commits
Select commit
Hold shift + click to select a range
4532736
feat(bqjdbc): Per connection logs - Add BigQueryJdbcMdc
Neenu1995 c3b9b7e
ensure garbage collection
Neenu1995 8b21ea5
add logs to gitignore
Neenu1995 0dc67a5
lint
Neenu1995 a0c2548
fix(java-spanner): use the existing dependency versions (#12746)
suztomo 313bf21
chore: Add AION SDK as code owners for the auth library (#12750)
lqiu96 a8d88fd
build(sdk-platform-java): Add formatter plugin to the root pom of sdk…
blakeli0 5cb57d3
fix(hermetic-build): prevent overwrite of Version.java in new librari…
diegomarquezp 2bf9235
ci: fix sdk-platform-java-ci syntax (#12753)
chingor13 8a32f81
fix(o11y): composite tracer to process url changes (#12754)
diegomarquezp da5c69e
chore: untangling auth library parent and imported BOM (#12737)
suztomo da00518
fix(gax): reduce visibility of ApiTracerContext methods (#12738)
blakeli0 1f65fa5
build: use local clone for release-please (#12757)
chingor13 f5027f7
chore: Add a library generation skill (#12689)
lqiu96 8d239f6
fix: normalize indentation in owlbot yamls for new libraries (#12759)
diegomarquezp 8d30e20
chore: Update gapic-generator-java version in WORKSPACE (#12761)
blakeli0 136d81e
chore(main): release 1.84.0-SNAPSHOT (#12760)
chingor13 8096f53
chore(bq jdbc): change uber jar bundling rules (#12195)
logachev 3b153be
chore(main): release 1.84.0 (#12764)
diegomarquezp c5a2b4b
ci: Remove extra compile job (#12763)
lqiu96 bb67aac
chore: Fix iam policy downgrade (#12767)
blakeli0 d8383c9
fix(auth): Address ClientSideCredentialAccessBoundary RefreshTask rac…
vverman 4fc7d43
ci: GraalVM CI uses existing Truststore if configured (#1914)
lqiu96 8cb8e52
test: Fix sonatype complaints in the tests (#1870)
lqiu96 d16b5b6
fix(gdch): support EC private keys (#1896)
diegomarquezp 0e0fcc3
chore: Refactor x509Provider to create a shared Utils class for Mtls …
vverman ebbe428
chore: Add licence with year for old TestEnvironmentProvider class
lqiu96 f76308d
chore: Remove the new .kokoro/build.sh file added from split repo
lqiu96 dcc8d51
chore(bigquery): remove dev gate flag and beta api for tracing teleme…
ldetmer 2801400
feat: [appoptimize] new module for appoptimize (#12768)
cloud-java-bot be752b8
fix(bqjdbc): lazily instantiate Statement in BigQueryDatabaseMetaData…
Neenu1995 d4582b4
chore: Fix GDCH tests referencing obsolete GDCH audience methods (#12…
lqiu96 c69253a
chore: Update generation configuration at Fri Apr 10 03:01:18 UTC 202…
cloud-java-bot bd8f287
chore(o11y): remove beta api from observability classes (#12747)
blakeli0 e1107af
ci: trigger sdk-platform-java CI on google-auth-library-java changes …
blakeli0 bdec6a4
build(deps): upgrade grpc-gcp to 1.10.0 (#12772)
blakeli0 f3ab101
fix: update appoptimize version to 0.0.1 to match released repo (#12782)
diegomarquezp 4933999
chore(main): release 1.85.0-SNAPSHOT (#12786)
diegomarquezp 042ec53
ci: replace java-logging with java-pubsub in downstream check (#12783)
blakeli0 58eec3a
ci: remove redundant sdk-platform-java from split-units (#12784)
blakeli0 966e8a4
chore(main): release 1.85.0 (#12788)
diegomarquezp 60c8240
ci: trigger split repo tests on auth, gax, and shared-deps changes (#…
lqiu96 ab9ff2d
fix(bqjdbc): Revert DatabaseMetaData field to be non-static in BigQue…
Neenu1995 e7cffc1
chore(deps): update upper bound dependencies file (#12706)
renovate-bot 344b82d
fix: correct build directory paths in graalvm cloudbuild.yaml (#12794)
diegomarquezp 6518bba
ci: skip bulk tests for isolated handwritten library changes (#12793)
lqiu96 9b87f57
fix(datastore): Create a plaintext gRPC transport channel when using …
mw-ship-it db25973
test(bigquery): Fix flaky ITBigQueryTest#testOpenTelemetryTracingQuer…
jinseopkim0 123b4e4
chore(main): release 1.86.0-SNAPSHOT (#12799)
diegomarquezp ff5ff19
Revert "chore(main): release 1.86.0-SNAPSHOT" (#12800)
diegomarquezp df9be2d
chore: Update generation configuration at Tue Apr 14 03:00:42 UTC 202…
cloud-java-bot bad2432
build(appoptimize): fix owlbot.py format (#12802)
chingor13 e659646
fix: bump vectorsearch to 0.13.0 for partial release (#12805)
diegomarquezp 722f19f
chore: Add a Java development skill for the monorepo (#12797)
lqiu96 2fdb96b
ci: fix library generation presubmit (#12803)
chingor13 bf54672
ci: restore sdk-platform-java jobs (#12813)
diegomarquezp fe87622
build: create additional tags on release (#12811)
chingor13 d0a1e91
ci: fix unmanaged_dependency_check module install (#12812)
chingor13 eca5736
chore: rm template from issue_tracker in config and repometadata (#12…
zhumin8 abc4259
build: use local google-auth-library in bazel tests (#12814)
chingor13 178953f
chore: downgrade gapic-libraries-bom to 1.85.0 (#12808)
blakeli0 058b80e
test(spanner): add a mock server test using key-aware routing (#12755)
olavloite ce1a8f7
perf(spanner): use StringBuilder for generating RequestId (#12809)
olavloite 6135fe9
chore: replace non-ASCII characters in api_description (#12795)
zhumin8 0e1e919
ci: stop using Google's Maven mirror in downstream checks (#12826)
suztomo aaffa52
change date formatter to DateTimeFormatter
Neenu1995 40edd07
make id generation cleaner
Neenu1995 79a5f8b
Merge branch 'main' into ns/mdc-per-conn-logs
Neenu1995 f206b77
clean up connection class
Neenu1995 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
97 changes: 97 additions & 0 deletions
97
...gle-cloud-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryJdbcMdc.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| /* | ||
| * Copyright 2026 Google LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package com.google.cloud.bigquery.jdbc; | ||
|
|
||
| import java.util.concurrent.ConcurrentHashMap; | ||
| import java.util.concurrent.atomic.AtomicLong; | ||
|
|
||
| /** | ||
| * Lightweight MDC implementation for the BigQuery JDBC driver using InheritableThreadLocal. | ||
| * Allocates a dedicated, independent InheritableThreadLocal object per concrete BigQueryConnection | ||
| * instance. | ||
| */ | ||
| public class BigQueryJdbcMdc { | ||
| private static final AtomicLong nextId = new AtomicLong(1); | ||
| private static final ConcurrentHashMap<BigQueryConnection, InheritableThreadLocal<String>> | ||
| instanceLocals = new ConcurrentHashMap<>(); | ||
| private static final ConcurrentHashMap<BigQueryConnection, String> instanceIds = | ||
| new ConcurrentHashMap<>(); | ||
|
|
||
| /** Allocates an exclusive InheritableThreadLocal and registers the connection mapping. */ | ||
| private static final InheritableThreadLocal<String> currentConnectionId = | ||
| new InheritableThreadLocal<>(); | ||
|
|
||
| public static void registerInstance(BigQueryConnection connection, String id) { | ||
| if (connection != null) { | ||
| String cleanId = | ||
| instanceIds.computeIfAbsent( | ||
| connection, | ||
| k -> { | ||
| String suffix = | ||
| (id != null && !id.isEmpty()) ? id : String.valueOf(nextId.getAndIncrement()); | ||
| return "JdbcConnection-" + suffix; | ||
| }); | ||
|
|
||
| currentConnectionId.set(cleanId); | ||
| InheritableThreadLocal<String> threadLocal = | ||
| instanceLocals.computeIfAbsent(connection, k -> new InheritableThreadLocal<>()); | ||
|
Neenu1995 marked this conversation as resolved.
|
||
| threadLocal.set(cleanId); | ||
| } | ||
| } | ||
|
|
||
| /** Retrieves the connection ID mapped to a specific BigQueryConnection instance. */ | ||
| public static String getConnectionId(BigQueryConnection connection) { | ||
|
Neenu1995 marked this conversation as resolved.
|
||
| if (connection != null) { | ||
| InheritableThreadLocal<String> local = instanceLocals.get(connection); | ||
| if (local != null) { | ||
| String val = local.get(); | ||
| if (val != null) { | ||
| return val; | ||
| } | ||
| } | ||
| return instanceIds.get(connection); | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| /** | ||
| * Returns the connection ID carried by any registered active connection on the current thread. | ||
| */ | ||
| public static String getConnectionId() { | ||
| return currentConnectionId.get(); | ||
| } | ||
|
|
||
| /** Clears the connection ID context from all active connection contexts on the current thread. */ | ||
| public static void removeInstance(BigQueryConnection connection) { | ||
| if (connection != null) { | ||
| InheritableThreadLocal<String> local = instanceLocals.remove(connection); | ||
| if (local != null) { | ||
| local.remove(); | ||
| } | ||
| instanceIds.remove(connection); | ||
| } | ||
| } | ||
|
Neenu1995 marked this conversation as resolved.
|
||
|
|
||
| public static void clear() { | ||
| currentConnectionId.remove(); | ||
| for (InheritableThreadLocal<String> local : instanceLocals.values()) { | ||
| local.remove(); | ||
| } | ||
| instanceLocals.clear(); | ||
| instanceIds.clear(); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
...cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryJdbcMdcTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| /* | ||
| * Copyright 2026 Google LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package com.google.cloud.bigquery.jdbc; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertNull; | ||
|
|
||
| import org.junit.jupiter.api.AfterEach; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.mockito.Mockito; | ||
|
|
||
| public class BigQueryJdbcMdcTest { | ||
|
|
||
| private BigQueryConnection mockConnection1; | ||
| private BigQueryConnection mockConnection2; | ||
|
|
||
| @BeforeEach | ||
| public void setUp() { | ||
| mockConnection1 = Mockito.mock(BigQueryConnection.class); | ||
| mockConnection2 = Mockito.mock(BigQueryConnection.class); | ||
| } | ||
|
|
||
| @AfterEach | ||
| public void tearDown() { | ||
| BigQueryJdbcMdc.clear(); | ||
| } | ||
|
|
||
| @Test | ||
| public void testRegisterAndRetrieveConnectionId() { | ||
| BigQueryJdbcMdc.registerInstance(mockConnection1, "123"); | ||
|
|
||
| assertEquals("JdbcConnection-123", BigQueryJdbcMdc.getConnectionId(mockConnection1)); | ||
| assertEquals("JdbcConnection-123", BigQueryJdbcMdc.getConnectionId()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testClearContext() { | ||
| BigQueryJdbcMdc.registerInstance(mockConnection1, "456"); | ||
| assertEquals("JdbcConnection-456", BigQueryJdbcMdc.getConnectionId(mockConnection1)); | ||
|
|
||
| BigQueryJdbcMdc.clear(); | ||
|
|
||
| assertNull(BigQueryJdbcMdc.getConnectionId()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testMultipleConnectionsSameThread() { | ||
| BigQueryJdbcMdc.registerInstance(mockConnection1, "111"); | ||
| BigQueryJdbcMdc.registerInstance(mockConnection2, "222"); | ||
|
|
||
| assertEquals("JdbcConnection-111", BigQueryJdbcMdc.getConnectionId(mockConnection1)); | ||
| assertEquals("JdbcConnection-222", BigQueryJdbcMdc.getConnectionId(mockConnection2)); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.