puppet-mongodb
puppet-mongodb copied to clipboard
Improve mongo output handling
Improve mongo output handling
This PR contains multiple changes to improve stability of parsing mongo output:
changes printjson to JSON.stringify to avoid internal types
In many cases printjson is adding internal types (ObjectId, etc) to the output, which results in an invalid JSON that is not parseable by ruby.
For example, printjson(db.isMaster()) prints something like this:
{
"topologyVersion" : {
"processId" : ObjectId("60995bb5e421c84948b94087"),
"counter" : NumberLong(6)
},
...
}
adds logic to extract error object from a corrupted output
Currently, the handling of exceptions is broken because the existing logic is expecting something parseable in the output, but it's not a valid JSON even after sanitization:
Error: Authentication failed.
2021-05-11T15:35:19.647+0200 E QUERY [thread1] Error: Could not retrieve replica set config: {
"ok" : 0,
"errmsg" : "not authorized on admin to execute command { replSetGetConfig: 1.0, $clusterTime: { clusterTime: Timestamp(0, 0), signature: { hash: BinData(0, 0000000000000000000000000000000000000000), keyId: 0 } }, $readPreference: { mode: \"secondaryPreferred\" }, $db: \"admin\" }",
"code" : 13,
"codeName" : "Unauthorized",
"$clusterTime" : {
"clusterTime" : Timestamp(0, 0),
"signature" : {
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
"keyId" : NumberLong(0)
}
}
} :
rs.conf@src/mongo/shell/utils.js:1323:11
@(shell eval):1:43'
Because of this, replica set provider (that relies on an error data) can't detect that the host is online and fails to properly initialize the replica set.
I've added code that attempts to extract an object in case an output is not a valid JSON.
adds check for error code when detecting failed authorization
The existing logic relies on an error message that potentially may change (because of i18n, etc), which may break it in a long run. I've added a check for a error code name, that is less likely to change.
Dear @ZloeSabo, thanks for the PR!
This is Vox Pupuli Tasks, your friendly Vox Pupuli GitHub Bot. I noticed that your pull request contains merge conflict. Can you please rebase?
You can find my sourcecode at voxpupuli/vox-pupuli-tasks
This should be fixed with #703