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

bucket inspect: Adds csv, tsv printer for inspect command #4228

Merged
merged 10 commits into from Nov 8, 2021

Conversation

someshkoli
Copy link
Contributor

@someshkoli someshkoli commented May 12, 2021

Signed-off-by: someshkoli kolisomesh27@gmail.com

  • I added CHANGELOG entry for this change.
  • Change is not relevant to the end user.

Changes

Adds csv, tsv printer methods to print block metadata table in csv and tsv format respectively.

Further work:

  • add json output (decide format)

Closes: #4180

Verification

unit tests needs to be added

Copy link
Member

@wiardvanrij wiardvanrij left a comment

Choose a reason for hiding this comment

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

Thanks for picking this up, awesome 👍

This is just my review/thought;
It's actually really smart and clever, but somewhat hard to follow/read

My initial review would be; what about just passing the *output into the func, like we do with *sortBy and then do a switch compare (default to table).
Then make a sort of "factory"? I.e. printer.Print(data) where printer is the instantiated type of printer depending on the output type?

LMK if this make sense :p

edit:

Example:

func (t ResolverType) ToResolver(logger log.Logger) ipLookupResolver {

@someshkoli
Copy link
Contributor Author

Thanks for picking this up, awesome

This is just my review/thought;
It's actually really smart and clever, but somewhat hard to follow/read

My initial review would be; what about just passing the *output into the func, like we do with *sortBy and then do a switch compare (default to table).
Then make a sort of "factory"? I.e. printer.Print(data) where printer is the instantiated type of printer depending on the output type?

LMK if this make sense :p

Yeah it does make sense, I initially thought of making an interface for diff printers along with their configs (TSV could have diff tab lengths etc ) but then doubted if i'm over engineering it....

@wiardvanrij
Copy link
Member

Thanks for picking this up, awesome
This is just my review/thought;
It's actually really smart and clever, but somewhat hard to follow/read
My initial review would be; what about just passing the *output into the func, like we do with *sortBy and then do a switch compare (default to table).
Then make a sort of "factory"? I.e. printer.Print(data) where printer is the instantiated type of printer depending on the output type?
LMK if this make sense :p

Yeah it does make sense, I initially thought of making an interface for diff printers along with their configs (TSV could have diff tab lengths etc ) but then doubted if i'm over engineering it....

That is actually a fair point!
I think it would help with readability though, yet you are right that this functionality is between the lines of over-engineering or not. Regardless, it looks good. If you have any doubts, don't hesitate to ask for more input on slack or something 👍

@someshkoli
Copy link
Contributor Author

someshkoli commented May 12, 2021

Thanks for picking this up, awesome
This is just my review/thought;
It's actually really smart and clever, but somewhat hard to follow/read
My initial review would be; what about just passing the *output into the func, like we do with *sortBy and then do a switch compare (default to table).
Then make a sort of "factory"? I.e. printer.Print(data) where printer is the instantiated type of printer depending on the output type?
LMK if this make sense :p

Yeah it does make sense, I initially thought of making an interface for diff printers along with their configs (TSV could have diff tab lengths etc ) but then doubted if i'm over engineering it....

That is actually a fair point!
I think it would help with readability though, yet you are right that this functionality is between the lines of over-engineering or not. Regardless, it looks good. If you have any doubts, don't hesitate to ask for more input on slack or something

Yes, would be easier to decide if there are some other use cases too

Copy link

@matthiasr matthiasr left a comment

Choose a reason for hiding this comment

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

What do the outputs look like, can you show some examples? Do we need to worry about quoting at all, or does encoding/csv do the right thing?

@@ -272,6 +282,9 @@ func registerBucketInspect(app extkingpin.AppClause, objStoreConfig *extflag.Pat
Default("FROM", "UNTIL").Enums(inspectColumns...)
timeout := cmd.Flag("timeout", "Timeout to download metadata from remote storage").Default("5m").Duration()

output := cmd.Flag("output", "Output format for result. Currently supports table, cvs, and, tsv.").Default("table").String()

Choose a reason for hiding this comment

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

the sortBy flag seems to use enums to restrict the possible values, is this something that you could do here as well?

@@ -616,7 +636,56 @@ func registerBucketCleanup(app extkingpin.AppClause, objStoreConfig *extflag.Pat
})
}

