Skip to content

Commit

Permalink
topic: Optionally includes replica information per partition.
Browse files Browse the repository at this point in the history
  • Loading branch information
fgeller committed Mar 2, 2016
1 parent 16d0e7a commit e068a64
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions topic.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ type topicConfig struct {
filter *regexp.Regexp
partitions bool
leaders bool
replicas bool
args struct {
brokers string
filter string
partitions bool
leaders bool
replicas bool
}
}

Expand All @@ -31,10 +33,11 @@ type topic struct {
}

type partition struct {
Id int32 `json:"id"`
OldestOffset int64 `json:"oldestOffset"`
NewestOffset int64 `json:"newestOffset"`
Leader string `json:"leader,omitempty"`
Id int32 `json:"id"`
OldestOffset int64 `json:"oldestOffset"`
NewestOffset int64 `json:"newestOffset"`
Leader string `json:"leader,omitempty"`
Replicas []int32 `json:"replicas,omitempty"`
}

func topicCommand() command {
Expand All @@ -49,6 +52,7 @@ func init() {
topic.StringVar(&config.topic.args.brokers, "brokers", "localhost:9092", "Comma separated list of brokers. Port defaults to 9092 when omitted.")
topic.BoolVar(&config.topic.args.partitions, "partitions", false, "Include information per partition.")
topic.BoolVar(&config.topic.args.leaders, "leaders", false, "Include leader information per partition.")
topic.BoolVar(&config.topic.args.replicas, "replicas", false, "Include replica ids per partition.")
topic.StringVar(&config.topic.args.filter, "filter", "", "Regex to filter topics by name.")

topic.Usage = func() {
Expand Down Expand Up @@ -79,6 +83,7 @@ func topicParseArgs(args []string) {
config.topic.filter = re
config.topic.partitions = config.topic.args.partitions
config.topic.leaders = config.topic.args.leaders
config.topic.replicas = config.topic.args.replicas
}

func topicRun(closer chan struct{}) {
Expand Down Expand Up @@ -151,6 +156,14 @@ func readTopic(client sarama.Client, name string) (topic, error) {
np.Leader = b.Addr()
}

if config.topic.replicas {
rs, err := client.Replicas(name, p)
if err != nil {
return t, err
}
np.Replicas = rs
}

t.Partitions = append(t.Partitions, np)
}
}
Expand Down

0 comments on commit e068a64

Please sign in to comment.