Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exporter not initiating connection to mongo when Unauthorized #1011

Open
dudigit opened this issue Jan 19, 2025 · 0 comments
Open

Exporter not initiating connection to mongo when Unauthorized #1011

dudigit opened this issue Jan 19, 2025 · 0 comments

Comments

@dudigit
Copy link

dudigit commented Jan 19, 2025

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:

  1. Run mongodb with authentication
  2. 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?
  1. 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 

        }

    }

}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant