Skip to content
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: Test connection using dedicated endpoint #17993

Merged
merged 24 commits into from
May 20, 2024

Conversation

disq
Copy link
Member

@disq disq commented May 16, 2024

Opening for comments.

A run with 2 plugin test connections (one success and one fail) and one plugin failure (not related to TestConnection)
(The postgresql plugin is an older public release with TestConnection not implemented, falling back on Init)

$ ./cli test-connection ./testsrc.yml ./gandi.yml 
Loading spec(s) from ./testsrc.yml, ./gandi.yml
Test Connection Results
source       gandi (cloudquery/gandi@v3.2.1)          Success
destination  pg@github (cloudquery/postgresql@v7.0.1) Failure: OTHER      rpc error: code = Internal desc = failed to init plugin: failed to initialize client: failed to get current database: failed to connect to `host=localhost user=postgres database=cq`: dial error (dial tcp 127.0.0.1:15432: connect: connection refused)
Error: at least one test connection failed
(exit code 1) $

With postgres implementing the test connector and a configuration with host=badhost

❯ ./cli test-connection test-connection.yaml
Loading spec(s) from test-connection.yaml
Test Connection Results
source       hackernews (cloudquery/hackernews@v3.1.8)  Success
destination  postgresql (grpc@localhost:7777)           Failure: INVALID_CREDENTIALS 	 no such host "badhost"
Error: at least one test connection failed

@disq disq requested a review from a team as a code owner May 16, 2024 16:47
@disq disq requested review from savme and removed request for a team May 16, 2024 16:47
@disq disq requested a review from erezrokah May 16, 2024 16:48
cli/go.mod Outdated

replace github.com/cloudquery/plugin-sdk/v4 => github.com/disq/plugin-sdk/v4 v4.0.0-20240516151118-4958828f53c9

replace github.com/cloudquery/plugin-pb-go => github.com/cloudquery/plugin-pb-go v1.19.13-0.20240516105108-3fdf6ac15ea2
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be removed before merge when plugin-sdk and plugin-pb-go are released.

@erezrokah
Copy link
Contributor

erezrokah commented May 17, 2024

Can you share the specs you used to test? How can the test connection fail for the test plugin (failed to test source test)?
For the second spec not sure host= badhost is invalid credentials (credentials usually refer to user/pass), but that's a plugin issue

@disq
Copy link
Member Author

disq commented May 17, 2024

# testsrc.yml
kind: source
spec:
  name: test
  version: v4.1.0
  path: cloudquery/test
  tables: ["*"]
  destinations: ["pg"]
  spec:
    num_clients: 1
    num_rows: 10
    num_sub_rows: 20000
    num_sub_cols: 200
# gandi.yml
kind: source
spec:
  name: gandi
  path: cloudquery/gandi
  registry: cloudquery
  version: "v3.2.1"
  tables:
    - "*"
  destinations:
    - pg
  spec:
    api_key: my-valid-key
    endpoint_url: https://api.sandbox.gandi.net/
---
kind: destination
spec:
  name: "pg"
  path: "cloudquery/postgresql"
  registry: "github"
  version: "v7.0.1"
  write_mode: "overwrite-delete-stale"
  spec:
    connection_string: "postgresql://postgres:pass@localhost:15432/cq"
# singlepg.yml
kind: destination
spec:
  name: "pg"
  path: "cloudquery/postgresql"
  registry: "github"
  version: "v7.0.1"
  write_mode: "overwrite-delete-stale"
  spec:
    connection_string: "postgresql://postgres:pass@localhost:15432/cq"
$ ./cli test-connection ./singlepg.yml 
Loading spec(s) from ./singlepg.yml
Test Connection Results
destination  pg@github (cloudquery/postgresql@v7.0.1)  Success
(exit code 0) $

@disq
Copy link
Member Author

disq commented May 17, 2024

