-
Notifications
You must be signed in to change notification settings - Fork 592
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
rpk Add Format Flags to topic's describe #23418
rpk Add Format Flags to topic's describe #23418
Conversation
323d353
to
5dd05ef
Compare
6e3bcd4
to
d87103f
Compare
76c3ba2
to
ac6b4f4
Compare
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 first commit in this PR needs to have
bazel run //:gazelle
run and the changes committed. -
Please wrap your commit messages at around 80 characters
List is working as intended. Everything is driven by the data and it flows through the various formats with formatting separate from the assembly of the data.
ac6b4f4
to
3c29b27
Compare
4929174
to
e60edbf
Compare
9fd2385
to
f5238f6
Compare
Retry command for Build#57318please wait until all jobs are finished before running the slash command
|
c9beeb2
to
dc9149c
Compare
Retry command for Build#57327please wait until all jobs are finished before running the slash command
|
dc9149c
to
904125a
Compare
Retry command for Build#57344please wait until all jobs are finished before running the slash command
|
904125a
to
239b623
Compare
Retry command for Build#58077please wait until all jobs are finished before running the slash command
|
Adds format flag to describe Supports JSON and YAML
239b623
to
60ca935
Compare
ducktape was retried in https://buildkite.com/redpanda/redpanda/builds/58482#01935040-d0f5-4a3b-ab3d-37f9e40d8ad5 |
Retry command for Build#58482please wait until all jobs are finished before running the slash command
|
non flaky failures in https://buildkite.com/redpanda/redpanda/builds/58482#0193505c-56e9-453d-833a-7e13dce0f6e3:
non flaky failures in https://buildkite.com/redpanda/redpanda/builds/58482#0193505c-56eb-4e3d-95ec-b6d05303e3f8:
|
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.
Leaving this here for reference, this is being continued on #24387
// By default, if neither are specified, we opt in to | ||
// the config section only. |
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.
Why remove this?
} else if len(topicArg) == 0 { | ||
out.Exit("did not match any topics, exiting.") |
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 is needed for regex, is there a reason to remove it?
if topic.Summary.Partitions > 0 { | ||
tw.PrintColumn("REPLICAS", topic.Summary.Replicas) | ||
} | ||
if topic.Summary.isErr { |
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.
We can avoid the additional field isErr
by just comparing topic.Sumary.Error != ""
reqResource.ResourceName = *topic.Topic | ||
req.Resources = append(req.Resources, reqResource) | ||
|
||
resp, err := req.RequestWith(context.Background(), cl) |
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.
resp, err := req.RequestWith(context.Background(), cl) | |
resp, err := req.RequestWith(cmd.Context(), cl) |
out.MaybeDie(err, "unable to request configs: %v", err) | ||
if len(resp.Resources) != 1 { | ||
out.Die("config response returned %d resources when we asked for 1", len(resp.Resources)) |
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.
For helper functions, it is better to return an error and avoid using out.MaybeDie
and out.Die
outside of the Run function.
if i < len(resp.Topics) { | ||
fmt.Println() | ||
var topicDescriptions []describedTopic | ||
for _, topic := range resp.Topics { |
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.
We should modify this so:
- If is text: only execute and print what's needed.
- If it's JSON, execute everything.
Right now it executes everything no matter which format it is, and then later figure out what to print. For Config, for example, we could be doing extra request without needing them:
# For example, this will trigger a GetConfig request but won't print anything.
$ rpk topic describe foo -p
|
||
func buildDescribeTopicConfig(configs []kmsg.DescribeConfigsResponseResourceConfig) (output []describeTopicConfig) { | ||
output = make([]describeTopicConfig, 0, len(configs)) | ||
for _, cfg := range configs { |
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.
We are missing sorting the configs
from the old code
return resp.Resources[0].Configs, err | ||
} | ||
|
||
func buildDescribeTopicConfig(configs []kmsg.DescribeConfigsResponseResourceConfig) (output []describeTopicConfig) { |
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.
func buildDescribeTopicConfig(configs []kmsg.DescribeConfigsResponseResourceConfig) (output []describeTopicConfig) { | |
func buildDescribeTopicConfig(configs []kmsg.DescribeConfigsResponseResourceConfig) ([]describeTopicConfig) { |
Since you still overwrite the zero value one line below.
if len(topicDescriptions) == 0 { | ||
out.Exit("[]") | ||
} |
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 shouldn't be an exit []
, we should pass an empty slice and down the line print it as expected per the requested format. []
is not a good response for text format.
} | ||
printDescribedTopics(summary, configs, partitions, topicDescriptions) | ||
out.MaybeDie(err, "unable to request topic metadata: %v", err) |
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 line doesn't belong here.
Continuing in #24387 |
Adds --format to rpk topic describe.
Backports Required
Release Notes
Improvements