-
Notifications
You must be signed in to change notification settings - Fork 659
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[admin] Add consumer group bindings for KIP 222, 518, 396 (partial) a…
…nd DeleteConsumerGroups (#923) Implement ListConsumerGroups, DescribeConsumerGroups, ListConsumerGroupOffsets (KIP-222), DeleteConsumerGroups, AlterConsumerGroupOffsets (KIP-396), Allow listing consumer groups per state (KIP-518). Co-authored-by: Milind L <[email protected]> Co-authored-by: Santwana Verma <[email protected]>
- Loading branch information
1 parent
9e04388
commit f56f3d2
Showing
12 changed files
with
2,132 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
examples/admin_alter_consumer_group_offsets/admin_alter_consumer_group_offsets.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/** | ||
* Copyright 2022 Confluent Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
// Alter consumer group offsets | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
"strconv" | ||
"time" | ||
|
||
"github.com/confluentinc/confluent-kafka-go/kafka" | ||
) | ||
|
||
func main() { | ||
args := os.Args | ||
|
||
if len(args) < 6 { | ||
fmt.Fprintf(os.Stderr, | ||
"Usage: %s <bootstrap_servers> <group_id> "+ | ||
"<topic1> <partition1> <offset1> [<topic2> <partition2> <offset2> ...]\n", | ||
args[0]) | ||
os.Exit(1) | ||
} | ||
|
||
// Create new AdminClient. | ||
ac, err := kafka.NewAdminClient(&kafka.ConfigMap{ | ||
"bootstrap.servers": args[1], | ||
}) | ||
if err != nil { | ||
fmt.Printf("Failed to create Admin client: %s\n", err) | ||
os.Exit(1) | ||
} | ||
defer ac.Close() | ||
|
||
var partitions []kafka.TopicPartition | ||
for i := 3; i+2 < len(args); i += 3 { | ||
partition, err := strconv.ParseInt(args[i+1], 10, 32) | ||
if err != nil { | ||
panic(err) | ||
} | ||
offset, err := strconv.ParseUint(args[i+2], 10, 64) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
partitions = append(partitions, kafka.TopicPartition{ | ||
Topic: &args[i], | ||
Partition: int32(partition), | ||
Offset: kafka.Offset(offset), | ||
}) | ||
} | ||
|
||
gps := []kafka.ConsumerGroupTopicPartitions{ | ||
{ | ||
Group: args[2], | ||
Partitions: partitions, | ||
}, | ||
} | ||
|
||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*30) | ||
defer cancel() | ||
|
||
res, err := ac.AlterConsumerGroupOffsets(ctx, gps) | ||
if err != nil { | ||
fmt.Printf("Failed to alter consumer group offsets: %s\n", err) | ||
os.Exit(1) | ||
} | ||
|
||
fmt.Printf("AlterConsumerGroupOffsets result: %+v\n", res) | ||
} |
68 changes: 68 additions & 0 deletions
68
examples/admin_delete_consumer_groups/admin_delete_consumer_groups.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/** | ||
* Copyright 2022 Confluent Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
// Delete consumer group | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
"strconv" | ||
"time" | ||
|
||
"github.com/confluentinc/confluent-kafka-go/kafka" | ||
) | ||
|
||
func main() { | ||
args := os.Args | ||
|
||
if len(args) < 4 { | ||
fmt.Fprintf(os.Stderr, | ||
"Usage: %s <bootstrap_servers> <request_timeout_sec> <group1> [<group2> ...]\n", args[0]) | ||
os.Exit(1) | ||
} | ||
|
||
// Create new AdminClient. | ||
ac, err := kafka.NewAdminClient(&kafka.ConfigMap{ | ||
"bootstrap.servers": args[1], | ||
}) | ||
if err != nil { | ||
fmt.Printf("Failed to create Admin client: %s\n", err) | ||
os.Exit(1) | ||
} | ||
defer ac.Close() | ||
|
||
timeoutSec, err := strconv.Atoi(args[2]) | ||
if err != nil { | ||
fmt.Printf("Failed to parse timeout: %s\n", err) | ||
os.Exit(1) | ||
} | ||
|
||
groups := args[3:] | ||
|
||
ctx, cancel := context.WithTimeout(context.Background(), time.Minute) | ||
defer cancel() | ||
|
||
res, err := ac.DeleteConsumerGroups(ctx, groups, | ||
kafka.SetAdminRequestTimeout(time.Duration(timeoutSec)*time.Second)) | ||
if err != nil { | ||
fmt.Printf("Failed to delete groups: %s\n", err) | ||
os.Exit(1) | ||
} | ||
|
||
fmt.Printf("DeleteConsumerGroups result: %+v\n", res) | ||
} |
72 changes: 72 additions & 0 deletions
72
examples/admin_describe_consumer_groups/admin_describe_consumer_groups.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/** | ||
* Copyright 2022 Confluent Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
// Describe consumer groups | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
"time" | ||
|
||
"github.com/confluentinc/confluent-kafka-go/kafka" | ||
) | ||
|
||
func main() { | ||
if len(os.Args) < 3 { | ||
fmt.Fprintf( | ||
os.Stderr, | ||
"Usage: %s <bootstrap-servers> <group1> [<group2> ...]\n", | ||
os.Args[0]) | ||
os.Exit(1) | ||
} | ||
|
||
bootstrapServers := os.Args[1] | ||
groups := os.Args[2:] | ||
|
||
// Create a new AdminClient. | ||
a, err := kafka.NewAdminClient(&kafka.ConfigMap{"bootstrap.servers": bootstrapServers}) | ||
if err != nil { | ||
fmt.Printf("Failed to create Admin client: %s\n", err) | ||
os.Exit(1) | ||
} | ||
defer a.Close() | ||
|
||
// Call DescribeConsumerGroups. | ||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*30) | ||
defer cancel() | ||
describeGroupsResult, err := a.DescribeConsumerGroups(ctx, groups) | ||
if err != nil { | ||
fmt.Printf("Failed to describe groups: %s\n", err) | ||
os.Exit(1) | ||
} | ||
|
||
// Print results | ||
fmt.Printf("A total of %d consumer group(s) described:\n\n", | ||
len(describeGroupsResult.ConsumerGroupDescriptions)) | ||
for _, g := range describeGroupsResult.ConsumerGroupDescriptions { | ||
fmt.Printf("GroupId: %s\n"+ | ||
"Error: %s\n"+ | ||
"IsSimpleConsumerGroup: %v\n"+ | ||
"PartitionAssignor: %s\n"+ | ||
"State: %s\n"+ | ||
"Coordinator: %+v\n"+ | ||
"Members: %+v\n\n", | ||
g.GroupID, g.Error, g.IsSimpleConsumerGroup, g.PartitionAssignor, | ||
g.State, g.Coordinator, g.Members) | ||
} | ||
} |
89 changes: 89 additions & 0 deletions
89
examples/admin_list_consumer_group_offsets/admin_list_consumer_group_offsets.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/** | ||
* Copyright 2022 Confluent Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
// List consumer group offsets | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
"strconv" | ||
"time" | ||
|
||
"github.com/confluentinc/confluent-kafka-go/kafka" | ||
) | ||
|
||
func main() { | ||
args := os.Args | ||
|
||
if len(args) < 6 { | ||
fmt.Fprintf(os.Stderr, | ||
"Usage: %s <bootstrap_servers> <group_id> <require_stable> "+ | ||
"<topic1> <partition1> [<topic2> <partition2> .... ]\n", args[0]) | ||
os.Exit(1) | ||
} | ||
|
||
requireStable, err := strconv.ParseBool(args[3]) | ||
if err != nil { | ||
fmt.Printf( | ||
"Failed to parse value of require_stable %s: %s\n", args[3], err) | ||
os.Exit(1) | ||
} | ||
|
||
// Create new AdminClient. | ||
ac, err := kafka.NewAdminClient(&kafka.ConfigMap{ | ||
"bootstrap.servers": args[1], | ||
}) | ||
if err != nil { | ||
fmt.Printf("Failed to create Admin client: %s\n", err) | ||
os.Exit(1) | ||
} | ||
defer ac.Close() | ||
|
||
var partitions []kafka.TopicPartition | ||
for i := 4; i+1 < len(args); i += 2 { | ||
partition, err := strconv.ParseInt(args[i+1], 10, 32) | ||
if err != nil { | ||
fmt.Printf("Failed to parse partition %s: %s\n", args[i+1], err) | ||
os.Exit(1) | ||
} | ||
|
||
partitions = append(partitions, kafka.TopicPartition{ | ||
Topic: &args[i], | ||
Partition: int32(partition), | ||
}) | ||
} | ||
|
||
gps := []kafka.ConsumerGroupTopicPartitions{ | ||
{ | ||
Group: args[2], | ||
Partitions: partitions, | ||
}, | ||
} | ||
|
||
ctx, cancel := context.WithTimeout(context.Background(), time.Minute) | ||
defer cancel() | ||
|
||
res, err := ac.ListConsumerGroupOffsets( | ||
ctx, gps, kafka.SetAdminRequireStableOffsets(requireStable)) | ||
if err != nil { | ||
fmt.Printf("Failed to list consumer group offsets %s\n", err) | ||
os.Exit(1) | ||
} | ||
|
||
fmt.Printf("ListConsumerGroupOffset result: %+v\n", res) | ||
} |
Oops, something went wrong.