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

remotetool: add --json output #533

Merged
merged 5 commits into from
Feb 16, 2024

Conversation

ola-rozenfeld
Copy link
Contributor

Followup to #532

This does the simplest thing possible for now -- we can always add more keys by creating a custom struct that we return from all tool operations, and marshalling that as json.

log.Exitf("error uploading directory for path %s: %v", getPathFlag(), err)
}
if *jsonOutput {
d, _ := json.Marshal(map[string]string{"digest": dg.String()})
Copy link

Choose a reason for hiding this comment

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

How hard would it be to add the cache hit rate and more metadata? In isolated I had included the individual file sizes as a delta-coded integer list. It was really sweet to create an histogram while packing the data as efficiently as possible; https://chromium.googlesource.com/infra/luci/luci-go/+/c364d2ae0a1c94014db11ff581ae7c9fa2ba1e3e/common/isolated/large.go
That said, sums and percentiles are probably sufficient.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not too hard -- PTAL.

Copy link

@maruel maruel left a comment

Choose a reason for hiding this comment

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

Thanks!

go/pkg/tool/tool.go Outdated Show resolved Hide resolved
Copy link

@maruel maruel 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 with two minor code movement.

go/pkg/tool/tool.go Show resolved Hide resolved
go/pkg/tool/tool.go Outdated Show resolved Hide resolved
Copy link

@maruel maruel left a comment

Choose a reason for hiding this comment

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

still lgtm (I can't resolve comments)

us, err := c.UploadDirectory(ctx, getPathFlag())
if *jsonOutput {
js, _ := json.MarshalIndent(us, "", " ")
fmt.Printf("%s\n", js)
Copy link

Choose a reason for hiding this comment

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

Did you mean to write to os.WriteFile(jsonOutput, js, 0o666) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't, but sure, if that's what you prefer :-) Done.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sorry to reopen this, but wouldn't printing to stdout accommodate pipes and files (via redirection) while writing to a file complicates the pipe workflow?

Copy link

Choose a reason for hiding this comment

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

The precedent in the posix way of doing this is to specific "-" as output to stdout. I think we'd get the best of both worlds.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Isn't that usually for tools that naturally expect files for in/out?

Copy link

Choose a reason for hiding this comment

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

Users want a tool to be composable. Since remotetool sends its status update to stderr and/or a file, I agree it is possible to use stdout to get the data. While in many case it's great, sometimes the user may want to not take a chance and use a named file instead. For example curl will output to stdout by default but may redirect to the user's choosing with --output and associated flags. Exceptions to that are use case where incrementally of the processing is needed so they do not offer the option to write to a file. A great example is go test -json where the user will want to process a list of json objects.

Copy link

Choose a reason for hiding this comment

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

To be clear, especially that I commented a lot here, I don't have a strong opinion and I'm fine with whatever @ola-rozenfeld or @mrahs prefers. If you prefer a bool -json flag it's okay too.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks for taking the time to bounce ideas! No strong opinions here either. json=- (which can be supported later) or -json works for me.

Ola, let me know if you're ready to merge and I'll hit the button.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, added support for "json=-" for stdout. That's it, should be ready to merge.
Thank you Anas and Marc Antoine for the quick reviews!

go/pkg/tool/tool.go Show resolved Hide resolved
go/pkg/tool/tool.go Outdated Show resolved Hide resolved
@mrahs mrahs merged commit 8756fbc into bazelbuild:master Feb 16, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants