Skip to content

feat: Add option to plugin doc command to output tables as JSON#347

Merged
kodiakhq[bot] merged 10 commits intomainfrom
json-output-tables
Nov 16, 2022
Merged

feat: Add option to plugin doc command to output tables as JSON#347
kodiakhq[bot] merged 10 commits intomainfrom
json-output-tables

Conversation

@hermanschaaf
Copy link
Copy Markdown
Contributor

@hermanschaaf hermanschaaf commented Nov 4, 2022

Fixes #309

This adds a --format json option to the source plugin doc command, which allows all tables to be dumped as a single JSON file. This can then be further parsed with jq for various purposes (such as comparing two versions of a plugin to see what changed).

Example: List first 5 top-level tables of AWS plugin

./aws doc --format json .
$ cat __tables.json | jq -r '.[].name' | head -n 5
aws_accessanalyzer_analyzers
aws_acm_certificates
aws_apigateway_api_keys
aws_apigateway_client_certificates
aws_apigateway_domain_names

@github-actions github-actions bot added feat and removed feat labels Nov 6, 2022
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.

Sorry for the delayed review, forgot about it. It looks good. One nit and one question.

return string(s)
}

func (s SourceDocsFormat) Validate() error {
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 think this can be just an enum (https://github.com/cloudquery/plugin-sdk/blob/main/serve/source.go#L67) which already include the validation.

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 point, but I think the enum code is private to the serve package so I'll have to refactor a bit first.

}
}

type jsonTable struct {
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 think this is fine but can't we re-use the same tables definition that we already have? we also encode them to json or we want a different structure.

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 tried this initially, and if I recall correctly the issue I faced was that column type came out as an integer, which isn't very useful without the mappings. So I figured that it would be good to decouple the GRPC representation from the one we use here, but I could be convinced that we shouldn't do that, and figure out a way to turn the type to a string here instead?

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.

Yeah I don't have a good idea right now so maybe we can merge this as is and maybe fix later on if it becomes a maintains burden. But actually now that I think about it why the gRPC representation is not good ? especially if it's intended to be read by computers? Maybe we can have some flag that will marshal the Type in a different way.

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 think one use case for this is going to be outputting the schema in a different format than the markdown we support. Maybe a different markdown format, maybe HTML? But having a number for the type is not very useful then, you'd either need access to the plugin-sdk or copy-paste the list of constants to know how it maps to a string. I also think it's probably good if we can evolve the internal representations separately. We may even move away from JSON for internal communication purposes if it turns out to be a drag on performance, but we'd still want to keep this.

@yevgenypats
Copy link
Copy Markdown
Contributor

@hermanschaaf I think we can do just the enum and we can merge it/roll this out so user can use it.

@hermanschaaf
Copy link
Copy Markdown
Contributor Author

@yevgenypats Updated to use enums, PTAL

"is_primary_key": true
}
],
"relations": [
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.

Sorry for jumping late to this, but can we also have the relations at the top level? Might be easier to process it that way. For example if I was to get a list of all tables, I'll need to recurse into the JSON at the moment.

We can add a another property parent to link to the parent table, and keep it nil for top level ones, WDYT?

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, I was in two minds about it 🤔 I think having it flattened will be good for some use cases, and not-so-good for others. I'm fine with changing it to flattened though. @yevgenypats WDYT?

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.

Maybe we can have both?

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.

why not both

@kodiakhq kodiakhq bot merged commit c1b4240 into main Nov 16, 2022
@kodiakhq kodiakhq bot deleted the json-output-tables branch November 16, 2022 13:46
kodiakhq bot pushed a commit that referenced this pull request Nov 21, 2022
🤖 I have created a release *beep* *boop*
---


## [1.6.0](v1.5.3...v1.6.0) (2022-11-21)


### Features

* Add option to plugin doc command to output tables as JSON ([#347](#347)) ([c1b4240](c1b4240))
* Support ${file:./path} expansion in spec ([#418](#418)) ([58d7c44](58d7c44))


### Bug Fixes

* Fix Destination testing suite ([#417](#417)) ([4771efa](4771efa))
* Increase GRPC message size limit to 50MiB ([#419](#419)) ([a54c6ea](a54c6ea))

---
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: Ability to dump to supported tables by a plugin in a machine readable way

4 participants