func printTable(blockMetas []*metadata.Meta, selectorLabels labels.Labels, sortBy []string) error {
type tablePrinter func(t Table) error

Choose a reason for hiding this comment

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

I'm not sure about hardcoding the output to os.Stdout in all the functions. What do you think about passing an io.Writer into any tablePrinter?

Suggested change
type tablePrinter func(t Table) error
type tablePrinter func(w io.Writer, t Table) error

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, even I was sceptical about using stdout directly here.

@@ -436,6 +436,8 @@ Flags:
Path to YAML file that contains object store
configuration. See format details:
https://thanos.io/tip/thanos/storage.md/#configuration
--output="table" Output format for result. Currently supports table,
cvs, and, tsv.

Choose a reason for hiding this comment

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

Suggested change
cvs, and, tsv.
csv, and tsv.

Choose a reason for hiding this comment

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

or maybe make it "technical" and leave out the and altogether?

Suggested change
cvs, and, tsv.
csv, tsv.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

or maybe make it "technical" and leave out the and altogether?

this one

} else if opType == CSV {
return printBlockData(blockMetas, selectorLabels, *sortBy, printCSV)
} else {
return fmt.Errorf("Invalid output type %s.", *output)
Copy link
Member

Choose a reason for hiding this comment

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

Typically error messages start with a lower letter because they look properly then in case they get chained e.g. doing: Creating: linking: ... vs. doing: creating: linking: .... In fact, this case would be handled for you if you'd use enums as recommended previously

Copy link
Contributor Author

Choose a reason for hiding this comment

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

got it thanks. will keep in mind for future contributions

@someshkoli someshkoli force-pushed the feature/bucket-inspect-output branch from 758efcd to ae26d9e Compare May 13, 2021 18:10
@someshkoli
Copy link
Contributor Author

someshkoli commented May 13, 2021

What do the outputs look like, can you show some examples? Do we need to worry about quoting at all, or does encoding/csv do the right thing?

Here's the output
image

And yes encoding/csv is behaving as expected I guess. There are some inconsistencies in tab spacing and I'm not sure why...
Any ideas why it's happening?

@someshkoli someshkoli requested a review from GiedriusS May 14, 2021 09:35
@yeya24
Copy link
Contributor

yeya24 commented Jun 30, 2021

This looks good and I love it. Quick question, does it support outputting csv/tsv to a file? @someshkoli

@matthiasr
Copy link

What prevents you from redirecting it to a file like thanos bucket inspect … --output=csv > bucket.csv?

@someshkoli
Copy link
Contributor Author

This looks good and I love it. Quick question, does it support outputting csv/tsv to a file? @someshkoli

What prevents you from redirecting it to a file like thanos bucket inspect … --output=csv > bucket.csv?

++, there isn't much work to output it to a file but might be redundant

@GiedriusS
Copy link
Member

Is this still a draft?

@yeya24
Copy link
Contributor

yeya24 commented Jun 30, 2021

What prevents you from redirecting it to a file like thanos bucket inspect … --output=csv > bucket.csv?

@matthiasr I am thinking about the logger output. They are also written to stdout and will be mixed with the csv output I guess? An output file flag might be necessary.

@someshkoli
Copy link
Contributor Author

Is this still a draft?

Not really but tsv output is sort of inconsistent, didn't spend too much time on this, will check soon

@someshkoli someshkoli marked this pull request as ready for review July 5, 2021 15:42
Signed-off-by: someshkoli <kolisomesh27@gmail.com>
Signed-off-by: someshkoli <kolisomesh27@gmail.com>
Signed-off-by: someshkoli <kolisomesh27@gmail.com>
Signed-off-by: someshkoli <kolisomesh27@gmail.com>
Signed-off-by: someshkoli <kolisomesh27@gmail.com>
Signed-off-by: someshkoli <kolisomesh27@gmail.com>
Signed-off-by: someshkoli <kolisomesh27@gmail.com>
Signed-off-by: someshkoli <kolisomesh27@gmail.com>
@someshkoli someshkoli force-pushed the feature/bucket-inspect-output branch from a953792 to 639c8cc Compare July 5, 2021 15:44
@someshkoli
Copy link
Contributor Author

Is this still a draft?

Not really but tsv output is sort of inconsistent, didn't spend too much time on this, will check soon

sorry for delayed update
Not sure what this error is but while reading the output via machine code it works properly so ig we're good to go

@stale
Copy link

stale bot commented Sep 6, 2021

Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@stale stale bot added the stale label Sep 6, 2021
@stale stale bot closed this Sep 19, 2021
Copy link

@matthiasr matthiasr left a comment

Choose a reason for hiding this comment

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

This looks good to me. @yeya24 as far as I can see, the logger goes to stderr, so this is no problem – if you redirect stdout you still get logs to the terminal and the data goes to the file.

@GiedriusS GiedriusS reopened this Oct 8, 2021
@stale stale bot removed the stale label Oct 8, 2021
@yeya24
Copy link
Contributor

yeya24 commented Oct 8, 2021

This looks good to me. @yeya24 as far as I can see, the logger goes to stderr, so this is no problem – if you redirect stdout you still get logs to the terminal and the data goes to the file.

SGTM. @someshkoli Sorry for the delay. Can you do a rebase and then we can review and merge this?

@someshkoli
Copy link
Contributor Author

This looks good to me. @yeya24 as far as I can see, the logger goes to stderr, so this is no problem – if you redirect stdout you still get logs to the terminal and the data goes to the file.

SGTM. @someshkoli Sorry for the delay. Can you do a rebase and then we can review and merge this?

will update the pr in a day or two, a bit occupied lately

@yeya24
Copy link
Contributor

yeya24 commented Nov 8, 2021

@someshkoli I would like to continue this if you are busy with other work so please let me know 😄

@someshkoli
Copy link
Contributor Author

someshkoli commented Nov 8, 2021

@someshkoli I would like to continue this if you are busy with other work so please let me know smile

Will wrap this up, rebasing it. @yeya24 a review ?

@yeya24
Copy link
Contributor

yeya24 commented Nov 8, 2021

@someshkoli I would like to continue this if you are busy with other work so please let me know smile

Will wrap this up, rebasing it. @yeya24 a review ?

I don't think this works. Can you fix go build?

@someshkoli
Copy link
Contributor Author

@someshkoli I would like to continue this if you are busy with other work so please let me know smile

Will wrap this up, rebasing it. @yeya24 a review ?

I don't think this works. Can you fix go build?

Has become too old :""), ton of rebasing required. Moving this to a clean new PR

@yeya24
Copy link
Contributor

yeya24 commented Nov 8, 2021

@someshkoli Can you please also update the changelog?

@someshkoli
Copy link
Contributor Author

someshkoli commented Nov 8, 2021

@someshkoli Can you please also update the changelog?

@yeya24 Done👌

Copy link
Contributor

@yeya24 yeya24 left a comment

Choose a reason for hiding this comment

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

LGTM

@yeya24 yeya24 enabled auto-merge (squash) November 8, 2021 21:10
@yeya24 yeya24 merged commit dcbd1f7 into thanos-io:main Nov 8, 2021
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.

bucket inspect: support machine-readable output formats
5 participants