-
Notifications
You must be signed in to change notification settings - Fork 444
Open
Description
Describe the bug
When Exporter works with mongodb + Authentication, when Unauthorizes, it dose not renew session to mongodb and keep error about authentcation
To Reproduce
Steps to reproduce the behavior:
- Run mongodb with authentication
- Run exporter with the following cmd line
/bin/mongodb_exporter --collector.diagnosticdata --collector.replicasetstatus
--compatible-mode --mongodb.direct-connect --mongodb.global-conn-pool --web.listen-address
\":9216\" --mongodb.uri \"mongodb://$MONGODB_ROOT_USER:$(echo $MONGODB_ROOT_PASSWORD
| sed -r \"s/@/%40/g;s/:/%3A/g;s/#/%23/g;s/\\\\$/%24/g\")@localhost:27017/admin?
- This issue happens sometime - not always - timing issue
When exporter is running before the mongodb
See many Unauthorized errors like:
level=error msg="cannot decode getCmdLineOtpions: cannot execute getCmdLineOpts command: (Unauthorized) Command getCmdLineOpts requires authentication"
Expected behavior
When exporter is run with wrong credential is exited
I expect that the exporter will initiate it's session to mongo in case one of it's collector error with authentication
or at least exit
Logs
level=error msg="cannot decode getCmdLineOtpions: cannot execute getCmdLineOpts command: (Unauthorized) Command getCmdLineOpts requires authentication"
Environment
- OS - Limux
- environment - k8s
- MongoDB 7
Additional context
I would offer to add some logic at each collector something like
res := client.Database("admin").RunCommand(d.ctx, cmd)
var r primitive.M
if err := res.Decode(&r); err != nil {
if e, ok := err.(mongo.CommandError); ok {
if e.Code == Unauthorized { // Unauthorized = 13
logger.Errorf("unauthorized to run currtop: %s", err)
os.Exit(1)
// Can handle with reinitiate the connection as well
}
}
}
nikitaz4