Skip to content

chore(bqjdbc): log connection properties set by the user#13244

Open
Neenu1995 wants to merge 2 commits into
mainfrom
ns/add-config-logs
Open

chore(bqjdbc): log connection properties set by the user#13244
Neenu1995 wants to merge 2 commits into
mainfrom
ns/add-config-logs

Conversation

@Neenu1995
Copy link
Copy Markdown
Contributor

No description provided.

@Neenu1995 Neenu1995 requested review from a team as code owners May 20, 2026 20:03
Copy link
Copy Markdown
Contributor

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

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 adds logging for connection properties in BigQueryConnection, including a masking mechanism for sensitive fields, and updates DataSource to allow access to these properties. A new test case verifies this functionality. Feedback highlights a log level mismatch in the test, an incorrect assertion for PartnerToken formatting, and an opportunity to improve the readability of the masking logic by using a set of keywords.

public void testConnectionPropertiesLoggingAndMasking() throws IOException, SQLException {
java.util.logging.Logger rootLogger = BigQueryJdbcRootLogger.getRootLogger();
java.util.logging.Level originalLevel = rootLogger.getLevel();
rootLogger.setLevel(java.util.logging.Level.INFO);
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.

critical

The code in BigQueryConnection logs properties at java.util.logging.Level.CONFIG. For the log message to be captured, the logger's level must be set to CONFIG or a finer level (e.g., ALL). Setting it to INFO will prevent the message from being logged, as INFO (value 800) is a coarser level than CONFIG (value 700).

Suggested change
rootLogger.setLevel(java.util.logging.Level.INFO);
rootLogger.setLevel(java.util.logging.Level.CONFIG);

assertTrue(logMessage.contains("ProjectId=MyTestProjectId"));
assertTrue(logMessage.contains("Location=US"));
assertTrue(logMessage.contains("OAuthAccessToken=*****"));
assertTrue(logMessage.contains("PartnerToken= (GPN:secretPartnerToken)"));
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.

high

This assertion appears to be incorrect. Given the URL PartnerToken=GPN:secretPartnerToken, the DataSource constructor sets this.partnerToken to GPN:secretPartnerToken. Subsequently, createProperties() in DataSource constructs the property value as " (GPN:" + this.partnerToken + ")", which results in " (GPN:GPN:secretPartnerToken)". The log message will therefore contain PartnerToken= (GPN:GPN:secretPartnerToken). Please update the assertion to reflect the actual behavior.

Suggested change
assertTrue(logMessage.contains("PartnerToken= (GPN:secretPartnerToken)"));
assertTrue(logMessage.contains("PartnerToken= (GPN:GPN:secretPartnerToken)"));

Comment on lines +161 to +166
if ((lowerName.contains("key")
|| lowerName.contains("token")
|| lowerName.contains("password")
|| lowerName.contains("pwd")
|| lowerName.contains("secret"))
&& !lowerName.equals("partnertoken")) {
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.

medium

For better readability and maintainability, consider extracting the sensitive keywords into a Set and using a stream to check if the property name contains any of them. This makes the condition less verbose and easier to extend in the future.

For example, you could define a static set of keywords at the class level:

private static final java.util.Set<String> SENSITIVE_KEYWORDS = new java.util.HashSet<>(java.util.Arrays.asList("key", "token", "password", "pwd", "secret"));

And then use it in the condition like this:

if (SENSITIVE_KEYWORDS.stream().anyMatch(lowerName::contains)
    && !lowerName.equals("partnertoken")) {

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.

1 participant