Skip to content

Add UserAgent for connector service calls - #1175

Merged
gopalldb merged 8 commits into
databricks:mainfrom
gopalldb:sea-roll
Jan 12, 2026
Merged

gopalldb merged 8 commits into
databricks:mainfrom
gopalldb:sea-roll

Conversation

@gopalldb

@gopalldb gopalldb commented Jan 9, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

Custom user agent from useragententry parameter wasn't included in connector service HTTP requests for feature flag retrieval.

Root Cause

Method execution order issue in UserAgentManager.setUserAgent() - custom user agent was set AFTER the connector service request was made.

Solution

Reordered the method to set custom user agent before calling getClientUserAgent() (which triggers feature flag fetch).

Testing

  • Added testCustomUserAgentIncludedBeforeClientTypeEvaluation() test

NO_CHANGELOG=true

Problem:
The custom user agent from 'useragententry' parameter was not included
in the connector service feature flags request. This happened because
UserAgentManager.setUserAgent() was setting the custom user agent AFTER
triggering the client type determination (which fetches feature flags).

Root Cause:
In UserAgentManager.setUserAgent():
- Line 28 called getClientUserAgent() which triggered getClientType()
- getClientType() called DatabricksDriverFeatureFlagsContextFactory.getInstance()
- Feature flags were fetched WITHOUT the custom user agent
- Custom user agent was set afterwards (too late)

Solution:
Reordered UserAgentManager.setUserAgent() to set custom user agent
BEFORE calling getClientUserAgent():
1. Set base product
2. Set custom user agent FIRST via UserAgent.withOtherInfo()
3. THEN call getClientUserAgent() which triggers feature flags fetch

Result:
Custom user agent is now included in ALL HTTP requests including
the connector service request.

Testing:
- Added testCustomUserAgentIncludedBeforeClientTypeEvaluation() test
- Updated existing tests to be version-agnostic
- All UserAgentManagerTest tests pass

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
- Added buildUserAgentForConnectorService() to build separate UA for connector service
- Modified DatabricksDriverFeatureFlagsContext to use new method for feature flag requests
- Maintains proper order for backend requests: base -> client type -> custom
- Custom UA now included in both connector service and backend requests without circular dependency
- Updated test to verify proper order: client type before custom user agent
- Added DEBUG log when SEA circuit breaker is open
- Shows time remaining until circuit closes
- Helps users understand THRIFT fallback due to 429 rate limits
- Created parseCustomerUserAgent() helper method
- Eliminates code duplication in setUserAgent() and buildUserAgentForConnectorService()
- Added try-catch protection for UserAgent.sanitize() calls
- All tests pass (7/7)
@gopalldb gopalldb changed the title Sea roll Add UserAgent for connector service calls Jan 9, 2026
@gopalldb
gopalldb requested a review from samikshya-db January 9, 2026 10:58

@jprakash-db jprakash-db left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall LGTM. Some minor comments

// Set custom User-Agent for connector service (includes custom user agent without client
// type)
String userAgent =
com.databricks.jdbc.common.util.UserAgentManager.buildUserAgentForConnectorService(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can directly import the function and then use

import com.databricks.jdbc.common.util.UserAgentManager.buildUserAgentForConnectorService

Then use - buildUserAgentForConnectorService

return new String[] {customerName, customerVersion};
} catch (Exception e) {
LOGGER.debug("Failed to parse customer userAgent entry {}, Error {}", customerUserAgent, e);
return null;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of null, can we give a generic name. So we can later using telemetry identity how many requests are coming from incorrect User Agent arguments

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We read from other signals in those scenario. This is a private function, and null is used to denote that value is not provided by customer or partner

if (parsed != null) {
try {
userAgent.append(" ").append(parsed[0]).append("/").append(UserAgent.sanitize(parsed[1]));
} catch (Exception e) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can these Exception be more specific? I think It should be some String exception

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Changed catch blocks to catch IllegalArgumentException instead of generic
Exception when calling UserAgent.sanitize(). This is the specific exception
thrown by sanitize() when it encounters invalid characters in user agent strings.

Addresses PR review comment.
@gopalldb
gopalldb enabled auto-merge (squash) January 12, 2026 05:41
@gopalldb
gopalldb merged commit 21e07bd into databricks:main Jan 12, 2026
12 of 13 checks passed
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.

3 participants