@@ -133,6 +133,11 @@ interface TraceEvent {
133
133
*/
134
134
const TARGET_RETAINED_TRACES = 32 ;
135
135
136
+ /**
137
+ * Default number of sockets/servers/channels/subchannels to return
138
+ */
139
+ const DEFAULT_MAX_RESULTS = 100 ;
140
+
136
141
export class ChannelzTraceStub {
137
142
readonly events : TraceEvent [ ] = [ ] ;
138
143
readonly creationTimestamp : Date = new Date ( ) ;
@@ -198,19 +203,15 @@ export class ChannelzTrace {
198
203
}
199
204
}
200
205
206
+ type RefOrderedMap = OrderedMap <
207
+ number ,
208
+ { ref : { id : number ; kind : EntityTypes ; name : string } ; count : number }
209
+ > ;
210
+
201
211
export class ChannelzChildrenTracker {
202
- private channelChildren = new OrderedMap <
203
- number ,
204
- { ref : ChannelRef ; count : number }
205
- > ( ) ;
206
- private subchannelChildren = new OrderedMap <
207
- number ,
208
- { ref : SubchannelRef ; count : number }
209
- > ( ) ;
210
- private socketChildren = new OrderedMap <
211
- number ,
212
- { ref : SocketRef ; count : number }
213
- > ( ) ;
212
+ private channelChildren : RefOrderedMap = new OrderedMap ( ) ;
213
+ private subchannelChildren : RefOrderedMap = new OrderedMap ( ) ;
214
+ private socketChildren : RefOrderedMap = new OrderedMap ( ) ;
214
215
private trackerMap = {
215
216
[ EntityTypes . channel ] : this . channelChildren ,
216
217
[ EntityTypes . subchannel ] : this . subchannelChildren ,
@@ -219,16 +220,19 @@ export class ChannelzChildrenTracker {
219
220
220
221
refChild ( child : ChannelRef | SubchannelRef | SocketRef ) {
221
222
const tracker = this . trackerMap [ child . kind ] ;
222
- const trackedChild = tracker . getElementByKey ( child . id ) ;
223
-
224
- if ( trackedChild === undefined ) {
225
- tracker . setElement ( child . id , {
226
- // @ts -expect-error union issues
227
- ref : child ,
228
- count : 1 ,
229
- } ) ;
223
+ const trackedChild = tracker . find ( child . id ) ;
224
+
225
+ if ( trackedChild . equals ( tracker . end ( ) ) ) {
226
+ tracker . setElement (
227
+ child . id ,
228
+ {
229
+ ref : child ,
230
+ count : 1 ,
231
+ } ,
232
+ trackedChild
233
+ ) ;
230
234
} else {
231
- trackedChild . count += 1 ;
235
+ trackedChild . pointer [ 1 ] . count += 1 ;
232
236
}
233
237
}
234
238
@@ -245,9 +249,9 @@ export class ChannelzChildrenTracker {
245
249
246
250
getChildLists ( ) : ChannelzChildren {
247
251
return {
248
- channels : this . channelChildren ,
249
- subchannels : this . subchannelChildren ,
250
- sockets : this . socketChildren ,
252
+ channels : this . channelChildren as ChannelzChildren [ 'channels' ] ,
253
+ subchannels : this . subchannelChildren as ChannelzChildren [ 'subchannels' ] ,
254
+ sockets : this . socketChildren as ChannelzChildren [ 'sockets' ] ,
251
255
} ;
252
256
}
253
257
}
@@ -585,7 +589,8 @@ function GetTopChannels(
585
589
call : ServerUnaryCall < GetTopChannelsRequest__Output , GetTopChannelsResponse > ,
586
590
callback : sendUnaryData < GetTopChannelsResponse >
587
591
) : void {
588
- const maxResults = parseInt ( call . request . max_results , 10 ) || 100 ;
592
+ const maxResults =
593
+ parseInt ( call . request . max_results , 10 ) || DEFAULT_MAX_RESULTS ;
589
594
const resultList : ChannelMessage [ ] = [ ] ;
590
595
const startId = parseInt ( call . request . start_channel_id , 10 ) ;
591
596
const channelEntries = entityMaps [ EntityTypes . channel ] ;
@@ -649,7 +654,8 @@ function GetServers(
649
654
call : ServerUnaryCall < GetServersRequest__Output , GetServersResponse > ,
650
655
callback : sendUnaryData < GetServersResponse >
651
656
) : void {
652
- const maxResults = parseInt ( call . request . max_results , 10 ) || 100 ;
657
+ const maxResults =
658
+ parseInt ( call . request . max_results , 10 ) || DEFAULT_MAX_RESULTS ;
653
659
const startId = parseInt ( call . request . start_server_id , 10 ) ;
654
660
const serverEntries = entityMaps [ EntityTypes . server ] ;
655
661
const resultList : ServerMessage [ ] = [ ] ;
@@ -820,7 +826,8 @@ function GetServerSockets(
820
826
}
821
827
822
828
const startId = parseInt ( call . request . start_socket_id , 10 ) ;
823
- const maxResults = parseInt ( call . request . max_results , 10 ) || 100 ;
829
+ const maxResults =
830
+ parseInt ( call . request . max_results , 10 ) || DEFAULT_MAX_RESULTS ;
824
831
const resolvedInfo = serverEntry . getInfo ( ) ;
825
832
// If we wanted to include listener sockets in the result, this line would
826
833
// instead say
0 commit comments