-
Notifications
You must be signed in to change notification settings - Fork 154
Introduce retries to databricks psql command
#3492
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
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
6467a9d
introduce retries to `databricks psql` command
anton-107 d6e0008
add acceptance tests for retries in `databricks psql` command
anton-107 72fb5ae
update NEXT_CHANGELOG.md
anton-107 4912b2b
refactor: remove the `Enabled` field
anton-107 66d52d5
refactor: remove the `isRetryableConnectionError` method
anton-107 7dbc8ba
add a comment on retryable errors and why we are not using the SDK fo…
anton-107 d9cbf89
refactor: remove constants with defaults; remove superfluous unit test
anton-107 b2c8140
refactor: RetryConfig is a struct, not a pointer
anton-107 1bebd21
rename `tryPsqlInteractive` to `attemptConnection`
anton-107 e877c45
minor refactoring
anton-107 a00df4e
make lint
anton-107 3ea4328
fix off-by-one error with custom number of retries
anton-107 9a8a495
Merge branch 'main' into anton-107/psql-retries
anton-107 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 |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| #!/bin/bash | ||
| # | ||
| # This script prints its arguments and exits. | ||
| # The test script renames this script to "psql" in order to capture the arguments that the CLI passes to psql command. | ||
| # | ||
| echo "Simulating connection failure with exit code '2'" | ||
| exit 2 |
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,8 @@ | ||
| Local = true | ||
| Cloud = false | ||
|
|
||
| [GOOS] | ||
| windows = false | ||
|
|
||
| [EnvMatrix] | ||
| DATABRICKS_CLI_DEPLOYMENT = ["terraform", "direct-exp"] |
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,61 @@ | ||
|
|
||
| === Command should use default number of retries: | ||
| >>> musterr [CLI] psql my-database -- --dbname=db1 -p 3000 | ||
| Connecting to Databricks Database Instance my-database ... | ||
| Postgres version: 14 | ||
| Database instance status: AVAILABLE | ||
| Successfully fetched database credentials | ||
| Launching psql session to my-database.my-host.com (attempt 1/3)... | ||
| Simulating connection failure with exit code '2' | ||
| Connection failed with retryable error: connection failed (retryable): psql exited with code 2 | ||
| Connection attempt 1/3 failed, retrying in 1s... | ||
| Launching psql session to my-database.my-host.com (attempt 2/3)... | ||
| Simulating connection failure with exit code '2' | ||
| Connection failed with retryable error: connection failed (retryable): psql exited with code 2 | ||
| Connection attempt 2/3 failed, retrying in 2s... | ||
| Launching psql session to my-database.my-host.com (attempt 3/3)... | ||
| Simulating connection failure with exit code '2' | ||
| Connection failed with retryable error: connection failed (retryable): psql exited with code 2 | ||
| Error: failed to connect after 3 attempts, last error: connection failed (retryable): psql exited with code 2 | ||
|
|
||
| Exit code (musterr): 1 | ||
|
|
||
| === Command should use custom number of retries: | ||
| >>> musterr [CLI] psql my-database --max-retries 5 -- --dbname=db1 -p 3000 | ||
| Connecting to Databricks Database Instance my-database ... | ||
| Postgres version: 14 | ||
| Database instance status: AVAILABLE | ||
| Successfully fetched database credentials | ||
| Launching psql session to my-database.my-host.com (attempt 1/5)... | ||
| Simulating connection failure with exit code '2' | ||
| Connection failed with retryable error: connection failed (retryable): psql exited with code 2 | ||
| Connection attempt 1/5 failed, retrying in 1s... | ||
| Launching psql session to my-database.my-host.com (attempt 2/5)... | ||
| Simulating connection failure with exit code '2' | ||
| Connection failed with retryable error: connection failed (retryable): psql exited with code 2 | ||
| Connection attempt 2/5 failed, retrying in 2s... | ||
| Launching psql session to my-database.my-host.com (attempt 3/5)... | ||
| Simulating connection failure with exit code '2' | ||
| Connection failed with retryable error: connection failed (retryable): psql exited with code 2 | ||
| Connection attempt 3/5 failed, retrying in 4s... | ||
| Launching psql session to my-database.my-host.com (attempt 4/5)... | ||
| Simulating connection failure with exit code '2' | ||
| Connection failed with retryable error: connection failed (retryable): psql exited with code 2 | ||
| Connection attempt 4/5 failed, retrying in 8s... | ||
| Launching psql session to my-database.my-host.com (attempt 5/5)... | ||
| Simulating connection failure with exit code '2' | ||
| Connection failed with retryable error: connection failed (retryable): psql exited with code 2 | ||
| Error: failed to connect after 5 attempts, last error: connection failed (retryable): psql exited with code 2 | ||
|
|
||
| Exit code (musterr): 1 | ||
|
|
||
| === Command should not use retries: | ||
| >>> musterr [CLI] psql my-database --max-retries 0 -- --dbname=db1 -p 3000 | ||
| Connecting to Databricks Database Instance my-database ... | ||
| Postgres version: 14 | ||
| Database instance status: AVAILABLE | ||
| Successfully fetched database credentials | ||
| Launching psql with connection to my-database.my-host.com... | ||
| Simulating connection failure with exit code '2' | ||
|
|
||
| Exit code (musterr): 2 |
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,17 @@ | ||
| mv always-fail.sh psql | ||
|
|
||
| cleanup() { | ||
| rm psql | ||
| } | ||
| trap cleanup EXIT | ||
|
|
||
| export PATH="$(pwd):$PATH" | ||
|
|
||
| title "Command should use default number of retries:" | ||
| trace musterr $CLI psql my-database -- --dbname=db1 -p 3000 | ||
|
|
||
| title "Command should use custom number of retries:" | ||
| trace musterr $CLI psql my-database --max-retries 5 -- --dbname=db1 -p 3000 | ||
|
|
||
| title "Command should not use retries:" | ||
| trace musterr $CLI psql my-database --max-retries 0 -- --dbname=db1 -p 3000 | ||
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,32 @@ | ||
| # This acceptance test is disabled on Windows runners because | ||
| # the current argument capturing method does not work on windows-latest GitHub Runner. | ||
| # | ||
| # See PR #3228 for documented attempts to fix this issue: | ||
| # https://github.com/databricks/cli/pull/3228 | ||
| GOOS.windows = false | ||
|
|
||
| [[Server]] | ||
| Pattern = "GET /api/2.0/database/instances/my-database" | ||
| Response.Body = ''' | ||
| { | ||
| "state": "AVAILABLE", | ||
| "pg_version": "14", | ||
| "read_write_dns": "my-database.my-host.com" | ||
| } | ||
| ''' | ||
|
|
||
| [[Server]] | ||
| Pattern = "GET /api/2.0/database/instances" | ||
| Response.Body = ''' | ||
| { | ||
| "database_instances": [] | ||
| } | ||
| ''' | ||
|
|
||
| [[Server]] | ||
| Pattern = "POST /api/2.0/database/credentials" | ||
| Response.Body = ''' | ||
| { | ||
| "token": "my-secret-token" | ||
| } | ||
| ''' |
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
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
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.