fix: solve compatibility issue for mongodb inputs when using 5.x relicaset (#9892)

This commit is contained in:
alon 2021-10-15 14:15:40 -05:00 committed by GitHub
parent aaaaabd0fd
commit 34c2b6232d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 11 deletions

View File

@ -248,14 +248,15 @@ type TransactionStats struct {
// ReplStatus stores data related to replica sets. // ReplStatus stores data related to replica sets.
type ReplStatus struct { type ReplStatus struct {
SetName string `bson:"setName"` SetName string `bson:"setName"`
IsMaster interface{} `bson:"ismaster"` IsWritablePrimary interface{} `bson:"isWritablePrimary"` // mongodb 5.x
Secondary interface{} `bson:"secondary"` IsMaster interface{} `bson:"ismaster"`
IsReplicaSet interface{} `bson:"isreplicaset"` Secondary interface{} `bson:"secondary"`
ArbiterOnly interface{} `bson:"arbiterOnly"` IsReplicaSet interface{} `bson:"isreplicaset"`
Hosts []string `bson:"hosts"` ArbiterOnly interface{} `bson:"arbiterOnly"`
Passives []string `bson:"passives"` Hosts []string `bson:"hosts"`
Me string `bson:"me"` Passives []string `bson:"passives"`
Me string `bson:"me"`
} }
// DBRecordStats stores data related to memory operations across databases. // DBRecordStats stores data related to memory operations across databases.
@ -1165,11 +1166,13 @@ func NewStatLine(oldMongo, newMongo MongoStatus, key string, all bool, sampleSec
if newStat.Repl != nil { if newStat.Repl != nil {
returnVal.ReplSetName = newStat.Repl.SetName returnVal.ReplSetName = newStat.Repl.SetName
// BEGIN code modification // BEGIN code modification
if newStat.Repl.IsMaster.(bool) { if val, ok := newStat.Repl.IsMaster.(bool); ok && val {
returnVal.NodeType = "PRI" returnVal.NodeType = "PRI"
} else if newStat.Repl.Secondary != nil && newStat.Repl.Secondary.(bool) { } else if val, ok := newStat.Repl.IsWritablePrimary.(bool); ok && val {
returnVal.NodeType = "PRI"
} else if val, ok := newStat.Repl.Secondary.(bool); ok && val {
returnVal.NodeType = "SEC" returnVal.NodeType = "SEC"
} else if newStat.Repl.ArbiterOnly != nil && newStat.Repl.ArbiterOnly.(bool) { } else if val, ok := newStat.Repl.ArbiterOnly.(bool); ok && val {
returnVal.NodeType = "ARB" returnVal.NodeType = "ARB"
} else { } else {
returnVal.NodeType = "UNK" returnVal.NodeType = "UNK"