Skip to content

Commit a6a06a1

Browse files
committed
PMM-13477 fix tests.
1 parent c2d8d50 commit a6a06a1

File tree

3 files changed

+27
-32
lines changed

3 files changed

+27
-32
lines changed

exporter/diagnostic_data_collector_test.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,24 +51,26 @@ func TestDiagnosticDataCollector(t *testing.T) {
5151

5252
c := newDiagnosticDataCollector(ctx, client, logger, false, ti, dbBuildInfo)
5353

54+
prefix := "local.oplog.rs.stats.storageStats.wiredTiger"
55+
if dbBuildInfo.VersionArray[0] < 7 {
56+
prefix = "local.oplog.rs.stats.wiredTiger"
57+
}
58+
5459
// The last \n at the end of this string is important
55-
expected := strings.NewReader(`
56-
# HELP mongodb_oplog_stats_ok local.oplog.rs.stats.
57-
# TYPE mongodb_oplog_stats_ok untyped
58-
mongodb_oplog_stats_ok 1
59-
# HELP mongodb_oplog_stats_wt_btree_fixed_record_size local.oplog.rs.stats.wiredTiger.btree.
60+
expectedString := fmt.Sprintf(`
61+
# HELP mongodb_oplog_stats_wt_btree_fixed_record_size %s.btree.
6062
# TYPE mongodb_oplog_stats_wt_btree_fixed_record_size untyped
6163
mongodb_oplog_stats_wt_btree_fixed_record_size 0
62-
# HELP mongodb_oplog_stats_wt_transaction_update_conflicts local.oplog.rs.stats.wiredTiger.transaction.
64+
# HELP mongodb_oplog_stats_wt_transaction_update_conflicts %s.transaction.
6365
# TYPE mongodb_oplog_stats_wt_transaction_update_conflicts untyped
64-
mongodb_oplog_stats_wt_transaction_update_conflicts 0` + "\n")
66+
mongodb_oplog_stats_wt_transaction_update_conflicts 0`, prefix, prefix)
67+
expected := strings.NewReader(expectedString + "\n")
6568

6669
// Filter metrics for 2 reasons:
6770
// 1. The result is huge
6871
// 2. We need to check against know values. Don't use metrics that return counters like uptime
6972
// or counters like the number of transactions because they won't return a known value to compare
7073
filter := []string{
71-
"mongodb_oplog_stats_ok",
7274
"mongodb_oplog_stats_wt_btree_fixed_record_size",
7375
"mongodb_oplog_stats_wt_transaction_update_conflicts",
7476
}

exporter/metrics.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ var (
5757
{"replSetGetStatus", "rs"},
5858
{"systemMetrics", "sys"},
5959
{"local.oplog.rs.stats.wiredTiger", "oplog_stats_wt"},
60+
{"local.oplog.rs.stats.storageStats.wiredTiger", "oplog_stats_wt"},
6061
{"local.oplog.rs.stats", "oplog_stats"},
62+
{"local.oplog.rs.stats.storageStats", "oplog_stats"},
6163
{"collstats_storage.wiredTiger", "collstats_storage_wt"},
6264
{"collstats_storage.indexDetails", "collstats_storage_idx"},
6365
{"collStats.storageStats", "collstats_storage"},

exporter/v1_compatibility.go

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -858,38 +858,26 @@ func retrieveMongoDBBuildInfo(ctx context.Context, client *mongo.Client, l *logr
858858
buildInfoCmd := bson.D{bson.E{Key: "buildInfo", Value: 1}}
859859
res := client.Database("admin").RunCommand(ctx, buildInfoCmd)
860860

861-
var buildInfoDoc bson.M
861+
var buildInfoDoc buildInfo
862862
err := res.Decode(&buildInfoDoc)
863863
if err != nil {
864864
return buildInfo{}, errors.Wrap(err, "Failed to run buildInfo command")
865865
}
866866

867-
modules, ok := buildInfoDoc["modules"].(bson.A)
868-
if !ok {
869-
return buildInfo{}, errors.Wrap(err, "Failed to cast module information variable")
870-
}
871-
872-
var bi buildInfo
873-
if len(modules) > 0 && modules[0].(string) == "enterprise" {
874-
bi.Edition = EnterpriseEdition
867+
if len(buildInfoDoc.Modules) > 0 && buildInfoDoc.Modules[0] == "enterprise" {
868+
buildInfoDoc.Edition = EnterpriseEdition
875869
} else {
876-
bi.Edition = CommunityEdition
870+
buildInfoDoc.Edition = CommunityEdition
877871
}
878-
l.Debug("MongoDB edition: ", bi.Edition)
872+
l.Debug("MongoDB edition: ", buildInfoDoc.Edition)
879873

880-
_, ok = buildInfoDoc["psmdbVersion"]
881-
if ok {
882-
bi.Vendor = PerconaVendor
874+
if buildInfoDoc.PSMDBVersion != "" {
875+
buildInfoDoc.Vendor = PerconaVendor
883876
} else {
884-
bi.Vendor = MongoDBVendor
885-
}
886-
887-
bi.Version, ok = buildInfoDoc["version"].(string)
888-
if !ok {
889-
return buildInfo{}, errors.Wrap(err, "Failed to cast version information variable")
877+
buildInfoDoc.Vendor = MongoDBVendor
890878
}
891879

892-
return bi, nil
880+
return buildInfoDoc, nil
893881
}
894882

895883
func storageEngine(m bson.M) (prometheus.Metric, error) { //nolint:ireturn
@@ -1348,9 +1336,12 @@ type rawStatus struct {
13481336
}
13491337

13501338
type buildInfo struct {
1351-
Version string
1352-
Edition string
1353-
Vendor string
1339+
Version string `bson:"version"`
1340+
PSMDBVersion string `bson:"psmdbVersion"`
1341+
VersionArray []int `bson:"versionArray"`
1342+
Edition string
1343+
Vendor string
1344+
Modules []string `bson:"modules"`
13541345
}
13551346

13561347
func getDatabaseStatList(ctx context.Context, client *mongo.Client, l *logrus.Entry) *databaseStatList {

0 commit comments

Comments
 (0)