@@ -366,7 +366,7 @@ func metricHelp(prefix, name string) string {
366366 return name
367367}
368368
369- func makeMetrics (client * mongo. Client , prefix string , m bson.M , labels map [string ]string , compatibleMode bool ) []prometheus.Metric {
369+ func makeMetrics (reservedNames [] string , prefix string , m bson.M , labels map [string ]string , compatibleMode bool ) []prometheus.Metric {
370370 var res []prometheus.Metric
371371
372372 if prefix != "" {
@@ -390,30 +390,24 @@ func makeMetrics(client *mongo.Client, prefix string, m bson.M, labels map[strin
390390 } else {
391391 l = labels
392392 }
393- res = append (res , handleMetric (client , prefix , nextPrefix , k , val , l , compatibleMode )... )
393+ res = append (res , handleMetric (reservedNames , prefix , nextPrefix , k , val , l , compatibleMode )... )
394394 }
395395
396396 return res
397397}
398398
399- func handleMetric (client * mongo. Client , prefix , nextPrefix , k string , val interface {}, l map [string ]string , compatibleMode bool ) []prometheus.Metric {
399+ func handleMetric (reservedNames [] string , prefix , nextPrefix , k string , val interface {}, l map [string ]string , compatibleMode bool ) []prometheus.Metric {
400400 var res []prometheus.Metric
401401 switch v := val .(type ) {
402402 case bson.M :
403- res = append (res , makeMetrics (client , nextPrefix , v , l , compatibleMode )... )
403+ res = append (res , makeMetrics (reservedNames , nextPrefix , v , l , compatibleMode )... )
404404 case map [string ]interface {}:
405- res = append (res , makeMetrics (client , nextPrefix , v , l , compatibleMode )... )
405+ res = append (res , makeMetrics (reservedNames , nextPrefix , v , l , compatibleMode )... )
406406 case primitive.A :
407- res = append (res , processSlice (client , nextPrefix , v , l , compatibleMode )... )
407+ res = append (res , processSlice (reservedNames , nextPrefix , v , l , compatibleMode )... )
408408 case []interface {}:
409409 // skip
410410 default :
411- reservedNames , err := allReservedNames (client )
412- if err != nil {
413- fmt .Printf ("\n \n \n cannot get reserved names: %v \n \n \n " , err )
414- return res
415- }
416-
417411 rm , err := makeRawMetric (reservedNames , prefix , k , v , l )
418412 if err != nil {
419413 invalidMetric := prometheus .NewInvalidMetric (prometheus .NewInvalidDesc (err ), err )
@@ -453,7 +447,7 @@ func handleMetric(client *mongo.Client, prefix, nextPrefix, k string, val interf
453447
454448// Extract maps from arrays. Only some structures like replicasets have arrays of members
455449// and each member is represented by a map[string]interface{}.
456- func processSlice (client * mongo. Client , prefix string , v []interface {}, commonLabels map [string ]string , compatibleMode bool ) []prometheus.Metric {
450+ func processSlice (reservedNames [] string , prefix string , v []interface {}, commonLabels map [string ]string , compatibleMode bool ) []prometheus.Metric {
457451 metrics := make ([]prometheus.Metric , 0 )
458452 labels := make (map [string ]string )
459453 for name , value := range commonLabels {
@@ -483,7 +477,7 @@ func processSlice(client *mongo.Client, prefix string, v []interface{}, commonLa
483477 labels ["member_idx" ] = host
484478 }
485479
486- metrics = append (metrics , makeMetrics (client , prefix , s , labels , compatibleMode )... )
480+ metrics = append (metrics , makeMetrics (reservedNames , prefix , s , labels , compatibleMode )... )
487481 }
488482
489483 return metrics
0 commit comments