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

Feature Request: Add regex filtering to topic like we do in groups. #72

Merged
merged 2 commits into from
Jun 18, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion group.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type groupCmd struct {
brokers []string
group string
filter *regexp.Regexp
tfilter *regexp.Regexp
topic string
partitions []int32
reset int64
Expand Down Expand Up @@ -75,7 +76,12 @@ func (cmd *groupCmd) run(args []string) {

topics := []string{cmd.topic}
if cmd.topic == "" {
topics = cmd.fetchTopics()
topics = []string{}
for _, t := range cmd.fetchTopics() {
if cmd.tfilter.MatchString(t) {
topics = append(topics, t)
}
}
}
fmt.Fprintf(os.Stderr, "found %v topics\n", len(topics))

Expand Down Expand Up @@ -362,6 +368,10 @@ func (cmd *groupCmd) parseArgs(as []string) {
failf("filter regexp invalid err=%v", err)
}

if cmd.tfilter, err = regexp.Compile(args.tfilter); err != nil {
failf("tfilter regexp invalid err=%v", err)
}

if args.reset != "" && (args.topic == "" || args.group == "") {
failf("group and topic are required to reset offsets.")
}
Expand Down Expand Up @@ -406,6 +416,7 @@ type groupArgs struct {
partitions string
group string
filter string
tfilter string
reset string
verbose bool
pretty bool
Expand All @@ -420,6 +431,7 @@ func (cmd *groupCmd) parseFlags(as []string) groupArgs {
flags.StringVar(&args.brokers, "brokers", "", "Comma separated list of brokers. Port defaults to 9092 when omitted (defaults to localhost:9092).")
flags.StringVar(&args.group, "group", "", "Consumer group name.")
flags.StringVar(&args.filter, "filter", "", "Regex to filter groups.")
flags.StringVar(&args.tfilter, "tfilter", "", "Regex to filter topics.")
Copy link
Owner

Choose a reason for hiding this comment

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

@michaelritsema i'd prefer a more explicit flag & var name. e.g. filter-topic and filter-group - what do you think?

flags.StringVar(&args.reset, "reset", "", "Target offset to reset for consumer group (newest, oldest, or specific offset)")
flags.BoolVar(&args.verbose, "verbose", false, "More verbose logging to stderr.")
flags.BoolVar(&args.pretty, "pretty", true, "Control output pretty printing.")
Expand Down