Skip to content

Commit 65d9e0b

Browse files
authored
fix mongo exporter auth in secondary mongod (#29)
1 parent 6f3aa6f commit 65d9e0b

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

shared/connection.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,17 @@ func MongoSession(opts MongoSessionOpts) *mgo.Session {
5656
return nil
5757
}
5858

59+
// For direct connection, we need to set mode to be Monotonic (similar to SecondaryPreferred) or
60+
// Eventual (similar to Nearest) before login. Otherwise, mongo exporter can not log in secondary mongod.
61+
session.SetMode(mgo.Eventual, true)
62+
5963
if cred != nil {
6064
if err := session.Login(cred); err != nil {
6165
glog.Errorf("Cannot login to server using TLS credential: %s", err)
6266
return nil
6367
}
6468
}
6569

66-
session.SetMode(mgo.Eventual, true)
6770
session.SetSyncTimeout(syncMongodbTimeout)
6871
session.SetSocketTimeout(opts.SocketTimeout)
6972
return session

0 commit comments

Comments
 (0)