-
Notifications
You must be signed in to change notification settings - Fork 165
feat(csharp/src/Drivers/Databricks): Add comprehensive connection logging to Databricks ADBC driver #3577
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
Open
eric-wang-1990
wants to merge
7
commits into
apache:main
Choose a base branch
from
eric-wang-1990:add-databricks-connection-logging
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
feat(csharp/src/Drivers/Databricks): Add comprehensive connection logging to Databricks ADBC driver #3577
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
112e1d6
Add comprehensive connection logging to Databricks ADBC driver
eric-wang-1990 2ab73c8
Remove redundant logging fields
eric-wang-1990 21fb9f3
Fix activity logging to use single traced context
eric-wang-1990 8cd79e5
Change feature flags from events to tags for better logging
eric-wang-1990 8234f76
Merge branch 'main' of https://github.com/apache/arrow-adbc into add-…
eric-wang-1990 8df8b03
fix
eric-wang-1990 2987ce7
Refactor CreateSessionRequest to use TraceActivity instead of Activit…
eric-wang-1990 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
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
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 |
|---|---|---|
|
|
@@ -31,6 +31,7 @@ | |
| using Apache.Arrow.Adbc.Drivers.Apache.Spark; | ||
| using Apache.Arrow.Adbc.Drivers.Databricks.Auth; | ||
| using Apache.Arrow.Adbc.Drivers.Databricks.Reader; | ||
| using Apache.Arrow.Adbc.Tracing; | ||
| using Apache.Arrow.Ipc; | ||
| using Apache.Hive.Service.Rpc.Thrift; | ||
| using Thrift.Protocol; | ||
|
|
@@ -100,6 +101,28 @@ public DatabricksConnection(IReadOnlyDictionary<string, string> properties) : ba | |
| ValidateProperties(); | ||
| } | ||
|
|
||
| private void LogConnectionProperties(Activity? activity) | ||
| { | ||
| if (activity == null) return; | ||
|
|
||
| foreach (var kvp in Properties) | ||
| { | ||
| string key = kvp.Key; | ||
| string value = kvp.Value; | ||
|
|
||
| // Sanitize sensitive properties - only mask actual credentials/tokens, not configuration | ||
| bool isSensitive = key.IndexOf("password", StringComparison.OrdinalIgnoreCase) >= 0 || | ||
| key.IndexOf("secret", StringComparison.OrdinalIgnoreCase) >= 0 || | ||
| key.Equals(AdbcOptions.Password, StringComparison.OrdinalIgnoreCase) || | ||
| key.Equals(SparkParameters.AccessToken, StringComparison.OrdinalIgnoreCase) || | ||
| key.Equals(DatabricksParameters.OAuthClientSecret, StringComparison.OrdinalIgnoreCase); | ||
|
|
||
| string logValue = isSensitive ? "***" : value; | ||
|
|
||
| activity.SetTag(key, logValue); | ||
| } | ||
| } | ||
|
|
||
| public override IEnumerable<KeyValuePair<string, object?>>? GetActivitySourceTags(IReadOnlyDictionary<string, string> properties) | ||
| { | ||
| IEnumerable<KeyValuePair<string, object?>>? tags = base.GetActivitySourceTags(properties); | ||
|
|
@@ -696,58 +719,129 @@ public override AdbcStatement CreateStatement() | |
|
|
||
| protected override TOpenSessionReq CreateSessionRequest() | ||
| { | ||
| var req = new TOpenSessionReq | ||
| return this.TraceActivity(activity => | ||
| { | ||
| Client_protocol = TProtocolVersion.SPARK_CLI_SERVICE_PROTOCOL_V7, | ||
| Client_protocol_i64 = (long)TProtocolVersion.SPARK_CLI_SERVICE_PROTOCOL_V7, | ||
| CanUseMultipleCatalogs = _enableMultipleCatalogSupport, | ||
| }; | ||
| // Log driver information at the beginning of the connection | ||
| activity?.AddEvent("connection.driver.info", [ | ||
| new("driver.name", "Apache Arrow ADBC Databricks Driver"), | ||
| new("driver.version", s_assemblyVersion), | ||
| new("driver.assembly", s_assemblyName) | ||
| ]); | ||
|
|
||
| // Set default namespace if available | ||
| if (_defaultNamespace != null) | ||
| { | ||
| req.InitialNamespace = _defaultNamespace; | ||
| } | ||
| req.Configuration = new Dictionary<string, string>(); | ||
| // merge timestampConfig with serverSideProperties | ||
| foreach (var kvp in timestampConfig) | ||
| { | ||
| req.Configuration[kvp.Key] = kvp.Value; | ||
| } | ||
| // If not using queries to set server-side properties, include them in Configuration | ||
| if (!_applySSPWithQueries) | ||
| { | ||
| var serverSideProperties = GetServerSideProperties(); | ||
| foreach (var property in serverSideProperties) | ||
| // Log connection properties (sanitize sensitive values) | ||
| LogConnectionProperties(activity); | ||
|
|
||
| var req = new TOpenSessionReq | ||
| { | ||
| req.Configuration[property.Key] = property.Value; | ||
| Client_protocol = TProtocolVersion.SPARK_CLI_SERVICE_PROTOCOL_V7, | ||
| Client_protocol_i64 = (long)TProtocolVersion.SPARK_CLI_SERVICE_PROTOCOL_V7, | ||
| CanUseMultipleCatalogs = _enableMultipleCatalogSupport, | ||
| }; | ||
|
|
||
| // Log OpenSession request details | ||
| activity?.SetTag("connection.client_protocol", req.Client_protocol.ToString()); | ||
|
|
||
| // Set default namespace if available | ||
| if (_defaultNamespace != null) | ||
| { | ||
| req.InitialNamespace = _defaultNamespace; | ||
| activity?.SetTag("connection.initial_namespace.catalog", _defaultNamespace.CatalogName ?? "(none)"); | ||
| activity?.SetTag("connection.initial_namespace.schema", _defaultNamespace.SchemaName ?? "(none)"); | ||
| } | ||
| } | ||
| return req; | ||
| req.Configuration = new Dictionary<string, string>(); | ||
| // merge timestampConfig with serverSideProperties | ||
| foreach (var kvp in timestampConfig) | ||
| { | ||
| req.Configuration[kvp.Key] = kvp.Value; | ||
| } | ||
| // If not using queries to set server-side properties, include them in Configuration | ||
| if (!_applySSPWithQueries) | ||
| { | ||
| var serverSideProperties = GetServerSideProperties(); | ||
| foreach (var property in serverSideProperties) | ||
| { | ||
| req.Configuration[property.Key] = property.Value; | ||
| } | ||
| } | ||
|
|
||
| activity?.SetTag("connection.configuration_count", req.Configuration.Count); | ||
|
|
||
| return req; | ||
| }); | ||
| } | ||
|
|
||
| protected override async Task HandleOpenSessionResponse(TOpenSessionResp? session, Activity? activity = default) | ||
| { | ||
|
|
||
| await base.HandleOpenSessionResponse(session, activity); | ||
|
|
||
| if (session != null) | ||
| { | ||
| var version = session.ServerProtocolVersion; | ||
|
|
||
| // Log server protocol version | ||
| activity?.SetTag("connection.server_protocol_version", version.ToString()); | ||
|
|
||
| // Validate it's a Databricks server | ||
| if (!FeatureVersionNegotiator.IsDatabricksProtocolVersion(version)) | ||
| { | ||
| activity?.SetTag("error.type", "InvalidServerProtocol"); | ||
| activity?.SetTag("error.message", "Non-Databricks server detected"); | ||
| throw new DatabricksException("Attempted to use databricks driver with a non-databricks server"); | ||
| } | ||
| _enablePKFK = _enablePKFK && FeatureVersionNegotiator.SupportsPKFK(version); | ||
|
|
||
| // Log protocol version capabilities (what the server supports) | ||
| bool protocolSupportsPKFK = FeatureVersionNegotiator.SupportsPKFK(version); | ||
| bool protocolSupportsDescTableExtended = FeatureVersionNegotiator.SupportsDESCTableExtended(version); | ||
|
|
||
| activity?.SetTag("connection.protocol.supports_pk_fk", protocolSupportsPKFK); | ||
| activity?.SetTag("connection.protocol.supports_desc_table_extended", protocolSupportsDescTableExtended); | ||
|
|
||
| // Apply protocol constraints to user settings | ||
| bool pkfkBefore = _enablePKFK; | ||
| _enablePKFK = _enablePKFK && protocolSupportsPKFK; | ||
|
|
||
| if (pkfkBefore && !_enablePKFK) | ||
| { | ||
| activity?.SetTag("connection.feature_downgrade.pk_fk", true); | ||
| activity?.SetTag("connection.feature_downgrade.pk_fk.reason", "Protocol version does not support PK/FK"); | ||
| } | ||
|
|
||
| // Handle multiple catalog support from server response | ||
| _enableMultipleCatalogSupport = session.__isset.canUseMultipleCatalogs ? session.CanUseMultipleCatalogs : false; | ||
|
|
||
| // Log final feature flags as tags | ||
| activity?.SetTag("connection.feature.enable_pk_fk", _enablePKFK); | ||
| activity?.SetTag("connection.feature.enable_multiple_catalog_support", _enableMultipleCatalogSupport); | ||
| activity?.SetTag("connection.feature.enable_direct_results", _enableDirectResults); | ||
| activity?.SetTag("connection.feature.use_cloud_fetch", _useCloudFetch); | ||
| activity?.SetTag("connection.feature.use_desc_table_extended", _useDescTableExtended); | ||
| activity?.SetTag("connection.feature.enable_run_async_in_thrift_op", _runAsyncInThrift); | ||
|
|
||
| // Handle default namespace | ||
| if (session.__isset.initialNamespace) | ||
| { | ||
| _defaultNamespace = session.InitialNamespace; | ||
| activity?.AddEvent("connection.namespace.set_from_server", [ | ||
| new("catalog", _defaultNamespace.CatalogName ?? "(none)"), | ||
| new("schema", _defaultNamespace.SchemaName ?? "(none)") | ||
| ]); | ||
| } | ||
| else if (_defaultNamespace != null && !string.IsNullOrEmpty(_defaultNamespace.SchemaName)) | ||
| { | ||
| // catalog in namespace is introduced when SET CATALOG is introduced, so we don't need to fallback | ||
| // server version is too old. Explicitly set the schema using queries | ||
| activity?.AddEvent("connection.namespace.fallback_to_use_schema", [ | ||
| new("schema_name", _defaultNamespace.SchemaName), | ||
| new("reason", "Server does not support initialNamespace in OpenSessionResp") | ||
| ]); | ||
| await SetSchema(_defaultNamespace.SchemaName); | ||
| } | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: remove extra blank line |
||
| } | ||
| else | ||
| { | ||
| activity?.SetTag("error.type", "NullSessionResponse"); | ||
| } | ||
| } | ||
|
|
||
|
|
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: remove extra blank line