Skip to content

feat(spec): Add source, destination String methods#609

Merged
kodiakhq[bot] merged 3 commits intocloudquery:mainfrom
erezrokah:feat/add_string_spec_source_dest
Jan 17, 2023
Merged

feat(spec): Add source, destination String methods#609
kodiakhq[bot] merged 3 commits intocloudquery:mainfrom
erezrokah:feat/add_string_spec_source_dest

Conversation

@erezrokah
Copy link
Copy Markdown
Member

@erezrokah erezrokah commented Jan 16, 2023

Summary

A user recently ran into some issues since they thought they used a newer version of a plugin, but actually used an old one.
This PR adds String() methods to specs so we can use them in logs/errors.

CLI PR cloudquery/cloudquery#6842


Use the following steps to ensure your PR is ready to be reviewed

  • Read the contribution guidelines 🧑‍🎓
  • Run go fmt to format your code 🖊
  • Lint your changes via golangci-lint run 🚨 (install golangci-lint here)
  • Update or add tests 🧪
  • Ensure the status checks below are successful ✅

@erezrokah erezrokah force-pushed the feat/add_string_spec_source_dest branch from a0bbabd to a2f5806 Compare January 16, 2023 13:17
@github-actions
Copy link
Copy Markdown

github-actions bot commented Jan 16, 2023

⏱️ Benchmark results

Comparing with 3d3f20f

  • DefaultConcurrencyDFS-2 resources/s: 11,062 ⬇️ 4.49% decrease vs. 3d3f20f
  • DefaultConcurrencyRoundRobin-2 resources/s: 12,322 ⬆️ 2.65% increase vs. 3d3f20f
  • Glob-2 ns/op: 159.4 ⬆️ 1.69% increase vs. 3d3f20f
  • TablesWithChildrenDFS-2 resources/s: 28,967 ⬇️ 3.70% decrease vs. 3d3f20f
  • TablesWithChildrenRoundRobin-2 resources/s: 28,397 ⬆️ 4.28% increase vs. 3d3f20f
  • TablesWithRateLimitingDFS-2 resources/s: 28.31 ⬇️ 0.14% decrease vs. 3d3f20f
  • TablesWithRateLimitingRoundRobin-2 resources/s: 856.3 ⬆️ 1.21% increase vs. 3d3f20f
  • BufferedScanner-2 ns/op: 10.01 ⬆️ 6.26% increase vs. 3d3f20f
  • LogReader-2 ns/op: 30.85 ⬆️ 0.06% increase vs. 3d3f20f

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.

String is a saved method in Go and usually means that it stringify the whole object. so let's say if we use fmt.Printf(spec) this will now print the version instead of the string.

Can we just use VersionString method for this?

@erezrokah
Copy link
Copy Markdown
Member Author

String is a saved method in Go and usually means that it stringify the whole object. so let's say if we use fmt.Printf(spec) this will now print the version instead of the string.

Isn't that what overriding String() is for? To provide your own representation of how a struct will be printed?
It doesn't print only the version, it prints the name + version or name + path + version.

Can we just use VersionString method for this?

Using String() is useful for that exact reason. Formatting functions will use that implicitly. Also our logger has a Stringer function:
https://github.com/cloudquery/cloudquery/pull/6842/files#diff-ca3888a7ad618b67068e6b20ecb264fe87bb19554e6e8b62a13f8b5ce540f431R24

We can have a dedicated method, but that means we have to call it before passing the spec to any method that does formatting. That's especially clunky for arrays as you'll need to iterate over the array and call the method per item

@yevgenypats
Copy link
Copy Markdown
Contributor

yevgenypats commented Jan 16, 2023

String is a saved method in Go and usually means that it stringify the whole object. so let's say if we use fmt.Printf(spec) this will now print the version instead of the string.

Isn't that what overriding String() is for? To provide your own representation of how a struct will be printed? It doesn't print only the version, it prints the name + version or name + path + version.

Can we just use VersionString method for this?

Using String() is useful for that exact reason. Formatting functions will use that implicitly. Also our logger has a Stringer function: https://github.com/cloudquery/cloudquery/pull/6842/files#diff-ca3888a7ad618b67068e6b20ecb264fe87bb19554e6e8b62a13f8b5ce540f431R24

We can have a dedicated method, but that means we have to call it before passing the spec to any method that does formatting. That's especially clunky for arrays as you'll need to iterate over the array and call the method per item

String is a saved method in Go and usually means that it stringify the whole object. so let's say if we use fmt.Printf(spec) this will now print the version instead of the string.

Isn't that what overriding String() is for? To provide your own representation of how a struct will be printed? It doesn't print only the version, it prints the name + version or name + path + version.

Can we just use VersionString method for this?

Using String() is useful for that exact reason. Formatting functions will use that implicitly. Also our logger has a Stringer function: https://github.com/cloudquery/cloudquery/pull/6842/files#diff-ca3888a7ad618b67068e6b20ecb264fe87bb19554e6e8b62a13f8b5ce540f431R24

We can have a dedicated method, but that means we have to call it before passing the spec to any method that does formatting. That's especially clunky for arrays as you'll need to iterate over the array and call the method per item

I don't think this is what we want or at least for me it was quite confusing as I would assume String function will return some kind of json or yaml representation of the whole spec and not the pat@version. I would prefer to have an explicit Version or PathVersionString then something implicit that we will have hard time changing in case we do want String and then we will have to have a function name FullString (so prefer it the other way around)

@erezrokah
Copy link
Copy Markdown
Member Author

I don't think this is what we want or at least for me it was quite confusing as I would assume String function will return some kind of json or yaml representation of the whole spec and not the pat@version. I would prefer to have an explicit Version or PathVersionString then something implicit that we will have hard time changing in case we do want String and then we will have to have a function name FullString (so prefer it the other way around)

Cool, got it. I'll make the function explicit

@erezrokah
Copy link
Copy Markdown
Member Author

Done in 734f49c cc @yevgenypats

@erezrokah erezrokah requested a review from yevgenypats January 17, 2023 08:42
@kodiakhq kodiakhq bot merged commit 604b9ef into cloudquery:main Jan 17, 2023
kodiakhq bot pushed a commit that referenced this pull request Jan 17, 2023
🤖 I have created a release *beep* *boop*
---


## [1.27.0](v1.26.0...v1.27.0) (2023-01-17)


### Features

* **spec:** Add source, destination String methods ([#609](#609)) ([604b9ef](604b9ef))

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

3 participants