@@ -1053,7 +1053,11 @@ func mongosMetrics(ctx context.Context, client *mongo.Client, l *logrus.Logger)
10531053 metrics = append (metrics , metric )
10541054 }
10551055
1056- metrics = append (metrics , balancerEnabled (ctx , client ))
1056+ if metric , err := balancerEnabled (ctx , client ); err != nil {
1057+ l .Debugf ("cannot create metric for balancer is enabled: %s" , err )
1058+ } else {
1059+ metrics = append (metrics , metric )
1060+ }
10571061
10581062 metric , err := chunksTotal (ctx , client )
10591063 if err != nil {
@@ -1164,17 +1168,19 @@ func chunksBalanced(ctx context.Context, client *mongo.Client) (prometheus.Metri
11641168 return prometheus .NewConstMetric (d , prometheus .GaugeValue , value )
11651169}
11661170
1167- func balancerEnabled (ctx context.Context , client * mongo.Client ) prometheus.Metric {
1171+ func balancerEnabled (ctx context.Context , client * mongo.Client ) ( prometheus.Metric , error ) {
11681172 type bss struct {
1169- stopped bool `bson:"stopped"`
1173+ Stopped bool `bson:"stopped"`
11701174 }
11711175 var bs bss
11721176 enabled := 0
11731177
11741178 err := client .Database ("config" ).Collection ("settings" ).FindOne (ctx , bson.M {"_id" : "balancer" }).Decode (& bs )
11751179 if err != nil {
1176- enabled = 1
1177- } else if ! bs .stopped {
1180+ return nil , err
1181+ }
1182+
1183+ if ! bs .Stopped {
11781184 enabled = 1
11791185 }
11801186
@@ -1184,7 +1190,7 @@ func balancerEnabled(ctx context.Context, client *mongo.Client) prometheus.Metri
11841190 d := prometheus .NewDesc (name , help , nil , nil )
11851191 metric , _ := prometheus .NewConstMetric (d , prometheus .GaugeValue , float64 (enabled ))
11861192
1187- return metric
1193+ return metric , nil
11881194}
11891195
11901196func chunksTotal (ctx context.Context , client * mongo.Client ) (prometheus.Metric , error ) {
0 commit comments