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

rpk Add Format Flags to topic's describe #23418

Conversation

gene-redpanda
Copy link
Contributor

@gene-redpanda gene-redpanda commented Sep 21, 2024

Adds --format to rpk topic describe.

Backports Required

  • none - not a bug fix
  • none - this is a backport
  • none - issue does not exist in previous branches
  • none - papercut/not impactful enough to backport
  • v24.2.x
  • v24.1.x
  • v23.3.x

Release Notes

Improvements

  • Adds --format support to rpk topic describe

@gene-redpanda gene-redpanda force-pushed the format-flags-topic-list-detail branch 3 times, most recently from 323d353 to 5dd05ef Compare October 7, 2024 22:48
@gene-redpanda gene-redpanda marked this pull request as ready for review October 7, 2024 22:56
@gene-redpanda gene-redpanda force-pushed the format-flags-topic-list-detail branch 2 times, most recently from 6e3bcd4 to d87103f Compare October 7, 2024 22:57
src/go/rpk/pkg/cli/topic/list.go Outdated Show resolved Hide resolved
src/go/rpk/pkg/cli/topic/list.go Outdated Show resolved Hide resolved
src/go/rpk/pkg/cli/topic/list.go Outdated Show resolved Hide resolved
src/go/rpk/pkg/cli/topic/describe.go Outdated Show resolved Hide resolved
@gene-redpanda gene-redpanda force-pushed the format-flags-topic-list-detail branch 4 times, most recently from 76c3ba2 to ac6b4f4 Compare October 11, 2024 14:51
@r-vasquez r-vasquez self-requested a review October 11, 2024 14:58
Copy link
Member

@dotnwat dotnwat left a comment

Choose a reason for hiding this comment

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

  1. The first commit in this PR needs to have bazel run //:gazelle run and the changes committed.

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

src/go/rpk/pkg/cli/topic/list.go Outdated Show resolved Hide resolved
src/go/rpk/pkg/cli/topic/list.go Outdated Show resolved Hide resolved
@gene-redpanda gene-redpanda force-pushed the format-flags-topic-list-detail branch from ac6b4f4 to 3c29b27 Compare October 17, 2024 19:17
@gene-redpanda gene-redpanda changed the title Add Format Flags to topic's describe and list Add Format Flags to topic's describe Oct 17, 2024
@gene-redpanda gene-redpanda force-pushed the format-flags-topic-list-detail branch 2 times, most recently from 4929174 to e60edbf Compare October 21, 2024 19:16
@gene-redpanda gene-redpanda changed the title Add Format Flags to topic's describe rpk Add Format Flags to topic's describe Oct 22, 2024
@gene-redpanda gene-redpanda force-pushed the format-flags-topic-list-detail branch 6 times, most recently from 9fd2385 to f5238f6 Compare October 28, 2024 19:30
@vbotbuildovich
Copy link
Collaborator

vbotbuildovich commented Oct 29, 2024

Retry command for Build#57318

please wait until all jobs are finished before running the slash command

/ci-repeat 1
tests/rptest/transactions/tx_atomic_produce_consume_test.py::TxAtomicProduceConsumeTest.test_basic_tx_consumer_transform_produce@{"with_failures":true}

@gene-redpanda gene-redpanda force-pushed the format-flags-topic-list-detail branch from c9beeb2 to dc9149c Compare October 29, 2024 22:06
@vbotbuildovich
Copy link
Collaborator

vbotbuildovich commented Oct 30, 2024

Retry command for Build#57327

please wait until all jobs are finished before running the slash command

/ci-repeat 1
tests/rptest/transactions/tx_atomic_produce_consume_test.py::TxAtomicProduceConsumeTest.test_basic_tx_consumer_transform_produce@{"with_failures":true}

@gene-redpanda gene-redpanda force-pushed the format-flags-topic-list-detail branch from dc9149c to 904125a Compare October 30, 2024 03:05
@vbotbuildovich
Copy link
Collaborator

vbotbuildovich commented Oct 30, 2024

Retry command for Build#57344

please wait until all jobs are finished before running the slash command

/ci-repeat 1
tests/rptest/transactions/tx_atomic_produce_consume_test.py::TxAtomicProduceConsumeTest.test_basic_tx_consumer_transform_produce@{"with_failures":true}
tests/rptest/tests/idempotency_test.py::IdempotencyWriteCachingTest.test_idempotent_producers_write_caching

@gene-redpanda gene-redpanda force-pushed the format-flags-topic-list-detail branch from 904125a to 239b623 Compare November 14, 2024 19:13
@vbotbuildovich
Copy link
Collaborator

