Skip to content

feat: Add function to list tables that match a source spec#440

Merged
kodiakhq[bot] merged 10 commits intomainfrom
add-tables-for-spec
Nov 29, 2022
Merged

feat: Add function to list tables that match a source spec#440
kodiakhq[bot] merged 10 commits intomainfrom
add-tables-for-spec

Conversation

@hermanschaaf
Copy link
Copy Markdown
Contributor

This adds a new GetTablesForSpec function to the SourceClient that filters the list of tables to the ones selected by the given Source Spec. It is fully backwards-compatible, and I decided to keep the changeset small by adding an optional parameter to the existing GetTables proto rpc.

This will be used to implement cloudquery/cloudquery#4715

Copy link
Copy Markdown
Contributor

@yevgenypats yevgenypats left a comment

Choose a reason for hiding this comment

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

Will it make sense to introduce another method for that? Otherwise the client can think this is supported while it doesn't and if it will be a new method it can distinguish that. Not sure if this is needed as it can also work that way. but just bringing this up for discussion.

@hermanschaaf
Copy link
Copy Markdown
Contributor Author

@yevgenypats Hmm yeah, good point. We don't need to know right now, but I can see it potentially being important/useful to avoid bugs in the future. I'm fine with adding an extra method if you're happy with that too.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Nov 29, 2022

⏱️ Benchmark results

Comparing with c8c824d

  • DefaultConcurrency-2 resources/s: 11,649 ⬇️ 3.43% decrease vs. c8c824d
  • Glob-2 ns/op: 158.2 ⬇️ 0.32% decrease vs. c8c824d
  • TablesWithChildrenDefaultConcurrency-2 resources/s: 31,445 ⬆️ 7.92% increase vs. c8c824d
  • BufferedScanner-2 ns/op: 9.371 ⬇️ 0.25% decrease vs. c8c824d
  • LogReader-2 ns/op: 30.74 ⬇️ 0.03% decrease vs. c8c824d

"google.golang.org/grpc/status"
)

var ErrMethodNotSupported = errors.New("method not supported")
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I added this error so that callers of this client library don't have to unwrap the returned error and figure out from grpc status codes whether it was supported or not. They can now check whether this error was returned to know if a method was not supported.

Copy link
Copy Markdown
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 we should do that because but rather we need to use the grpc code directly. The CLI can have a helper function that check if a grpc is unimplemented and return some error message but the client shouldn't introduce a new error.

Copy link
Copy Markdown
Contributor Author

@hermanschaaf hermanschaaf Nov 29, 2022

Choose a reason for hiding this comment

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

Maybe I misunderstand the purpose of the client library, but my thinking is that it should abstract away the gRPC calls so that users of this library don't have to concern themselves with the underlying gRPC layer? (Otherwise this has a leaky abstraction)

Copy link
Copy Markdown
Contributor Author

@hermanschaaf hermanschaaf Nov 29, 2022

Choose a reason for hiding this comment

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

Oh yeah, it's probably also worth mentioning that the gRPC status codes don't support errors.As, otherwise it would have been okay to wrap the error before returning it: grpc/grpc-go#2934.

But as things stand, it's pretty tricky for callers of the client library to discover when it's not supported in a reliable way. Probably the best would be to look for a specific string in the error message.

Copy link
Copy Markdown
Contributor

@yevgenypats yevgenypats Nov 29, 2022

Choose a reason for hiding this comment

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

I see. ok I guess it's a nit. not sure right now what would be the best solution so let's skip it. mostly the thing that worries me that it is now inconsistent because then we need to put it in all calls.

@hermanschaaf
Copy link
Copy Markdown
Contributor Author

@yevgenypats I've added the method, and updated the corresponding PR here cloudquery/cloudquery#5098 to make sure it all works together. Here's an updated example using the new code:

➜  playground ../cloudquery/cli/cli sync aws.yml
Loading spec(s) from aws.yml
Source aws will migrate and sync 23 tables.
Starting migration for: aws -> [postgresql]
Migration completed successfully.
Starting sync for: aws -> [postgresql]
Sync completed successfully. Resources: 5, Errors: 1, Panics: 0, Time: 3s

And if a new CLI is run against an old version of the AWS plugin:

➜  playground ../cloudquery/cli/cli sync aws.yml
Loading spec(s) from aws.yml
Starting migration for: aws -> [postgresql]
Migration completed successfully.
Starting sync for: aws -> [postgresql]
Sync completed successfully. Resources: 5, Errors: 1, Panics: 0, Time: 4s

Please take another look 🙇

Copy link
Copy Markdown
Contributor

@yevgenypats yevgenypats left a comment

Choose a reason for hiding this comment

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

Looks good. One comment on error handling and I think one more "e2e" test is missing here https://github.com/cloudquery/plugin-sdk/blob/main/serve/source_test.go

@hermanschaaf
Copy link
Copy Markdown
Contributor Author

@yevgenypats Thanks for the review! Updated with the following changes:

  • added IsUnimplemented helper function to help determine when the underlying method was unimplemented by the server
  • added an e2e test for GetTablesForSpec
  • no longer returning a custom error, but instead wrapping the grpc one

@kodiakhq kodiakhq bot merged commit a8f3690 into main Nov 29, 2022
@kodiakhq kodiakhq bot deleted the add-tables-for-spec branch November 29, 2022 17:24
hermanschaaf pushed a commit that referenced this pull request Nov 29, 2022
🤖 I have created a release *beep* *boop*
---


##
[1.10.0](v1.9.0...v1.10.0)
(2022-11-29)


### Features

* Add function to list tables that match a source spec
([#440](#440))
([a8f3690](a8f3690))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).
kodiakhq bot pushed a commit to cloudquery/cloudquery that referenced this pull request Nov 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants