@@ -799,7 +799,7 @@ func specialMetrics(ctx context.Context, client *mongo.Client, m bson.M, l *logr
799
799
}
800
800
801
801
metrics = append (metrics , storageEngine (m ))
802
- metrics = append (metrics , serverVersion (m , buildInfo ))
802
+ metrics = append (metrics , serverVersion (buildInfo ))
803
803
metrics = append (metrics , myState (ctx , client ))
804
804
805
805
if mm := replSetMetrics (m ); mm != nil {
@@ -825,7 +825,6 @@ func retrieveMongoDBBuildInfo(ctx context.Context, client *mongo.Client, l *logr
825
825
return buildInfo {}, errors .Wrap (err , "Failed to run buildInfo command" )
826
826
}
827
827
828
- var edition string
829
828
modules , ok := buildInfoDoc ["modules" ].(bson.A )
830
829
if ! ok {
831
830
return buildInfo {}, errors .Wrap (err , "Failed to cast module information variable" )
@@ -837,7 +836,7 @@ func retrieveMongoDBBuildInfo(ctx context.Context, client *mongo.Client, l *logr
837
836
} else {
838
837
bi .Edition = CommunityEdition
839
838
}
840
- l .Debug ("MongoDB edition: " , edition )
839
+ l .Debug ("MongoDB edition: " , bi . Edition )
841
840
842
841
_ , ok = buildInfoDoc ["psmdbVersion" ]
843
842
if ok {
@@ -846,6 +845,11 @@ func retrieveMongoDBBuildInfo(ctx context.Context, client *mongo.Client, l *logr
846
845
bi .Vendor = MongoDBVendor
847
846
}
848
847
848
+ bi .Version , ok = buildInfoDoc ["version" ].(string )
849
+ if ! ok {
850
+ return buildInfo {}, errors .Wrap (err , "Failed to cast version information variable" )
851
+ }
852
+
849
853
return bi , nil
850
854
}
851
855
@@ -866,16 +870,11 @@ func storageEngine(m bson.M) prometheus.Metric {
866
870
return metric
867
871
}
868
872
869
- func serverVersion (m bson.M , bi buildInfo ) prometheus.Metric { //nolint:ireturn
870
- v := walkTo (m , []string {"serverStatus" , "version" })
873
+ func serverVersion (bi buildInfo ) prometheus.Metric { //nolint:ireturn
871
874
name := "mongodb_version_info"
872
875
help := "The server version"
873
876
874
- serverVersion , ok := v .(string )
875
- if ! ok {
876
- serverVersion = "server version is unavailable"
877
- }
878
- labels := map [string ]string {"mongodb" : serverVersion , "edition" : bi .Edition , "vendor" : bi .Vendor }
877
+ labels := map [string ]string {"mongodb" : bi .Version , "edition" : bi .Edition , "vendor" : bi .Vendor }
879
878
880
879
d := prometheus .NewDesc (name , help , nil , labels )
881
880
metric , _ := prometheus .NewConstMetric (d , prometheus .GaugeValue , float64 (1 ))
@@ -1354,6 +1353,7 @@ type rawStatus struct {
1354
1353
}
1355
1354
1356
1355
type buildInfo struct {
1356
+ Version string
1357
1357
Edition string
1358
1358
Vendor string
1359
1359
}
0 commit comments