-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
bucket inspect: Adds csv, tsv printer for inspect command #4228
Conversation
There was a problem hiding this 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:
thanos/pkg/discovery/dns/provider.go
Line 43 in deb5998
func (t ResolverType) ToResolver(logger log.Logger) ipLookupResolver { |
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! |
Yes, would be easier to decide if there are some other use cases too |
There was a problem hiding this 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?
cmd/thanos/tools_bucket.go
Outdated
@@ -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() |
There was a problem hiding this comment.
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?
cmd/thanos/tools_bucket.go
Outdated
@@ -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 |
There was a problem hiding this comment.
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?
type tablePrinter func(t Table) error | |
type tablePrinter func(w io.Writer, t Table) error |
There was a problem hiding this comment.
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.
docs/components/tools.md
Outdated
@@ -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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cvs, and, tsv. | |
csv, and tsv. |
There was a problem hiding this comment.
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?
cvs, and, tsv. | |
csv, tsv. |
There was a problem hiding this comment.
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
cmd/thanos/tools_bucket.go
Outdated
} else if opType == CSV { | ||
return printBlockData(blockMetas, selectorLabels, *sortBy, printCSV) | ||
} else { | ||
return fmt.Errorf("Invalid output type %s.", *output) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
758efcd
to
ae26d9e
Compare
And yes encoding/csv is behaving as expected I guess. There are some inconsistencies in tab spacing and I'm not sure why... |
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 |
++, there isn't much work to output it to a file but might be redundant |
Is this still a draft? |
@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. |
Not really but tsv output is sort of inconsistent, didn't spend too much time on this, will check soon |
Signed-off-by: someshkoli <[email protected]>
Signed-off-by: someshkoli <[email protected]>
Signed-off-by: someshkoli <[email protected]>
Signed-off-by: someshkoli <[email protected]>
Signed-off-by: someshkoli <[email protected]>
Signed-off-by: someshkoli <[email protected]>
Signed-off-by: someshkoli <[email protected]>
Signed-off-by: someshkoli <[email protected]>
a953792
to
639c8cc
Compare
sorry for delayed update |
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. |
There was a problem hiding this 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.
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 |
@someshkoli I would like to continue this if you are busy with other work so please let me know 😄 |
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 |
2d18563
to
639c8cc
Compare
@someshkoli Can you please also update the changelog? |
cab9533
to
639c8cc
Compare
Signed-off-by: someshkoli <[email protected]>
@yeya24 Done👌 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Signed-off-by: someshkoli [email protected]
Changes
Adds csv, tsv printer methods to print block metadata table in csv and tsv format respectively.
Further work:
Closes: #4180
Verification
unit tests needs to be added