percona / mongodb_exporter

A Prometheus exporter for MongoDB including sharding, replication and storage engines
Apache License 2.0
1.16k stars 425 forks source link

Invalid DSN error for standard replica set connection string #887

Open wdonne opened 1 month ago

wdonne commented 1 month ago

Describe the bug When using a standard connection string for a MongoDB replica set like mongodb://username:password@hostname-0,hostname-1,hostname-2, the following error message appears in the logs: "Cannot connect to MongoDB: invalid dsn: error parsing uri: scheme must be \"mongodb\" or \"mongodb+srv\"" To Reproduce Steps to reproduce the behavior:

  1. Create a secret with such a connection string
  2. Use a secretRef to refer to it

Expected behavior The connection to MongoDB should succeed.

Logs "Cannot connect to MongoDB: invalid dsn: error parsing uri: scheme must be \"mongodb\" or \"mongodb+srv\""

Environment

Additional context The example of a mongodb+srv URI in the documentation is wrong. Such a URI can't have multiple hosts or ports. It uses a DNS SRV record to discover all the members of a replica set. With the mongodb scheme, all the hosts of the replica set should be specified.

BupycHuk commented 1 month ago

Hi, what version of mongodb_exporter did you use? We haven't released mongodb_exporter with these changes yet.