@@ -1053,7 +1053,11 @@ func mongosMetrics(ctx context.Context, client *mongo.Client, l *logrus.Logger)
1053
1053
metrics = append (metrics , metric )
1054
1054
}
1055
1055
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
+ }
1057
1061
1058
1062
metric , err := chunksTotal (ctx , client )
1059
1063
if err != nil {
@@ -1164,17 +1168,19 @@ func chunksBalanced(ctx context.Context, client *mongo.Client) (prometheus.Metri
1164
1168
return prometheus .NewConstMetric (d , prometheus .GaugeValue , value )
1165
1169
}
1166
1170
1167
- func balancerEnabled (ctx context.Context , client * mongo.Client ) prometheus.Metric {
1171
+ func balancerEnabled (ctx context.Context , client * mongo.Client ) ( prometheus.Metric , error ) {
1168
1172
type bss struct {
1169
- stopped bool `bson:"stopped"`
1173
+ Stopped bool `bson:"stopped"`
1170
1174
}
1171
1175
var bs bss
1172
1176
enabled := 0
1173
1177
1174
1178
err := client .Database ("config" ).Collection ("settings" ).FindOne (ctx , bson.M {"_id" : "balancer" }).Decode (& bs )
1175
1179
if err != nil {
1176
- enabled = 1
1177
- } else if ! bs .stopped {
1180
+ return nil , err
1181
+ }
1182
+
1183
+ if ! bs .Stopped {
1178
1184
enabled = 1
1179
1185
}
1180
1186
@@ -1184,7 +1190,7 @@ func balancerEnabled(ctx context.Context, client *mongo.Client) prometheus.Metri
1184
1190
d := prometheus .NewDesc (name , help , nil , nil )
1185
1191
metric , _ := prometheus .NewConstMetric (d , prometheus .GaugeValue , float64 (enabled ))
1186
1192
1187
- return metric
1193
+ return metric , nil
1188
1194
}
1189
1195
1190
1196
func chunksTotal (ctx context.Context , client * mongo.Client ) (prometheus.Metric , error ) {
0 commit comments