vbotbuildovich commented Nov 14, 2024

Retry command for Build#58077

please wait until all jobs are finished before running the slash command

/ci-repeat 1
tests/rptest/transactions/tx_atomic_produce_consume_test.py::TxAtomicProduceConsumeTest.test_basic_tx_consumer_transform_produce@{"with_failures":true}
tests/rptest/tests/raft_recovery_test.py::RaftRecoveryUpgradeTest.test_upgrade

Adds format flag to describe
Supports JSON and YAML
@redpanda-data redpanda-data deleted a comment from vbotbuildovich Nov 19, 2024
@redpanda-data redpanda-data deleted a comment from vbotbuildovich Nov 19, 2024
@redpanda-data redpanda-data deleted a comment from vbotbuildovich Nov 19, 2024
@redpanda-data redpanda-data deleted a comment from vbotbuildovich Nov 19, 2024
@redpanda-data redpanda-data deleted a comment from vbotbuildovich Nov 19, 2024
@redpanda-data redpanda-data deleted a comment from vbotbuildovich Nov 19, 2024
@redpanda-data redpanda-data deleted a comment from vbotbuildovich Nov 19, 2024
@redpanda-data redpanda-data deleted a comment from vbotbuildovich Nov 19, 2024
@redpanda-data redpanda-data deleted a comment from vbotbuildovich Nov 19, 2024
@redpanda-data redpanda-data deleted a comment from vbotbuildovich Nov 19, 2024
@redpanda-data redpanda-data deleted a comment from vbotbuildovich Nov 19, 2024
@redpanda-data redpanda-data deleted a comment from vbotbuildovich Nov 19, 2024
@r-vasquez r-vasquez force-pushed the format-flags-topic-list-detail branch from 239b623 to 60ca935 Compare November 21, 2024 18:30
@vbotbuildovich
Copy link
Collaborator

vbotbuildovich commented Nov 21, 2024

@vbotbuildovich
Copy link
Collaborator

vbotbuildovich commented Nov 21, 2024

Retry command for Build#58482

please wait until all jobs are finished before running the slash command

/ci-repeat 1
tests/rptest/transactions/tx_atomic_produce_consume_test.py::TxAtomicProduceConsumeTest.test_basic_tx_consumer_transform_produce@{"with_failures":true}
tests/rptest/tests/raft_recovery_test.py::RaftRecoveryUpgradeTest.test_upgrade
tests/rptest/tests/cluster_features_test.py::FeaturesNodeJoinTest.test_old_node_join

@vbotbuildovich
Copy link
Collaborator

vbotbuildovich commented Nov 21, 2024

non flaky failures in https://buildkite.com/redpanda/redpanda/builds/58482#0193505c-56e9-453d-833a-7e13dce0f6e3:

"rptest.tests.raft_recovery_test.RaftRecoveryUpgradeTest.test_upgrade"

non flaky failures in https://buildkite.com/redpanda/redpanda/builds/58482#0193505c-56eb-4e3d-95ec-b6d05303e3f8:

"rptest.tests.cluster_features_test.FeaturesNodeJoinTest.test_old_node_join"

Copy link
Contributor

@r-vasquez r-vasquez left a 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

Comment on lines -78 to -79
// By default, if neither are specified, we opt in to
// the config section only.
Copy link
Contributor

Choose a reason for hiding this comment

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

Why remove this?

Comment on lines -89 to -90
} else if len(topicArg) == 0 {
out.Exit("did not match any topics, exiting.")
Copy link
Contributor

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 {
Copy link
Contributor

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)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
resp, err := req.RequestWith(context.Background(), cl)
resp, err := req.RequestWith(cmd.Context(), cl)

Comment on lines +256 to +258
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))
Copy link
Contributor

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 {
Copy link
Contributor

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:

  1. If is text: only execute and print what's needed.
  2. 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 {
Copy link
Contributor

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) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
func buildDescribeTopicConfig(configs []kmsg.DescribeConfigsResponseResourceConfig) (output []describeTopicConfig) {
func buildDescribeTopicConfig(configs []kmsg.DescribeConfigsResponseResourceConfig) ([]describeTopicConfig) {

Since you still overwrite the zero value one line below.

Comment on lines +118 to +120
if len(topicDescriptions) == 0 {
out.Exit("[]")
}
Copy link
Contributor

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)
Copy link
Contributor

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.

@r-vasquez
Copy link
Contributor

Continuing in #24387

@r-vasquez r-vasquez closed this Dec 3, 2024
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.

4 participants