@@ -69,6 +69,18 @@ type DescribeGroupsResponseMemberMetadata struct {
69
69
70
70
// UserData is the user data for the member.
71
71
UserData []byte
72
+
73
+ // OwnedPartitions contains the partitions owned by this group member; only set if
74
+ // consumers are using a cooperative rebalancing assignor protocol.
75
+ OwnedPartitions []DescribeGroupsResponseMemberMetadataOwnedPartition
76
+ }
77
+
78
+ type DescribeGroupsResponseMemberMetadataOwnedPartition struct {
79
+ // Topic is the name of the topic.
80
+ Topic string
81
+
82
+ // Partitions is the partitions that are owned by the group in the topic.
83
+ Partitions []int
72
84
}
73
85
74
86
// GroupMemberAssignmentsInfo stores the topic partition assignment data for a group member.
@@ -93,6 +105,9 @@ type GroupMemberTopic struct {
93
105
Partitions []int
94
106
}
95
107
108
+ // DescribeGroups calls the Kafka DescribeGroups API to get information about one or more
109
+ // consumer groups. See https://kafka.apache.org/protocol#The_Messages_DescribeGroups for
110
+ // more information.
96
111
func (c * Client ) DescribeGroups (
97
112
ctx context.Context ,
98
113
req * DescribeGroupsRequest ,
@@ -141,176 +156,18 @@ func (c *Client) DescribeGroups(
141
156
return resp , nil
142
157
}
143
158
144
- // See http://kafka.apache.org/protocol.html#The_Messages_DescribeGroups
145
- //
146
- // TODO: Remove everything below and use protocol-based version above everywhere.
147
- type describeGroupsRequestV0 struct {
148
- // List of groupIds to request metadata for (an empty groupId array
149
- // will return empty group metadata).
150
- GroupIDs []string
151
- }
152
-
153
- func (t describeGroupsRequestV0 ) size () int32 {
154
- return sizeofStringArray (t .GroupIDs )
155
- }
156
-
157
- func (t describeGroupsRequestV0 ) writeTo (wb * writeBuffer ) {
158
- wb .writeStringArray (t .GroupIDs )
159
- }
160
-
161
- type describeGroupsResponseMemberV0 struct {
162
- // MemberID assigned by the group coordinator
163
- MemberID string
164
-
165
- // ClientID used in the member's latest join group request
166
- ClientID string
167
-
168
- // ClientHost used in the request session corresponding to the member's
169
- // join group.
170
- ClientHost string
171
-
172
- // MemberMetadata the metadata corresponding to the current group protocol
173
- // in use (will only be present if the group is stable).
174
- MemberMetadata []byte
175
-
176
- // MemberAssignments provided by the group leader (will only be present if
177
- // the group is stable).
178
- //
179
- // See consumer groups section of https://cwiki.apache.org/confluence/display/KAFKA/A+Guide+To+The+Kafka+Protocol
180
- MemberAssignments []byte
181
- }
182
-
183
- func (t describeGroupsResponseMemberV0 ) size () int32 {
184
- return sizeofString (t .MemberID ) +
185
- sizeofString (t .ClientID ) +
186
- sizeofString (t .ClientHost ) +
187
- sizeofBytes (t .MemberMetadata ) +
188
- sizeofBytes (t .MemberAssignments )
189
- }
190
-
191
- func (t describeGroupsResponseMemberV0 ) writeTo (wb * writeBuffer ) {
192
- wb .writeString (t .MemberID )
193
- wb .writeString (t .ClientID )
194
- wb .writeString (t .ClientHost )
195
- wb .writeBytes (t .MemberMetadata )
196
- wb .writeBytes (t .MemberAssignments )
197
- }
198
-
199
- func (t * describeGroupsResponseMemberV0 ) readFrom (r * bufio.Reader , size int ) (remain int , err error ) {
200
- if remain , err = readString (r , size , & t .MemberID ); err != nil {
201
- return
202
- }
203
- if remain , err = readString (r , remain , & t .ClientID ); err != nil {
204
- return
205
- }
206
- if remain , err = readString (r , remain , & t .ClientHost ); err != nil {
207
- return
208
- }
209
- if remain , err = readBytes (r , remain , & t .MemberMetadata ); err != nil {
210
- return
211
- }
212
- if remain , err = readBytes (r , remain , & t .MemberAssignments ); err != nil {
159
+ // readFrom decodes an owned partition item from the member metadata.
160
+ func (t * DescribeGroupsResponseMemberMetadataOwnedPartition ) readFrom (r * bufio.Reader , size int ) (remain int , err error ) {
161
+ if remain , err = readString (r , size , & t .Topic ); err != nil {
213
162
return
214
163
}
215
- return
216
- }
217
-
218
- type describeGroupsResponseGroupV0 struct {
219
- // ErrorCode holds response error code
220
- ErrorCode int16
221
-
222
- // GroupID holds the unique group identifier
223
- GroupID string
224
-
225
- // State holds current state of the group (one of: Dead, Stable, AwaitingSync,
226
- // PreparingRebalance, or empty if there is no active group)
227
- State string
228
-
229
- // ProtocolType holds the current group protocol type (will be empty if there is
230
- // no active group)
231
- ProtocolType string
232
-
233
- // Protocol holds the current group protocol (only provided if the group is Stable)
234
- Protocol string
235
-
236
- // Members contains the current group members (only provided if the group is not Dead)
237
- Members []describeGroupsResponseMemberV0
238
- }
239
-
240
- func (t describeGroupsResponseGroupV0 ) size () int32 {
241
- return sizeofInt16 (t .ErrorCode ) +
242
- sizeofString (t .GroupID ) +
243
- sizeofString (t .State ) +
244
- sizeofString (t .ProtocolType ) +
245
- sizeofString (t .Protocol ) +
246
- sizeofArray (len (t .Members ), func (i int ) int32 { return t .Members [i ].size () })
247
- }
164
+ partitions := []int32 {}
248
165
249
- func (t describeGroupsResponseGroupV0 ) writeTo (wb * writeBuffer ) {
250
- wb .writeInt16 (t .ErrorCode )
251
- wb .writeString (t .GroupID )
252
- wb .writeString (t .State )
253
- wb .writeString (t .ProtocolType )
254
- wb .writeString (t .Protocol )
255
- wb .writeArray (len (t .Members ), func (i int ) { t .Members [i ].writeTo (wb ) })
256
- }
257
-
258
- func (t * describeGroupsResponseGroupV0 ) readFrom (r * bufio.Reader , size int ) (remain int , err error ) {
259
- if remain , err = readInt16 (r , size , & t .ErrorCode ); err != nil {
260
- return
261
- }
262
- if remain , err = readString (r , remain , & t .GroupID ); err != nil {
263
- return
264
- }
265
- if remain , err = readString (r , remain , & t .State ); err != nil {
266
- return
267
- }
268
- if remain , err = readString (r , remain , & t .ProtocolType ); err != nil {
269
- return
270
- }
271
- if remain , err = readString (r , remain , & t .Protocol ); err != nil {
272
- return
273
- }
274
-
275
- fn := func (r * bufio.Reader , size int ) (fnRemain int , fnErr error ) {
276
- item := describeGroupsResponseMemberV0 {}
277
- if fnRemain , fnErr = (& item ).readFrom (r , size ); err != nil {
278
- return
279
- }
280
- t .Members = append (t .Members , item )
166
+ if remain , err = readInt32Array (r , remain , & partitions ); err != nil {
281
167
return
282
168
}
283
- if remain , err = readArrayWith (r , remain , fn ); err != nil {
284
- return
285
- }
286
-
287
- return
288
- }
289
-
290
- type describeGroupsResponseV0 struct {
291
- // Groups holds selected group information
292
- Groups []describeGroupsResponseGroupV0
293
- }
294
-
295
- func (t describeGroupsResponseV0 ) size () int32 {
296
- return sizeofArray (len (t .Groups ), func (i int ) int32 { return t .Groups [i ].size () })
297
- }
298
-
299
- func (t describeGroupsResponseV0 ) writeTo (wb * writeBuffer ) {
300
- wb .writeArray (len (t .Groups ), func (i int ) { t .Groups [i ].writeTo (wb ) })
301
- }
302
-
303
- func (t * describeGroupsResponseV0 ) readFrom (r * bufio.Reader , sz int ) (remain int , err error ) {
304
- fn := func (r * bufio.Reader , size int ) (fnRemain int , fnErr error ) {
305
- item := describeGroupsResponseGroupV0 {}
306
- if fnRemain , fnErr = (& item ).readFrom (r , size ); fnErr != nil {
307
- return
308
- }
309
- t .Groups = append (t .Groups , item )
310
- return
311
- }
312
- if remain , err = readArrayWith (r , sz , fn ); err != nil {
313
- return
169
+ for _ , partition := range partitions {
170
+ t .Partitions = append (t .Partitions , int (partition ))
314
171
}
315
172
316
173
return
@@ -347,6 +204,31 @@ func decodeMemberMetadata(rawMetadata []byte) (DescribeGroupsResponseMemberMetad
347
204
return mm , err
348
205
}
349
206
207
+ if mm .Version == 1 && remain > 0 {
208
+ fn := func (r * bufio.Reader , size int ) (fnRemain int , fnErr error ) {
209
+ op := DescribeGroupsResponseMemberMetadataOwnedPartition {}
210
+ if fnRemain , fnErr = readString (r , size , & op .Topic ); fnErr != nil {
211
+ return
212
+ }
213
+
214
+ ps := []int32 {}
215
+ if fnRemain , fnErr = readInt32Array (r , fnRemain , & ps ); fnErr != nil {
216
+ return
217
+ }
218
+
219
+ for _ , p := range ps {
220
+ op .Partitions = append (op .Partitions , int (p ))
221
+ }
222
+
223
+ mm .OwnedPartitions = append (mm .OwnedPartitions , op )
224
+ return
225
+ }
226
+
227
+ if remain , err = readArrayWith (bufReader , remain , fn ); err != nil {
228
+ return mm , err
229
+ }
230
+ }
231
+
350
232
if remain != 0 {
351
233
return mm , fmt .Errorf ("Got non-zero number of bytes remaining: %d" , remain )
352
234
}
0 commit comments