Skip to content

Commit

Permalink
PMM-13477 fix tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
BupycHuk committed Nov 4, 2024
1 parent c2d8d50 commit a6a06a1
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 32 deletions.
18 changes: 10 additions & 8 deletions exporter/diagnostic_data_collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,24 +51,26 @@ func TestDiagnosticDataCollector(t *testing.T) {

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

prefix := "local.oplog.rs.stats.storageStats.wiredTiger"
if dbBuildInfo.VersionArray[0] < 7 {
prefix = "local.oplog.rs.stats.wiredTiger"
}

// The last \n at the end of this string is important
expected := strings.NewReader(`
# HELP mongodb_oplog_stats_ok local.oplog.rs.stats.
# TYPE mongodb_oplog_stats_ok untyped
mongodb_oplog_stats_ok 1
# HELP mongodb_oplog_stats_wt_btree_fixed_record_size local.oplog.rs.stats.wiredTiger.btree.
expectedString := fmt.Sprintf(`
# HELP mongodb_oplog_stats_wt_btree_fixed_record_size %s.btree.
# TYPE mongodb_oplog_stats_wt_btree_fixed_record_size untyped
mongodb_oplog_stats_wt_btree_fixed_record_size 0
# HELP mongodb_oplog_stats_wt_transaction_update_conflicts local.oplog.rs.stats.wiredTiger.transaction.
# HELP mongodb_oplog_stats_wt_transaction_update_conflicts %s.transaction.
# TYPE mongodb_oplog_stats_wt_transaction_update_conflicts untyped
mongodb_oplog_stats_wt_transaction_update_conflicts 0` + "\n")
mongodb_oplog_stats_wt_transaction_update_conflicts 0`, prefix, prefix)
expected := strings.NewReader(expectedString + "\n")

// Filter metrics for 2 reasons:
// 1. The result is huge
// 2. We need to check against know values. Don't use metrics that return counters like uptime
// or counters like the number of transactions because they won't return a known value to compare
filter := []string{
"mongodb_oplog_stats_ok",
"mongodb_oplog_stats_wt_btree_fixed_record_size",
"mongodb_oplog_stats_wt_transaction_update_conflicts",
}
Expand Down
2 changes: 2 additions & 0 deletions exporter/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ var (
{"replSetGetStatus", "rs"},
{"systemMetrics", "sys"},
{"local.oplog.rs.stats.wiredTiger", "oplog_stats_wt"},
{"local.oplog.rs.stats.storageStats.wiredTiger", "oplog_stats_wt"},
{"local.oplog.rs.stats", "oplog_stats"},
{"local.oplog.rs.stats.storageStats", "oplog_stats"},
{"collstats_storage.wiredTiger", "collstats_storage_wt"},
{"collstats_storage.indexDetails", "collstats_storage_idx"},
{"collStats.storageStats", "collstats_storage"},
Expand Down
39 changes: 15 additions & 24 deletions exporter/v1_compatibility.go
Original file line number Diff line number Diff line change
Expand Up @@ -858,38 +858,26 @@ func retrieveMongoDBBuildInfo(ctx context.Context, client *mongo.Client, l *logr
buildInfoCmd := bson.D{bson.E{Key: "buildInfo", Value: 1}}
res := client.Database("admin").RunCommand(ctx, buildInfoCmd)

var buildInfoDoc bson.M
var buildInfoDoc buildInfo
err := res.Decode(&buildInfoDoc)
if err != nil {
return buildInfo{}, errors.Wrap(err, "Failed to run buildInfo command")
}

modules, ok := buildInfoDoc["modules"].(bson.A)
if !ok {
return buildInfo{}, errors.Wrap(err, "Failed to cast module information variable")
}

var bi buildInfo
if len(modules) > 0 && modules[0].(string) == "enterprise" {
bi.Edition = EnterpriseEdition
if len(buildInfoDoc.Modules) > 0 && buildInfoDoc.Modules[0] == "enterprise" {
buildInfoDoc.Edition = EnterpriseEdition
} else {
bi.Edition = CommunityEdition
buildInfoDoc.Edition = CommunityEdition
}
l.Debug("MongoDB edition: ", bi.Edition)
l.Debug("MongoDB edition: ", buildInfoDoc.Edition)

_, ok = buildInfoDoc["psmdbVersion"]
if ok {
bi.Vendor = PerconaVendor
if buildInfoDoc.PSMDBVersion != "" {
buildInfoDoc.Vendor = PerconaVendor
} else {
bi.Vendor = MongoDBVendor
}

bi.Version, ok = buildInfoDoc["version"].(string)
if !ok {
return buildInfo{}, errors.Wrap(err, "Failed to cast version information variable")
buildInfoDoc.Vendor = MongoDBVendor
}

return bi, nil
return buildInfoDoc, nil
}

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

type buildInfo struct {
Version string
Edition string
Vendor string
Version string `bson:"version"`
PSMDBVersion string `bson:"psmdbVersion"`
VersionArray []int `bson:"versionArray"`
Edition string
Vendor string
Modules []string `bson:"modules"`
}

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

0 comments on commit a6a06a1

Please sign in to comment.