-
Notifications
You must be signed in to change notification settings - Fork 165
feat(csharp/src/Drivers/Databricks): Implement Telemetry Reporting for Databricks #3191
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
jeremytang-db
wants to merge
22
commits into
apache:main
Choose a base branch
from
jeremytang-db:main
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
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
fe9b88e
test
jeremytang-db c3626de
Merge branch 'main' of github.com:jeremytang-db/arrow-adbc
jeremytang-db b91fd41
fix merge
jeremytang-db ec0f4df
more fix
jeremytang-db fc75eaf
in progress
jeremytang-db e5064af
review
jeremytang-db 82814f8
fix field name
jeremytang-db 4e654fb
move things
jeremytang-db 8fc65eb
fix small errors
jeremytang-db a300733
add
jeremytang-db 487ecfc
update
jeremytang-db 77a69f0
Merge branch 'apache:main' into main
jeremytang-db 493e3b8
update
jeremytang-db d56635e
add guid for update
jeremytang-db 1780b29
update
jeremytang-db 42a4cd2
Merge branch 'main' of https://github.com/apache/arrow-adbc
jeremytang-db a8fc364
fix
jeremytang-db 3a9f96c
update
jeremytang-db bea91e3
update
jeremytang-db b1c4ccf
update
jeremytang-db 32baf42
update
jeremytang-db 8e068d5
Merge branch 'main' into main
jeremytang-db 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
68 changes: 68 additions & 0 deletions
68
csharp/src/Drivers/Databricks/Telemetry/DatabricksActivityListener.cs
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,68 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
|
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. please add a readme file in this folder, on how is the file generated. |
||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You 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. | ||
| */ | ||
|
|
||
| using System; | ||
| using System.Diagnostics; | ||
| using System.IO; | ||
| using System.Linq; | ||
| using Apache.Arrow.Adbc.Tracing; | ||
| using Apache.Arrow.Adbc.Drivers.Apache; | ||
| using Apache.Arrow.Adbc.Drivers.Databricks.Telemetry.Model; | ||
| using Apache.Arrow.Adbc.Drivers.Databricks.Telemetry.Enums; | ||
|
|
||
| namespace Apache.Arrow.Adbc.Drivers.Databricks.Telemetry | ||
| { | ||
| internal class DatabricksActivityListener : IDisposable | ||
| { | ||
| private readonly ActivityListener _activityListener; | ||
| private TelemetryHelper? _telemetryHelper; | ||
|
|
||
jeremytang-db marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| public DatabricksActivityListener(TelemetryHelper? telemetryHelper, string sourceName, Guid guid) | ||
| { | ||
| this._telemetryHelper = telemetryHelper; | ||
| this._activityListener = new ActivityListener | ||
| { | ||
| ShouldListenTo = (activitySource) => activitySource.Tags?.Any(kvp => kvp.Key == Util.GetDatabricksTag() && kvp.Value?.Equals(guid) == true) == true, | ||
| Sample = (ref ActivityCreationOptions<ActivityContext> _) => ActivitySamplingResult.AllData, | ||
| ActivityStopped = OnActivityStopped, | ||
| }; | ||
| ActivitySource.AddActivityListener(_activityListener); | ||
| } | ||
|
|
||
| private void OnActivityStopped(Activity activity) | ||
| { | ||
| if(_telemetryHelper == null) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| if(activity.OperationName?.EndsWith("ExecuteStatementAsync") == true) | ||
| { | ||
| var sqlExecutionEvent = new SqlExecutionEvent(); | ||
| var operationDetail = new OperationDetail(); | ||
| operationDetail.OperationType = OperationType.EXECUTE_STATEMENT_ASYNC; | ||
| sqlExecutionEvent.OperationDetail = operationDetail; | ||
| _telemetryHelper.AddSqlExecutionEvent(sqlExecutionEvent, Convert.ToInt64(activity.Duration.TotalMilliseconds)); | ||
| } | ||
| } | ||
|
|
||
| public void Dispose() | ||
| { | ||
| this._activityListener.Dispose(); | ||
| } | ||
| } | ||
| } | ||
24 changes: 24 additions & 0 deletions
24
csharp/src/Drivers/Databricks/Telemetry/DatabricksConnectionConfig.cs
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,24 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You 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. | ||
| */ | ||
|
|
||
| namespace Apache.Arrow.Adbc.Drivers.Databricks.Telemetry; | ||
|
|
||
| internal class DatabricksConnectionConfig | ||
| { | ||
| public static readonly int MAX_BATCH_SIZE = 200; | ||
| public static readonly int FLUSH_INTERVAL_MILLIS = 300000; // 5 minutes | ||
| } |
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,7 @@ | ||
| # Databricks Telemetry | ||
|
|
||
| Uses `DatabricksActivityListener.cs` to listen and record events to `TelemetryHelper.cs` using ActivityListener. | ||
|
|
||
| `TelemetryHelper.cs` stores telemetry logs and telemetry parameters. | ||
|
|
||
| `TelemtryClient.cs` sends logs to `/telemetry` or `/telemetry-unauth` depending on authentication level. |
83 changes: 83 additions & 0 deletions
83
csharp/src/Drivers/Databricks/Telemetry/TelemetryClient.cs
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,83 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You 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. | ||
| */ | ||
|
|
||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Net.Http; | ||
| using System.Net.Http.Headers; | ||
| using System.Text.Json; | ||
| using System.Threading.Tasks; | ||
| using Apache.Arrow.Adbc.Drivers.Databricks.Telemetry.Model; | ||
|
|
||
| namespace Apache.Arrow.Adbc.Drivers.Databricks.Telemetry | ||
| { | ||
| internal class TelemetryClient | ||
| { | ||
| private readonly HttpClient _httpClient; | ||
| private readonly string? _telemetryUrl; | ||
| private readonly string? _accessToken; | ||
|
|
||
| public TelemetryClient(HttpClient httpClient, string? hostUrl, string? accessToken) | ||
| { | ||
| _httpClient = httpClient; | ||
| _accessToken = accessToken; | ||
| _telemetryUrl = !string.IsNullOrEmpty(hostUrl) ? accessToken != null ? $"https://{hostUrl}/telemetry-ext" : $"https://{hostUrl}/telemetry-unauth" : null; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Sends a batch of telemetry events asynchronously | ||
| /// </summary> | ||
| /// <param name="telemetryBatch">List of telemetry events to send</param> | ||
| /// <returns>Task representing the async operation</returns> | ||
| public async Task<bool> SendTelemetryBatchAsync(List<TelemetryFrontendLog> telemetryBatch) | ||
| { | ||
| if (string.IsNullOrEmpty(_telemetryUrl) || telemetryBatch.Count == 0) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| try | ||
| { | ||
| var request = new HttpRequestMessage(HttpMethod.Post, _telemetryUrl); | ||
|
|
||
| // Serialize the batch to JSON | ||
| var telemetryRequest = new TelemetryRequest(); | ||
| telemetryRequest.UploadTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(); | ||
| telemetryRequest.ProtoLogs = telemetryBatch.Select(x => JsonSerializer.Serialize(x)).ToList(); | ||
| request.Content = new StringContent(JsonSerializer.Serialize(telemetryRequest)); | ||
|
|
||
| // Set headers | ||
| request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); | ||
| request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); | ||
| if(_accessToken != null) | ||
| { | ||
| request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", _accessToken); | ||
| } | ||
|
|
||
| var response = await _httpClient.SendAsync(request); | ||
| return response.IsSuccessStatusCode; | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| // Log the exception but don't throw to prevent telemetry failures from affecting main functionality | ||
| System.Diagnostics.Debug.WriteLine($"Failed to send telemetry: {ex.Message}"); | ||
| return false; | ||
| } | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
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.