@@ -108,8 +108,7 @@ func (cs *childSet) Each(
108108) {
109109 cs .mu .Lock ()
110110 defer cs .mu .Unlock ()
111- cs .mu .children .Do (func (e interface {}) {
112- cm := cs .mu .children .GetChildMetric (e )
111+ cs .mu .children .ForEach (func (cm ChildMetric ) {
113112 pm := cm .ToPrometheusMetric ()
114113
115114 childLabels := make ([]* io_prometheus_client.LabelPair , 0 , len (labels )+ len (cs .labels ))
@@ -130,8 +129,8 @@ func (cs *childSet) Each(
130129func (cs * childSet ) apply (applyFn func (item MetricItem )) {
131130 cs .mu .Lock ()
132131 defer cs .mu .Unlock ()
133- cs .mu .children .Do (func (e interface {} ) {
134- applyFn (cs . mu . children . GetChildMetric ( e ).( MetricItem ) )
132+ cs .mu .children .ForEach (func (cm ChildMetric ) {
133+ applyFn (cm )
135134 })
136135}
137136
@@ -192,8 +191,7 @@ func (sm *SQLMetric) Each(
192191 sm .mu .Lock ()
193192 defer sm .mu .Unlock ()
194193
195- sm .mu .children .Do (func (e interface {}) {
196- cm := sm .mu .children .GetChildMetric (e )
194+ sm .mu .children .ForEach (func (cm ChildMetric ) {
197195 pm := cm .ToPrometheusMetric ()
198196
199197 childLabels := make ([]* io_prometheus_client.LabelPair , 0 , len (labels )+ 2 )
@@ -317,8 +315,9 @@ type ChildrenStorage interface {
317315 Get (labelVals ... string ) (ChildMetric , bool )
318316 Add (metric ChildMetric )
319317 Del (key ChildMetric )
320- Do (f func (e interface {}))
321- GetChildMetric (e interface {}) ChildMetric
318+
319+ // ForEach calls f for each child metric, in arbitrary order.
320+ ForEach (f func (metric ChildMetric ))
322321 Clear ()
323322}
324323
@@ -329,10 +328,6 @@ type UnorderedCacheWrapper struct {
329328 cache * cache.UnorderedCache
330329}
331330
332- func (ucw * UnorderedCacheWrapper ) GetChildMetric (e interface {}) ChildMetric {
333- return e .(* cache.Entry ).Value .(ChildMetric )
334- }
335-
336331func (ucw * UnorderedCacheWrapper ) Get (labelVals ... string ) (ChildMetric , bool ) {
337332 hashKey := metricKey (labelVals ... )
338333 value , ok := ucw .cache .Get (hashKey )
@@ -358,9 +353,9 @@ func (ucw *UnorderedCacheWrapper) Del(metric ChildMetric) {
358353 }
359354}
360355
361- func (ucw * UnorderedCacheWrapper ) Do (f func (e interface {} )) {
356+ func (ucw * UnorderedCacheWrapper ) ForEach (f func (metric ChildMetric )) {
362357 ucw .cache .Do (func (e * cache.Entry ) {
363- f (e )
358+ f (e . Value .( ChildMetric ) )
364359 })
365360}
366361
@@ -395,17 +390,13 @@ func (b BtreeWrapper) Del(metric ChildMetric) {
395390 }
396391}
397392
398- func (b BtreeWrapper ) Do (f func (e interface {} )) {
393+ func (b BtreeWrapper ) ForEach (f func (metric ChildMetric )) {
399394 b .tree .Ascend (func (i btree.Item ) bool {
400- f (i )
395+ f (i .( ChildMetric ) )
401396 return true
402397 })
403398}
404399
405- func (b BtreeWrapper ) GetChildMetric (e interface {}) ChildMetric {
406- return e .(ChildMetric )
407- }
408-
409400func (b BtreeWrapper ) Clear () {
410401 b .tree .Clear (false )
411402}
0 commit comments