@@ -16,13 +16,18 @@ type DescribeConsumerGroupsResponse struct {
16
16
Groups * kmsg.DescribeGroupsResponse
17
17
}
18
18
19
- func (s * Service ) listConsumerGroupsCached (ctx context.Context ) (* kmsg.ListGroupsResponse , error ) {
20
- key := "list-consumer-groups"
19
+ type GroupsInfo struct {
20
+ AllowedGroups * kmsg.ListGroupsResponse
21
+ AllGroupsCount int
22
+ }
23
+
24
+ func (s * Service ) listConsumerGroupsCached (ctx context.Context ) (* GroupsInfo , error ) {
25
+ keyAllowedGroups := "list-consumer-groups"
21
26
22
- if cachedRes , exists := s .getCachedItem (key ); exists {
23
- return cachedRes .(* kmsg. ListGroupsResponse ), nil
27
+ if cachedRes , exists := s .getCachedItem (keyAllowedGroups ); exists {
28
+ return cachedRes .(* GroupsInfo ), nil
24
29
}
25
- res , err , _ := s .requestGroup .Do (key , func () (interface {}, error ) {
30
+ groups , err , _ := s .requestGroup .Do (keyAllowedGroups , func () (interface {}, error ) {
26
31
res , err := s .listConsumerGroups (ctx )
27
32
if err != nil {
28
33
return nil , err
@@ -34,15 +39,19 @@ func (s *Service) listConsumerGroupsCached(ctx context.Context) (*kmsg.ListGroup
34
39
}
35
40
}
36
41
res .Groups = allowedGroups
37
- s .setCachedItem (key , res , 120 * time .Second )
42
+ groups := & GroupsInfo {
43
+ AllGroupsCount : len (res .Groups ),
44
+ AllowedGroups : res ,
45
+ }
46
+ s .setCachedItem (keyAllowedGroups , groups , 120 * time .Second )
38
47
39
- return res , nil
48
+ return groups , nil
40
49
})
41
50
if err != nil {
42
51
return nil , err
43
52
}
44
53
45
- return res .(* kmsg. ListGroupsResponse ), nil
54
+ return groups .(* GroupsInfo ), nil
46
55
}
47
56
48
57
func (s * Service ) listConsumerGroups (ctx context.Context ) (* kmsg.ListGroupsResponse , error ) {
@@ -59,14 +68,14 @@ func (s *Service) listConsumerGroups(ctx context.Context) (*kmsg.ListGroupsRespo
59
68
return res , nil
60
69
}
61
70
62
- func (s * Service ) DescribeConsumerGroups (ctx context.Context ) ([]DescribeConsumerGroupsResponse , error ) {
71
+ func (s * Service ) DescribeConsumerGroups (ctx context.Context ) ([]DescribeConsumerGroupsResponse , int , error ) {
63
72
listRes , err := s .listConsumerGroupsCached (ctx )
64
73
if err != nil {
65
- return nil , err
74
+ return nil , - 1 , err
66
75
}
67
76
68
- groupIDs := make ([]string , len (listRes .Groups ))
69
- for i , group := range listRes .Groups {
77
+ groupIDs := make ([]string , len (listRes .AllowedGroups . Groups ))
78
+ for i , group := range listRes .AllowedGroups . Groups {
70
79
groupIDs [i ] = group .Group
71
80
}
72
81
@@ -90,6 +99,5 @@ func (s *Service) DescribeConsumerGroups(ctx context.Context) ([]DescribeConsume
90
99
Groups : res ,
91
100
})
92
101
}
93
-
94
- return describedGroups , nil
102
+ return describedGroups , listRes .AllGroupsCount , nil
95
103
}
0 commit comments