Skip to content

Commit ef96689

Browse files
committed
group/describe: add --no-members and --topic flags
allow more fine grained output
1 parent cc81524 commit ef96689

File tree

1 file changed

+58
-37
lines changed

1 file changed

+58
-37
lines changed

cmd/kaf/group.go

+58-37
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ var (
3030
flagPeekBefore int64
3131
flagPeekAfter int64
3232
flagPeekTopics []string
33+
34+
flagNoMembers bool
35+
flagDescribeTopics []string
3336
)
3437

3538
func init() {
@@ -48,6 +51,9 @@ func init() {
4851
groupPeekCmd.Flags().Int32SliceVarP(&flagPeekPartitions, "partitions", "p", []int32{}, "Partitions to peek from")
4952
groupPeekCmd.Flags().Int64VarP(&flagPeekBefore, "before", "B", 0, "Number of messages to peek before current offset")
5053
groupPeekCmd.Flags().Int64VarP(&flagPeekAfter, "after", "A", 0, "Number of messages to peek after current offset")
54+
55+
groupDescribeCmd.Flags().BoolVar(&flagNoMembers, "no-members", false, "Hide members section of the output")
56+
groupDescribeCmd.Flags().StringSliceVarP(&flagDescribeTopics, "topic", "t", []string{}, "topics to display for the group. defaults to all topics.")
5157
}
5258

5359
const (
@@ -470,6 +476,18 @@ var groupDescribeCmd = &cobra.Command{
470476
}
471477

472478
for topic, partitions := range offsetAndMetadata.Blocks {
479+
if len(flagDescribeTopics) > 0 {
480+
var found bool
481+
for _, topicToShow := range flagDescribeTopics {
482+
if topic == topicToShow {
483+
found = true
484+
}
485+
}
486+
487+
if !found {
488+
continue
489+
}
490+
}
473491
fmt.Fprintf(w, "\t%v:\n", topic)
474492
fmt.Fprintf(w, "\t\tPartition\tGroup Offset\tHigh Watermark\tLag\tMetadata\t\n")
475493
fmt.Fprintf(w, "\t\t---------\t------------\t--------------\t---\t--------\n")
@@ -499,55 +517,58 @@ var groupDescribeCmd = &cobra.Command{
499517
fmt.Fprintf(w, "\t\tTotal\t%d\t\t%d\t\n", offsetSum, lagSum)
500518
}
501519

502-
fmt.Fprintf(w, "Members:\t")
503-
504-
w.Flush()
505-
w.Init(outWriter, tabwriterMinWidthNested, 4, 2, tabwriterPadChar, tabwriterFlags)
520+
if !flagNoMembers {
506521

507-
fmt.Fprintln(w)
508-
for _, member := range group.Members {
509-
fmt.Fprintf(w, "\t%v:\n", member.ClientId)
510-
fmt.Fprintf(w, "\t\tHost:\t%v\n", member.ClientHost)
522+
fmt.Fprintf(w, "Members:\t")
511523

512-
assignment, err := member.GetMemberAssignment()
513-
if err != nil || assignment == nil {
514-
continue
515-
}
524+
w.Flush()
525+
w.Init(outWriter, tabwriterMinWidthNested, 4, 2, tabwriterPadChar, tabwriterFlags)
516526

517-
fmt.Fprintf(w, "\t\tAssignments:\n")
527+
fmt.Fprintln(w)
528+
for _, member := range group.Members {
529+
fmt.Fprintf(w, "\t%v:\n", member.ClientId)
530+
fmt.Fprintf(w, "\t\tHost:\t%v\n", member.ClientHost)
518531

519-
fmt.Fprintf(w, "\t\t Topic\tPartitions\t\n")
520-
fmt.Fprintf(w, "\t\t -----\t----------\t")
532+
assignment, err := member.GetMemberAssignment()
533+
if err != nil || assignment == nil {
534+
continue
535+
}
521536

522-
for topic, partitions := range assignment.Topics {
523-
fmt.Fprintf(w, "\n\t\t %v\t%v\t", topic, partitions)
524-
}
537+
fmt.Fprintf(w, "\t\tAssignments:\n")
525538

526-
metadata, err := member.GetMemberMetadata()
527-
if err != nil {
528-
fmt.Fprintf(w, "\n")
529-
continue
530-
}
539+
fmt.Fprintf(w, "\t\t Topic\tPartitions\t\n")
540+
fmt.Fprintf(w, "\t\t -----\t----------\t")
531541

532-
decodedUserData, err := tryDecodeUserData(group.Protocol, metadata.UserData)
533-
if err != nil {
534-
if IsASCIIPrintable(string(metadata.UserData)) {
535-
fmt.Fprintf(w, "\f\t\tMetadata:\t%v\n", string(metadata.UserData))
536-
} else {
542+
for topic, partitions := range assignment.Topics {
543+
fmt.Fprintf(w, "\n\t\t %v\t%v\t", topic, partitions)
544+
}
537545

538-
fmt.Fprintf(w, "\f\t\tMetadata:\t%v\n", base64.StdEncoding.EncodeToString(metadata.UserData))
546+
metadata, err := member.GetMemberMetadata()
547+
if err != nil {
548+
fmt.Fprintf(w, "\n")
549+
continue
539550
}
540-
} else {
541-
switch d := decodedUserData.(type) {
542-
case streams.SubscriptionInfo:
543-
fmt.Fprintf(w, "\f\t\tMetadata:\t\n")
544-
fmt.Fprintf(w, "\t\t UUID:\t0x%v\n", hex.EncodeToString(d.UUID))
545-
fmt.Fprintf(w, "\t\t UserEndpoint:\t%v\n", d.UserEndpoint)
551+
552+
decodedUserData, err := tryDecodeUserData(group.Protocol, metadata.UserData)
553+
if err != nil {
554+
if IsASCIIPrintable(string(metadata.UserData)) {
555+
fmt.Fprintf(w, "\f\t\tMetadata:\t%v\n", string(metadata.UserData))
556+
} else {
557+
558+
fmt.Fprintf(w, "\f\t\tMetadata:\t%v\n", base64.StdEncoding.EncodeToString(metadata.UserData))
559+
}
560+
} else {
561+
switch d := decodedUserData.(type) {
562+
case streams.SubscriptionInfo:
563+
fmt.Fprintf(w, "\f\t\tMetadata:\t\n")
564+
fmt.Fprintf(w, "\t\t UUID:\t0x%v\n", hex.EncodeToString(d.UUID))
565+
fmt.Fprintf(w, "\t\t UserEndpoint:\t%v\n", d.UserEndpoint)
566+
}
546567
}
547-
}
548568

549-
fmt.Fprintf(w, "\n")
569+
fmt.Fprintf(w, "\n")
550570

571+
}
551572
}
552573

553574
w.Flush()

0 commit comments

Comments
 (0)