Skip to content

solve compatibility issue for mongodb inputs when using 5.x relicaset #9895

@alonlong

Description

@alonlong
if newStat.Repl != nil {
		returnVal.ReplSetName = newStat.Repl.SetName
		// BEGIN code modification
		if newStat.Repl.IsMaster.(bool) {
			returnVal.NodeType = "PRI"
		} else if newStat.Repl.Secondary != nil && newStat.Repl.Secondary.(bool) {
			returnVal.NodeType = "SEC"
		} else if newStat.Repl.ArbiterOnly != nil && newStat.Repl.ArbiterOnly.(bool) {
			returnVal.NodeType = "ARB"
		} else {
			returnVal.NodeType = "UNK"
		} // END code modification
	}

when using telegraf collects mongodb metrics with 5.x replicaset, newStat.Repl.IsMaster.(bool) will cause a crash, the reason is that the 'repl' of serverStatus in 5.x use 'isWritablePrimary' instead of 'ismaster'

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/mongodbbugunexpected problem or unintended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions