Skip to content

Commit b201f8c

Browse files
authored
Collect metrics for a set of CG states ADDENDUM (#8)
1 parent 0e82c7c commit b201f8c

File tree

4 files changed

+15
-13
lines changed

4 files changed

+15
-13
lines changed

minion/consumer_group_offsets.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,9 @@ func (s *Service) ListAllConsumerGroupOffsetsAdminAPI(ctx context.Context) (map[
2323
return nil, fmt.Errorf("failed to list groupsRes: %w", err)
2424
}
2525
groupIDs := make([]string, len(groupsRes.AllowedGroups.Groups))
26-
groupStatesMap := s.Cfg.ConsumerGroups.GetAllowedConsumerGroupStates()
2726

2827
for i, group := range groupsRes.AllowedGroups.Groups {
29-
if len(groupStatesMap) == 0 {
30-
groupIDs[i] = group.Group
31-
} else {
32-
// only add group if it's state is allowed
33-
if _, ok := groupStatesMap[group.GroupState]; ok {
34-
groupIDs[i] = group.Group
35-
}
36-
}
28+
groupIDs[i] = group.Group
3729
}
3830

3931
return s.listConsumerGroupOffsetsBulk(ctx, groupIDs)

minion/describe_consumer_groups.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@ func (s *Service) listConsumerGroupsCached(ctx context.Context) (*GroupsInfo, er
3333
return nil, err
3434
}
3535
allowedGroups := make([]kmsg.ListGroupsResponseGroup, 0)
36+
3637
for i := range res.Groups {
37-
if s.IsGroupAllowed(res.Groups[i].Group) {
38+
if s.IsGroupAllowed(res.Groups[i].Group, res.Groups[i].GroupState) {
3839
allowedGroups = append(allowedGroups, res.Groups[i])
3940
}
4041
}

minion/storage.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ func (s *Storage) getNumberOfConsumedRecords() float64 {
108108
return s.consumedRecords.Load()
109109
}
110110

111-
func (s *Storage) getGroupOffsets(isAllowed func(groupName string) bool) map[string]map[string]map[int32]OffsetCommit {
111+
func (s *Storage) getGroupOffsets(isAllowed func(groupName string, groupState string) bool) map[string]map[string]map[int32]OffsetCommit {
112112
// Offsets by group, topic, partition
113113
offsetsByGroup := make(map[string]map[string]map[int32]OffsetCommit)
114114

@@ -121,7 +121,7 @@ func (s *Storage) getGroupOffsets(isAllowed func(groupName string) bool) map[str
121121
for _, offset := range offsets {
122122
val := offset.(OffsetCommit)
123123

124-
if !isAllowed(val.Key.Group) {
124+
if !isAllowed(val.Key.Group, "") {
125125
continue
126126
}
127127

minion/utils.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"strings"
77
)
88

9-
func (s *Service) IsGroupAllowed(groupName string) bool {
9+
func (s *Service) IsGroupAllowed(groupName string, groupState string) bool {
1010
isAllowed := false
1111
for _, regex := range s.AllowedGroupIDsExpr {
1212
if regex.MatchString(groupName) {
@@ -21,6 +21,15 @@ func (s *Service) IsGroupAllowed(groupName string) bool {
2121
break
2222
}
2323
}
24+
25+
if isAllowed && groupState != "" {
26+
groupStatesMap := s.Cfg.ConsumerGroups.GetAllowedConsumerGroupStates()
27+
if len(groupStatesMap) > 0 {
28+
if _, ok := groupStatesMap[groupState]; !ok {
29+
isAllowed = false
30+
}
31+
}
32+
}
2433
return isAllowed
2534
}
2635

0 commit comments

Comments
 (0)