@@ -799,7 +799,7 @@ func specialMetrics(ctx context.Context, client *mongo.Client, m bson.M, l *logr
799799 }
800800
801801 metrics = append (metrics , storageEngine (m ))
802- metrics = append (metrics , serverVersion (m , buildInfo ))
802+ metrics = append (metrics , serverVersion (buildInfo ))
803803 metrics = append (metrics , myState (ctx , client ))
804804
805805 if mm := replSetMetrics (m ); mm != nil {
@@ -825,7 +825,6 @@ func retrieveMongoDBBuildInfo(ctx context.Context, client *mongo.Client, l *logr
825825 return buildInfo {}, errors .Wrap (err , "Failed to run buildInfo command" )
826826 }
827827
828- var edition string
829828 modules , ok := buildInfoDoc ["modules" ].(bson.A )
830829 if ! ok {
831830 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
837836 } else {
838837 bi .Edition = CommunityEdition
839838 }
840- l .Debug ("MongoDB edition: " , edition )
839+ l .Debug ("MongoDB edition: " , bi . Edition )
841840
842841 _ , ok = buildInfoDoc ["psmdbVersion" ]
843842 if ok {
@@ -846,6 +845,11 @@ func retrieveMongoDBBuildInfo(ctx context.Context, client *mongo.Client, l *logr
846845 bi .Vendor = MongoDBVendor
847846 }
848847
848+ bi .Version , ok = buildInfoDoc ["version" ].(string )
849+ if ! ok {
850+ return buildInfo {}, errors .Wrap (err , "Failed to cast version information variable" )
851+ }
852+
849853 return bi , nil
850854}
851855
@@ -866,16 +870,11 @@ func storageEngine(m bson.M) prometheus.Metric {
866870 return metric
867871}
868872
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
871874 name := "mongodb_version_info"
872875 help := "The server version"
873876
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 }
879878
880879 d := prometheus .NewDesc (name , help , nil , labels )
881880 metric , _ := prometheus .NewConstMetric (d , prometheus .GaugeValue , float64 (1 ))
@@ -1354,6 +1353,7 @@ type rawStatus struct {
13541353}
13551354
13561355type buildInfo struct {
1356+ Version string
13571357 Edition string
13581358 Vendor string
13591359}
0 commit comments