Skip to content

Conversation

@yevgenypats
Copy link
Contributor

@yevgenypats yevgenypats commented Jan 16, 2023

This introduce WithDynamicTables for source plugins to give an option for plugins to generate tables on the go, this can be useful in GA analytics, Salesforce and others where you can only get the schema and tables in runtime.

Give WithDynamicTables is actually a breaking change and I didn't want to turn our code into spagetti that tries to understand in runtime which version is the client I took the opportunity to fix our protobuf structures and introduce a way for creating new versions for server in a breaking way while also serving older versions of the server so it wont affect user experience but will give us a better way to write and maintain different versions and eventually deprecate older versions.

cc @erezrokah as I know you suggested exactly that a while back but it was too early for me after the initial refactor :) and wasn't sure what are the requirements yet but here we go!

@github-actions github-actions bot added feat and removed feat labels Jan 16, 2023
Copy link
Member

@hermanschaaf hermanschaaf left a comment

Choose a reason for hiding this comment

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

Looks great! I had a look through the code. @yevgenypats Have you been able to use it successfully for a source plugin? It would be nice to see an example of it in use to better judge the interface and make sure it can be used to do what we need, before committing to it :)

@yevgenypats
Copy link
Contributor Author

Looks great! I had a look through the code. @yevgenypats Have you been able to use it successfully for a source plugin? It would be nice to see an example of it in use to better judge the interface and make sure it can be used to do what we need, before committing to it :)

Yes, definitely. What I'd like to do is the following:

  1. to merge this after initial review
  2. Put the SDK on freeze (not push any release and just keep this commit in main).
  3. open a CLI PR and open any small PRs on top if any changes to v1 so it will be easier to review.

Copy link
Member

@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.

Looks good but it's quite a big diff to review.
To confirm, other than the new package structure the changes are:

  1. Add the new option
  2. Sync the dynamic tables during init
  3. Continue with sync based on dynamic tables

Is that mostly correct?

return status.Errorf(codes.InvalidArgument, "failed to decode spec: %v", err)
}
ctx := stream.Context()
if err := s.Plugin.Init(ctx, spec); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

Was this missing or moved from someplace else?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah now we need to call it in v0 as we don't want to break the v0 protocol


// Sync is syncing data from the requested tables in spec to the given channel
func (p *Plugin) Sync(ctx context.Context, spec specs.Source, res chan<- *schema.Resource) error {
func (p *Plugin) Init(ctx context.Context, spec specs.Source) error {
Copy link
Member

Choose a reason for hiding this comment

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

Ah, got it we need a separate Init to sync dynamic tables

@yevgenypats
Copy link
Contributor Author

Looks good but it's quite a big diff to review. To confirm, other than the new package structure the changes are:

  1. Add the new option
  2. Sync the dynamic tables during init
  3. Continue with sync based on dynamic tables

Is that mostly correct?
correct.

I can split to PRs if that's helpful with one only introducing v0 moving things around and then one introducing v1.

@erezrokah
Copy link
Member

I can split to PRs if that's helpful with one only introducing v0 moving things around and then one introducing v1.

No need to split, just wanted to confirm

Copy link
Member

@hermanschaaf hermanschaaf left a comment

Choose a reason for hiding this comment

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

LGTM, not sure why the build is failing on the post-step

@github-actions
Copy link

⏱️ Benchmark results

Comparing with 3756780

  • DefaultConcurrencyDFS-2 resources/s: 10,951 ⬇️ 1.08% decrease vs. 3756780
  • DefaultConcurrencyRoundRobin-2 resources/s: 12,300 ⬆️ 0.27% increase vs. 3756780
  • Glob-2 ns/op: 145.6 ⬇️ 0.21% decrease vs. 3756780
  • TablesWithChildrenDFS-2 resources/s: 28,670 ⬇️ 10.14% decrease vs. 3756780
  • TablesWithChildrenRoundRobin-2 resources/s: 29,292 ⬆️ 1.80% increase vs. 3756780
  • TablesWithRateLimitingDFS-2 resources/s: 28 ⬇️ 0.68% decrease vs. 3756780
  • TablesWithRateLimitingRoundRobin-2 resources/s: 776.7 ⬇️ 4.98% decrease vs. 3756780
  • BufferedScanner-2 ns/op: 9.29 ⬇️ 1.66% decrease vs. 3756780
  • LogReader-2 ns/op: 31.21 ⬆️ 1.22% increase vs. 3756780

@kodiakhq kodiakhq bot merged commit 448232c into main Jan 17, 2023
@kodiakhq kodiakhq bot deleted the feat/dynamic_tables branch January 17, 2023 13:17
kodiakhq bot pushed a commit that referenced this pull request Jan 18, 2023
Import paths and references will need to be updated after #610 anyway, let's use this opportunity to change from e.g. `destination.WithDestinationLogger(log.Logger)` to `destination.WithLogger(log.Logger)`

~I will update the tests momentarily...~ done
kodiakhq bot pushed a commit that referenced this pull request Jan 23, 2023
This adds discovery service to support multiple versions. Follow-up to this: #610
kodiakhq bot pushed a commit that referenced this pull request Jan 23, 2023
🤖 I have created a release *beep* *boop*
---


## [1.28.0](v1.27.0...v1.28.0) (2023-01-23)


### Features

* Add version discovery service ([#619](#619)) ([33ab32a](33ab32a))
* Dynamic tables and introduce proto versioning ([#610](#610)) ([448232c](448232c))


### Bug Fixes

* **clients:** Update `log line too long` message ([#611](#611)) ([0d3ff48](0d3ff48))
* Simplify client naming conventions ([#617](#617)) ([38b136b](38b136b))

---
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 that referenced this pull request Jan 26, 2023

This is more of hot fix/patch to #610.
#610 had an unwanted side effect on the migrate command, as now we init the plugin before running it.
initializing the plugin is expensive, requires credentials and does a whole lot of validations, for example:
https://github.com/cloudquery/cloudquery/blob/a06139efad9a2e8de14f186a223222c9d52ce58a/plugins/source/aws/client/client.go#L383
https://github.com/cloudquery/cloudquery/blob/a06139efad9a2e8de14f186a223222c9d52ce58a/plugins/source/azure/client/client.go#L124

Those seem unnecessary for tables migration (unless one uses dynamic tables).

---
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.

4 participants