- Notifications
You must be signed in to change notification settings - Fork126
[471] - Close underlying HTTP Client on closingConnection#674
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Open
Varun0157 wants to merge37 commits intodatabricks:mainChoose a base branch fromVarun0157:close-conn
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.
Uh oh!
There was an error while loading.Please reload this page.
Open
Changes fromall commits
Commits
Show all changes
37 commits Select commitHold shift + click to select a range
4437a2a Refactor codebase to use a unified http client
vikrantpuppala30c04a6 Some more fixes and aligned tests
vikrantpuppala4294600 Fix all tests
vikrantpuppala3155211 fmt
vikrantpuppala1143838 preliminary connection closure func
Varun015768cc822 unit test for backend closure
Varun0157ef1d9fd remove redundant comment
Varun01574bb2e4b assert SEA http client closure in unit tests
Varun0157734dd06 correct docstrng
Varun0157d00e3c8 fix e2e
vikrantpuppala000d3a3 fix unit
vikrantpuppalacba3da7 more fixes
vikrantpuppala2a1f719 more fixes
vikrantpuppala1dd40a1 review comments
vikrantpuppala3847aca fix warnings
vikrantpuppalad9a4797 fix check-types
vikrantpuppalaba2a3a9 remove separate http client for telemetry
vikrantpuppalad1f045e more clean up
vikrantpuppalaea3b0b0 Merge remote-tracking branch 'target/http-client-refactor-2' into clo…
Varun01574e66230 remove excess release_connection call
Varun0157bf0a2f6 Merge remote-tracking branch 'target/main' into close-conn
Varun015767020f1 formatting (black) - fix some closures
Varun0157496d7f7 Revert "formatting (black) - fix some closures"
Varun015784ec33a add more http_client closures
Varun015776ce5ce remove excess close call
Varun01574452725 wait for _flush before closing HTTP client
Varun0157d90ac80 make close() async
Varun01578ff6552 Merge remote-tracking branch 'target/main' into close-conn
Varun0157666fe62 Merge remote-tracking branch 'origin/main' into close-conn
Varun01571c88a01 Merge branch 'main' into close-conn
Varun0157f78456b Merge branch 'main' into close-conn
Varun0157b97ac03 Merge branch 'main' into close-conn
Varun0157c78bace simplify close_session (remove secondary _close_session invocation)
Varun0157bedfc06 simplify changes
Varun0157a36353b simplify diff
Varun015776fb623 simplify imports, log TelemetryClient closure
Varun015766192b4 simplify diff
Varun0157File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
5 changes: 4 additions & 1 deletionsrc/databricks/sql/auth/thrift_http_client.py
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
7 changes: 5 additions & 2 deletionssrc/databricks/sql/backend/sea/backend.py
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
2 changes: 1 addition & 1 deletionsrc/databricks/sql/backend/sea/utils/http_client.py
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
4 changes: 2 additions & 2 deletionssrc/databricks/sql/backend/thrift_backend.py
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
34 changes: 30 additions & 4 deletionssrc/databricks/sql/telemetry/telemetry_client.py
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 |
|---|---|---|
| @@ -2,8 +2,7 @@ | ||
| import time | ||
| import logging | ||
| import json | ||
| from concurrent.futures import ThreadPoolExecutor, wait | ||
| from datetime import datetime, timezone | ||
| from typing import List, Dict, Any, Optional, TYPE_CHECKING | ||
| from databricks.sql.telemetry.models.event import ( | ||
| @@ -182,6 +181,7 @@ def __init__( | ||
| self._user_agent = None | ||
| self._events_batch = [] | ||
| self._lock = threading.RLock() | ||
| self._pending_futures = set() | ||
| self._driver_connection_params = None | ||
| self._host_url = host_url | ||
| self._executor = executor | ||
| @@ -245,6 +245,9 @@ def _send_telemetry(self, events): | ||
| timeout=900, | ||
| ) | ||
| with self._lock: | ||
| self._pending_futures.add(future) | ||
| future.add_done_callback( | ||
| lambda fut: self._telemetry_request_callback(fut, sent_count=sent_count) | ||
| ) | ||
| @@ -303,6 +306,9 @@ def _telemetry_request_callback(self, future, sent_count: int): | ||
| except Exception as e: | ||
| logger.debug("Telemetry request failed with exception: %s", e) | ||
| finally: | ||
| with self._lock: | ||
| self._pending_futures.discard(future) | ||
| def _export_telemetry_log(self, **telemetry_event_kwargs): | ||
| """ | ||
| @@ -356,10 +362,30 @@ def export_latency_log(self, latency_ms, sql_execution_event, sql_statement_id): | ||
| ) | ||
| def close(self): | ||
| """Schedule client closure.""" | ||
| logger.debug( | ||
| "Scheduling closure for TelemetryClient of connection %s", | ||
| self._session_id_hex, | ||
| ) | ||
| self._executor.submit(self._close_and_wait) | ||
| def _close_and_wait(self): | ||
| """Flush remaining events and wait for them to complete before closing.""" | ||
| self._flush() | ||
| with self._lock: | ||
| pending_events = list(self._pending_futures) | ||
| if pending_events: | ||
| logger.debug( | ||
| "Waiting for %s pending telemetry requests to complete.", | ||
| len(pending_events), | ||
| ) | ||
| wait(pending_events) | ||
| logger.debug("Closing TelemetryClient for connection %s", self._session_id_hex) | ||
| self._http_client.close() | ||
Varun0157 marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| class TelemetryClientFactory: | ||
| """ | ||
1 change: 1 addition & 0 deletionstests/unit/test_sea_backend.py
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
9 changes: 8 additions & 1 deletiontests/unit/test_thrift_backend.py
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
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.