feat(alicloud): Add alicloud source plugin to sync bss and oss resources#6418
Conversation
This PR has the following changes to source plugin(s) tables:
|
hermanschaaf
left a comment
There was a problem hiding this comment.
This is amazing, thank you @lshmouse! Really excited to be adding support for Alicloud. I left a few comments after an initial review. I'll also try and test it out a bit soon so I can give more thorough feedback. Let me know if you're willing to add some mock tests or if you'd like some help with that :)
|
|
||
| func ResolveUpdateDate() schema.ColumnResolver { | ||
| return func(_ context.Context, _ schema.ClientMeta, r *schema.Resource, c schema.Column) error { | ||
| return r.Set(c.Name, time.Now().AddDate(0, 0, -1).Format("2006-01-02")) |
There was a problem hiding this comment.
Why is this column resolver needed, and why does it add -1 days? Do you need information about exactly when a row was added? The _cq_sync_time column doesn't give exact row-level data, but it does tell you when a sync started, which is usually good enough.
There was a problem hiding this comment.
Oh, after reading a bit more of the PR, I see that this column is part of the PK, probably to avoid overwriting rows from previous syncs. You can also achieve the same by leaving the PK empty, in which case it will default to _cq_sync_id. In overwrite-delete-stale mode CloudQuery will first sync all rows, then delete rows from previous syncs.
| bucketName := codegen.ColumnDefinition{ | ||
| Name: "name", | ||
| Type: schema.TypeString, | ||
| Resolver: `client.ResolveParentColumn("Name")`, |
There was a problem hiding this comment.
I think we should be able to use schema.ParentColumnResolver from the plugin-sdk library here (e.g. https://github.com/cloudquery/cloudquery/blob/ec1d132529824d16682a92a83ee326fcba939efc/plugins/source/aws/codegen/recipes/s3.go#LL61C2-L61C2), and remove the custom resolver from this plugin. I notice this pattern was copied from the Github plugin, we should probably fix it there too in a follow-up PR :)
| version: "v1.1.12" | ||
| write_mode: "append" # CSV only supports 'append' mode | ||
| spec: | ||
| directory: './cq_csv_output' No newline at end of file |
There was a problem hiding this comment.
This is a good way for developers to test the plugin against real infrastructure for now, but eventually we'll probably remove it here and move it to the docs.
For testing in CI we'll require mock tests for the resolvers. Here's an example from the Github plugin. I can also help you write those if you like, they are fairly mechanical once you've created the mocks :)
| github.com/alibabacloud-go/tea v1.1.20 | ||
| github.com/aliyun/alibaba-cloud-sdk-go v1.62.80 | ||
| github.com/aliyun/aliyun-oss-go-sdk v2.2.6+incompatible | ||
| github.com/cloudquery/plugin-sdk v1.11.1 |
There was a problem hiding this comment.
This plugin-sdk version is a little out-of-date, let's make sure to use the latest version (v1.21.0)
| } | ||
|
|
||
| /* | ||
| * https://help.aliyun.com/document_detail/100392.html |
There was a problem hiding this comment.
These links are great - we should also add them to the Description field of each table so they show up in the docs :)
| */ | ||
| func fetchBssBill(_ context.Context, meta schema.ClientMeta, _ *schema.Resource, res chan<- any) error { | ||
| spec := meta.(*client.Client).Spec | ||
| cli, err := bssopenapi.NewClientWithAccessKey(spec.RegionID, spec.AccessKey, spec.SecretKey) |
There was a problem hiding this comment.
I don't know if it's possible in this case, but plugins generally initialize the client in client.go, and store it as a property on the client.Client struct, so we could then access it here like
c := meta.(*client.Client)
cli := c.Client
This has the added benefit of erroring out earlier if there is an issue initializing the client, before calling all the resolvers.
| RegionID string `json:"region_id,omitempty"` | ||
| AccessKey string `json:"access_key,omitempty"` | ||
| SecretKey string `json:"secret_key,omitempty"` | ||
| BillHistory int `json:"bill_history,omitempty"` |
There was a problem hiding this comment.
What does this option do? Looks like it either loads the billing history or only the latest bill? Should it be a boolean in that case? I think we'll probably soon have a better way of handling historical billing cycles (cloudquery/plugin-sdk#569), so maybe we can update it to use that when it's ready.
| return err | ||
| } | ||
| if response.GetHttpStatus() != http.StatusOK { | ||
| return fmt.Errorf("httpcode %d", response.GetHttpStatus()) |
There was a problem hiding this comment.
We may want to handle retryable errors (like 5xx and 429), either here or in a generalized function. We don't have a perfect pattern for this yet, but see the Slack plugin for an example: https://github.com/cloudquery/cloudquery/blob/main/plugins/source/slack/resources/services/users/users_fetch.go#L20 and https://github.com/cloudquery/cloudquery/blob/main/plugins/source/slack/client/rate_limiting.go#L13
| @@ -0,0 +1,64 @@ | |||
| package models | |||
|
|
|||
| type BillOverview struct { | |||
There was a problem hiding this comment.
Mostly out of curiosity, what is the difference between these structs and the ones provided by the Alicloud SDK? Just wondering why (or whether) we need it
|
@hermanschaaf Thanks very much for your careful review. I will update the pull request later, thanks~ |
|
Hi @lshmouse 👋 Just wanted to update you: I spent a bit more time going through the code today, and started bringing it up-to-date with the latest plugin-sdk and best practices. I'll push the commits to your branch once they're ready and then we can merge, but there's still a bit more work to do which I'll pick up next week. My work-in-progress branch is here if you want to have a look or merge it into your branch sooner rather than later: https://github.com/cloudquery/cloudquery/tree/alicloud Hope you don't mind! |
hermanschaaf
left a comment
There was a problem hiding this comment.
Thanks again @lshmouse for this great contribution!
🤖 I have created a release *beep* *boop* --- ## 1.0.0 (2023-01-18) ### Features * **alicloud:** Add alicloud source plugin to sync bss and oss resources ([#6418](#6418)) ([a8ee1c9](a8ee1c9)) * **alicloud:** Add support for Alicloud ECS instances ([#6901](#6901)) ([c592fbe](c592fbe)) * **alicloud:** Prepare CI environment, fix PKs and column types, add docs ([#6907](#6907)) ([3696d1e](3696d1e)) ### Bug Fixes * **deps:** Update module github.com/cloudquery/plugin-sdk to v1.27.0 ([#6856](#6856)) ([545799b](545799b)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
|
@hermanschaaf I was blocked by something else in the past two weeks. Thanks very much for completing the patch~ |
Summary
#6416
Add the alicloud source plugin to sync bss and oss resources