-
Notifications
You must be signed in to change notification settings - Fork 14k
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
feat: shorter timeout on test_connection #18001
Conversation
Codecov Report
@@ Coverage Diff @@
## master #18001 +/- ##
==========================================
- Coverage 67.07% 66.12% -0.95%
==========================================
Files 1609 1569 -40
Lines 64903 61641 -3262
Branches 6866 6233 -633
==========================================
- Hits 43535 40762 -2773
+ Misses 19502 19280 -222
+ Partials 1866 1599 -267
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
@betodealmeida out of interest in a slow ping problematic? I gather adding and thus testings a database connection—except if it is used for offline monitoring—is somewhat of a rare event. Additionally are there specific database engines which may take minutes to ping? Asking to learn as the default SQLAlchemy ping is merely a |
We saw a lot of errors when people are trying to setup their databases, with a lot of people simply giving up. Because of that we're trying to make the process less error-prone, or at least quicker.
When the DB connects successfully the ping is fast. The problem is that if the URL is incorrect it might take a long time for the test to fail, which only happens when the Superset <--> DB connection times out. If it takes more than 30 seconds to run |
* feat: shorter timeout on test_connection * pip-compile-multi --no-upgrade * Fix for SQLite * Return 408 * Add test
* feat: shorter timeout on test_connection * pip-compile-multi --no-upgrade * Fix for SQLite * Return 408 * Add test
SUMMARY
When we run
test_connection
when adding a database, the response might error only after 1-2 minutes, depending on the parameters. The error comes back only when the network connection from the driver times out, and because this requests runs in a separate thread and in a 3rd party library we can't adjust that timeout.We have a
@timeout
context manager in our code base, but they don't work here because SQLAlchemy runs theping
command in a separate thread. To enforce a shorter timeout onping
I used the func_timeout library, which spins off and monitors its own thread where the target function runs.I also improved the error message (see screenshots below), and added logic to disable the "test connection" button while the test is in flight. In my initial attempt I added a spinner, but because the main thread is occupied while the test is in flight the spinner doesn't spin.
BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
Before, note that an invalid connection to
druid://google.com:8082/druid/v2/sql/
times out only after ~90 seconds:After, with
TEST_DATABASE_CONNECTION_TIMEOUT
set to 2 seconds just for testing:TESTING INSTRUCTIONS
ADDITIONAL INFORMATION