Remove dependency from db.hostInfo()

Hi, I was testing a mongodb Atlas shared cluster for genieacs. I found this depends on db.hostInfo() command, which is not allowed on Atlas shared clusters, Looking at the code, I see there is a single usage of that command here. Could we get db time offset computed in a different way such that this command dependency is removed?

Oh, I would also like to inform you that current clusterTime is also reported in the “not Allowed” Error message… so this is quite of LOL

-LuKe

From cache.ts@209:

const res = await db.command({ hostInfo: 1 });
mongoTimeOffset = res.system.currentTime.getTime() - now;

Here is the db.hostInfo() result from a shared Atlas cluster:

MongoDB Enterprise FreeCluster0-shard-0:PRIMARY> db.hostInfo()
{
    "ok" : 0,
    "errmsg" : "not authorized on admin to execute command { hostInfo: 1.0, lsid: { id: {4 [188 255 21 88 225 75 69 62 187 185 211 224 58 146 107 214]} }, $clusterTime: { clusterTime: 6805113691801911297, signature: { hash: [107 196 241 187 113 190 166 22 253 115 117 85 5 130 228 100 93 24 15 183], keyId: 6777040071863304192.000000 } }, $db: \"admin\" }",
    "code" : 8000,
    "codeName" : "AtlasError"
}

I guess clusterTime is not what we want from db.hostInfo(), it is just a logical time for query ordering.

The alternative would be to fix mongoTimeOffset from configs

Ok, I think this one should be fine:

MongoDB Enterprise FreeCluster0-shard-0:PRIMARY> db.serverStatus()
{
    "host" : "freecluster0-shard-00....azure.mongodb.net:27017",
    "version" : "4.2.3",
    "process" : "mongod",
    "pid" : NumberLong(10288),
    "uptime" : 833901,
    "uptimeMillis" : NumberLong(833901023),
    "uptimeEstimate" : NumberLong(833901),
    "localTime" : ISODate("2020-03-17T10:46:32.581Z"),
    …
}

db.serverStatus() is available as allowable action for free clusters when user is granted the proper permission, db.hostInfo() is not. There are multiple timestamps in the output but localTime is the only “stable” one as spec is suggesting: https://docs.mongodb.com/manual/reference/command/serverStatus/#server-status-output

Possible solution:

const res = await db.command({ serverStatus: 1 });
mongoTimeOffset = res.localTime.getTime() - now;

Thanks for looking into this. Let me give it some thought.

1 Like

What is the purpose of this particular code stanza? Is the offset tracking neccesary?

I am in a similar situation as the OP - I can not give the elevated permission set that this line would require due to Information Security regulations I need to abide.

1 Like

This has finally been addressed in the latest master branch. Should make it into the upcoming v1.2.4 soon.

Awesome! Thank you. Will test 1.2.4 when it’s out.