@erezrokah The "failed to test source test" issue was fixed in 4477eb2 and the next cleanup commit. I just updated the PR description to reflect. It can still generate failed to test source|destination %v: %w type errors if for example it cannot communicate via gRPC with the plugin etc.

cli/cmd/test_connection.go Outdated Show resolved Hide resolved
cli/cmd/test_connection.go Outdated Show resolved Hide resolved
cli/cmd/test_connection.go Outdated Show resolved Hide resolved
Copy link
Contributor

@erezrokah erezrokah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few more comments

cli/cmd/test_connection.go Outdated Show resolved Hide resolved
cli/cmd/test_connection.go Outdated Show resolved Hide resolved
cli/cmd/test_connection.go Outdated Show resolved Hide resolved
}

func (*testConnectionFailures) Error() string {
// The errs are already shown in the console, so we don't need to show them again here
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are the errors shown when you do --log-console too?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, now better, with proper plugin_ref etc.

2024-05-17T14:33:56Z INF Loading spec(s) args=["./pgrpc.yml"] invocation-id=dafde1e3-5e32-4fad-8fb5-c7ad7a885284 module=cli
2024-05-17T14:33:56Z INF Testing destination destination="pg (grpc@localhost:7778)" invocation-id=dafde1e3-5e32-4fad-8fb5-c7ad7a885284 module=cli
2024-05-17T14:33:56Z INF Test connection completed invocation-id=dafde1e3-5e32-4fad-8fb5-c7ad7a885284 module=cli testresults=[{"failure_code":"OTHER","failure_description":"rpc error: code = Internal desc = failed to init plugin: failed to initialize client: failed to get current database: failed to connect to `host=localhost user=postgres database=cq`: dial error (dial tcp 127.0.0.1:15432: connect: connection refused)","plugin_kind":"destination","plugin_ref":"pg (grpc@localhost:7778)","success":false}]
Error: at least one test connection failed
2024-05-17T14:33:56Z ERR exiting with error error="at least one test connection failed" invocation-id=dafde1e3-5e32-4fad-8fb5-c7ad7a885284 module=cli

//
// The function returns any failed test results, or nil if all tests passed. The hackernews plugin is excluded from the
// failed test results since it was previously used as a test case for the test connection command.
func filterFailedTestResults(results []testConnectionResult) (*testConnectionResult, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait what's the reason we need to filter these plugins? I don't think their connection test can ever fail

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those should be there until we update the cloud side to use the new cli.

Copy link
Contributor

@erezrokah erezrokah May 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah because with existing Cloud the new CLI will report failures for them?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it matters much this feature is only enabled for the cloudquery team

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we want the cloud api side to work, this filtering needs to be there at least for now.

@disq disq added the automerge Automatically merge once required checks pass label May 20, 2024
@kodiakhq kodiakhq bot merged commit 0baae95 into main May 20, 2024
20 checks passed
@kodiakhq kodiakhq bot deleted the feat/adding-test-connection-cli branch May 20, 2024 09:41
kodiakhq bot pushed a commit that referenced this pull request May 20, 2024
🤖 I have created a release *beep* *boop*
---


## [5.20.0](cli-v5.19.0...cli-v5.20.0) (2024-05-20)


### Features

* Test connection using dedicated endpoint ([#17993](#17993)) ([0baae95](0baae95))


### Bug Fixes

* **deps:** Update module github.com/cloudquery/cloudquery-api-go to v1.11.2 ([#17995](#17995)) ([9bc2353](9bc2353))
* **deps:** Update module github.com/cloudquery/plugin-pb-go to v1.19.13 ([#18001](#18001)) ([042f3b8](042f3b8))
* **deps:** Update module github.com/cloudquery/plugin-sdk/v4 to v4.42.2 ([#18000](#18000)) ([5fc0f46](5fc0f46))
* **deps:** Update module github.com/cloudquery/plugin-sdk/v4 to v4.43.0 ([#18014](#18014)) ([20592c8](20592c8))

---
This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/cli area/website automerge Automatically merge once required checks pass
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants