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!: Add path variable support to GCS destination plugin. #17602

Merged
merged 10 commits into from
Apr 12, 2024

Conversation

shubham-padia
Copy link
Contributor

@shubham-padia shubham-padia commented Apr 11, 2024

Fixes #15097 . Since the PR is fairly large, please review it commit by commit along with a read of the commit message descriptions to get a better sense of the changes.

Summary

Add path variable support to GCS destination plugin. This is a breaking change. We check if the path string has any of the template variables like {{FORMAT}}, {{TABLE}} and so on. If they do, we follow the behaviour of S3 plugin wherein we replace the template variables and that's it. If there are no such variables, we revert back to the current behaviour in the code block shown above.

Please read the issue comments to check on how the decisions for this PR were made.

This PR follows similar approach to the S3 plugin. I've added some extra tests for client.read() errors which we should probably copy back to S3 and File plugins in a follow up issue.

Note: I have not made additions to CHANGELOG.md, I'm assuming the maintainer will do it just before merge, in order to make sure of the right tag at the time of merge. Please lmk if I need to make that change

GCS screenshot for path `new/{{TABLE}}/{{UUID}}.{{FORMAT}}`

Screenshot 2024-04-12 at 1 46 50β€―AM

  • Read the contribution guidelines πŸ§‘β€πŸŽ“
  • Run make lint to ensure the proposed changes follow the coding style 🚨 (install golangci-lint here)
  • Run make test to ensure the proposed changes pass the tests πŸ§ͺ
  • If changing a source plugin run make gen to ensure docs are up to date πŸ“
  • Ensure the status checks below are successful βœ…

@shubham-padia shubham-padia marked this pull request as ready for review April 11, 2024 20:06
@shubham-padia shubham-padia requested a review from a team as a code owner April 11, 2024 20:06
@shubham-padia shubham-padia requested review from bbernays and removed request for a team April 11, 2024 20:06
@shubham-padia
Copy link
Contributor Author

I checked the failing runs:

  1. Fixed the grammar mistake in the documentation at https://github.com/cloudquery/cloudquery/compare/693d590150666a0282a090934885d80fd34d5df9..ccbbec85f57557e6582cf6ef4ce72ad103240f7d
  2. For https://github.com/cloudquery/cloudquery/actions/runs/8652900255, $ACTIONS_ID_TOKEN_REQUEST_TOKEN is not available to this PR since I think this is running from a fork?
  3. For https://github.com/cloudquery/cloudquery/actions/runs/8652900268, where wait_for_required_workflows fails, it might have to do something with kodiakhq and auto merging? I could look more into it but a maintainer might be able to help me out much quicker if it's a small issue.

@erezrokah
Copy link
Contributor

2. For https://github.com/cloudquery/cloudquery/actions/runs/8652900255, $ACTIONS_ID_TOKEN_REQUEST_TOKEN is not available to this PR since I think this is running from a fork?

πŸ’― Credentials are not available for forked PR, I'll open a copy of this PR from a non forked branch to validate

3. where wait_for_required_workflows fails

Is a custom workflow we wrote to facilitate branch protection enforcement in monorepos without having to run workflows for all monorepos components due to https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/collaborating-on-repositories-with-code-quality-features/troubleshooting-required-status-checks#handling-skipped-but-required-checks

It's failing since due to the issue with the credentials

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.

Looks great @shubham-padia, added a few minor comments, sorry for the delayed review

Comment on lines 141 to 147
if err != nil {
if expectErrorWhenReading {
assert.ErrorContains(t, err, readErrorString)
t.Skip()
}
t.Fatal(fmt.Errorf("failed to sync: %w", err))
} else if expectErrorWhenReading {
t.Fatal(fmt.Errorf("expected error while performing client.read(), got None"))
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if err != nil {
if expectErrorWhenReading {
assert.ErrorContains(t, err, readErrorString)
t.Skip()
}
t.Fatal(fmt.Errorf("failed to sync: %w", err))
} else if expectErrorWhenReading {
t.Fatal(fmt.Errorf("expected error while performing client.read(), got None"))
}
if expectErrorWhenReading {
require.ErrorContains(t, err,readErrorString)
} else {
require.NoError(t, err)
}

Could this work instead? Regardless what's the reason we have t.Skip() in the test?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that works much better, thanks @erezrokah. This is my first time using Go, so this is much appreciated!

I was using t.Skip() to skip the rest of the test when we encounter an error but I saw this file uses return, so I changed it to that.

Copy link
Contributor

Choose a reason for hiding this comment

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

OK so I think we can drop the return in both cases. That's the reason to use require over assert. require stops the test on failure https://github.com/stretchr/testify?tab=readme-ov-file#require-package

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@erezrokah I think we still need this return, require will stop the tests on failure, but failure in this case would mean either not getting an error or the error not containing the string that we provided. If the error contains the message, the require assertion would pass successfully and move on to the next part of the tests

Copy link
Contributor

Choose a reason for hiding this comment

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

You're right πŸ‘ How about a25ccda to early return and reduce the if/else nesting?

I also added another commit to remove the boolean flag in 0982124

WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, much cleaner, thanks!

plugins/destination/gcs/docs/overview.md Outdated Show resolved Hide resolved
@erezrokah
Copy link
Contributor

Looks like tests are passing https://github.com/cloudquery/cloudquery/actions/runs/8665051208/job/23762862668?pr=17608. For the changelog we generate those automatically based on the commit message.

To trigger a major version bump the PR title should start with feat!: (see https://github.com/cloudquery/cloudquery/blob/main/CONTRIBUTING.md#commit-messages)

@shubham-padia shubham-padia changed the title feat: Add path variable support to GCS destination plugin. feat!: Add path variable support to GCS destination plugin. Apr 12, 2024
This commit follows an approach similar to the S3 plugin.
To maintain backwards compatibility:
Check if the path string has any of the template variables like {{FORMAT}},
{TABLE}} and so on. If they do, we follow the behaviour of S3 plugin wherein we
replace the template variables and that's it. If there are no such variables, we
revert back to the current behaviour in the code block shown above.

This commit is not the complete solution, we need to:
- disable uuid in case of no_rotate and any other possible
schema validations.
- replace path variables in read.go.

We are not doing the above items in this commit for the sake of
breaking down commits in easy to review chunks. Still, this commit
passes all the existing tests to make sure that none of the individual
commits would break any of the existing tests.
batching enabled -> require {{UUID}} in path or require no path
variables in path, since we will use UUID by default if batch
Mostly rearranging of the schema.
@erezrokah
Copy link
Contributor

@shubham-padia please let me know what you think of my recent changes. I think the PR is ready to be merged unless there's something I missed

@shubham-padia
Copy link
Contributor Author

@erezrokah Those changes look good, thanks! This should be good to merge!

@erezrokah erezrokah merged commit 1ea5680 into cloudquery:main Apr 12, 2024
16 of 19 checks passed
@erezrokah
Copy link
Contributor

erezrokah commented Apr 12, 2024

We'll release the new version #17611 on Tuesday April 16th as a part of our weekly cadence of releases

kodiakhq bot pushed a commit that referenced this pull request Apr 17, 2024
πŸ€– I have created a release *beep* *boop*
---


## [4.0.0](plugins-destination-gcs-v3.6.6...plugins-destination-gcs-v4.0.0) (2024-04-17)


### ⚠ BREAKING CHANGES

* Add path variable support to GCS destination plugin.  ([#17602](#17602))

### Features

* Add custom JSON schema errors ([#17669](#17669)) ([a3ad426](a3ad426))
* Add path variable support to GCS destination plugin.  ([#17602](#17602)) ([1ea5680](1ea5680))


### Bug Fixes

* **deps:** Update module github.com/cloudquery/codegen to v0.3.14 ([#17658](#17658)) ([478eb9c](478eb9c))
* **deps:** Update module github.com/cloudquery/codegen to v0.3.15 ([#17659](#17659)) ([58586d0](58586d0))
* **deps:** Update module github.com/cloudquery/plugin-sdk/v4 to v4.38.1 ([#17610](#17610)) ([a12d17b](a12d17b))
* **deps:** Update module github.com/cloudquery/plugin-sdk/v4 to v4.38.2 ([#17656](#17656)) ([058910b](058910b))
* **deps:** Update module google.golang.org/api to v0.172.0 ([#17617](#17617)) ([1e62b14](1e62b14))

---
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: GCS Destination Templating
4 participants