Skip to content

feat: Add CQ type system to support multiple destinations#320

Merged
yevgenypats merged 18 commits intomainfrom
feat/cq_type_system
Oct 31, 2022
Merged

feat: Add CQ type system to support multiple destinations#320
yevgenypats merged 18 commits intomainfrom
feat/cq_type_system

Conversation

@yevgenypats
Copy link
Copy Markdown
Contributor

@yevgenypats yevgenypats commented Oct 30, 2022

This add a type system to CloudQuery SDK.

This is mandatory to support multiple destinations.

Also, this found quite a few bugs where we were sending random stuff over the wire without any validation apart from maybe when we were hitting the database and then failing batches all together.

In CloudQuery type system I used heavily https://github.com/jackc/pgtype and kept the license and the copyright in it's own package cqtype.

This is a continue of this PR #298 where I split it into this one and #318

Copy link
Copy Markdown
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.

Added a few comments and will continue to review tomorrow 📖

eg := &errgroup.Group{}
// given most destination plugins writing in batch we are using a worker pool to write in parallel
// it might not generalize well and we might need to move it to each destination plugin implementation.
for i := 0; i < writeWorkers; i++ {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Since writeWorkers is always 1 maybe we can remove this for now?

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.

yeah we can. I was playing with that, wasn't sure what it should be and how it generalize to most plugins.

yevgenypats and others added 2 commits October 30, 2022 22:05
Co-authored-by: Erez Rokah <erezrokah@users.noreply.github.com>
Co-authored-by: Herman Schaaf <hermanschaaf@gmail.com>
cqtypes/inet.go Outdated
Comment on lines +11 to +17
// Network address family is dependent on server socket.h value for AF_INET.
// In practice, all platforms appear to have the same value. See
// src/include/utils/inet.h for more information.
const (
// defaultAFInet = 2
// defaultAFInet6 = 3
)
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.

Looks like this constant block is now unused 🤔

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.

yes. removed. it is used in pgx to encode to postgresql binary format but we don't need it as we just need the decode part and not from postgresql


eg := errgroup.Group{}
eg.Go(func() error {
return s.Plugin.Write(context.Background(), tables, sourceName, syncTime, resources)
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.

Just trying to understand: why is this write now using context.Background() instead of msg.Context() ?

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.

Good catch. I think just got confused in the context maze

panic(columnName + " column not found")
}
if err := r.data[index].Set(value); err != nil {
panic(fmt.Errorf("failed to set column %s: %w", columnName, err))
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.

Should this be a panic? It seems like if we set a column and it fails, we should return an error but otherwise leave it empty.

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.

Yeah it should panic because it mean what the user provided is of incorrect value and defined the wrong column. We don't have a way of knowing about this (in sentry and in logs) other then panic as all other errors are classified as error. But I do think it's a panic in any case.

yevgenypats and others added 2 commits October 31, 2022 17:16
Co-authored-by: Herman Schaaf <hermanschaaf@gmail.com>
@yevgenypats yevgenypats merged commit d3b24a0 into main Oct 31, 2022
@yevgenypats yevgenypats deleted the feat/cq_type_system branch October 31, 2022 15:44
kodiakhq bot pushed a commit that referenced this pull request Oct 31, 2022
🤖 I have created a release *beep* *boop*
---


## [0.13.16](v0.13.15...v0.13.16) (2022-10-31)


### Features

* Add CQ type system to support multiple destinations ([#320](#320)) ([d3b24a0](d3b24a0))

---
This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
yevgenypats added a commit to cloudquery/cloudquery that referenced this pull request Oct 31, 2022
yevgenypats added a commit to cloudquery/cloudquery that referenced this pull request Oct 31, 2022
yevgenypats added a commit to cloudquery/cloudquery that referenced this pull request Nov 1, 2022
This is instead of #3176 

SDK PRs:

cloudquery/plugin-sdk#318
cloudquery/plugin-sdk#320

Previous related CloudQuery PRs:

#3286

Co-authored-by: Herman Schaaf <hermanschaaf@gmail.com>
Co-authored-by: Erez Rokah <erezrokah@users.noreply.github.com>
yevgenypats added a commit to cloudquery/cloudquery that referenced this pull request Nov 1, 2022
This is instead of #3176 

SDK PRs:

cloudquery/plugin-sdk#318
cloudquery/plugin-sdk#320

Previous related CloudQuery PRs:

#3286

Co-authored-by: Herman Schaaf <hermanschaaf@gmail.com>
Co-authored-by: Erez Rokah <erezrokah@users.noreply.github.com>
daniel-garcia pushed a commit to infobloxopen/ibcq-source-k8s that referenced this pull request Feb 24, 2026
This is instead of cloudquery/cloudquery#3176 

SDK PRs:

cloudquery/plugin-sdk#318
cloudquery/plugin-sdk#320

Previous related CloudQuery PRs:

cloudquery/cloudquery#3286

Co-authored-by: Herman Schaaf <hermanschaaf@gmail.com>
Co-authored-by: Erez Rokah <erezrokah@users.noreply.github.com>
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