Cannot add MongoDB on a port other than 27017
Description
How to test
How to document
Attachments
relates to
Smart Checklist
Activity

Carlos Salguero September 30, 2021 at 11:05 AM
The thing is that each instance is part of a replicaset. Internally, they are connected to each other using "some" network identifier/ip.
When a program tries to connect not forcing the direct connection, the driver tries to use Mongo's internal hostnames but for example, when running in a docker container or a remote network, your local DNS won't be able to resolve the hostname.
If you use direct, the driver will connect using only the ip/hostname provided in the DSN and won't try to check the replicaset members.
Also, internally, the replicaset members can be using the standard port 27017 but to the outside world, there might be exposing different ports. In non-direct connections, the replicaset members are defined as host1:27017, host2:27017, host3:27017 but when the driver tries to use that, even when the hostname can be resolved, the port won't.

Jyoti Prakash September 28, 2021 at 2:31 PM
Pls Ignore my comments

Jyoti Prakash September 28, 2021 at 1:43 PM
- can you please let me know the steps- what update did you make?
Also, are you getting the metrics as well?

Carlos Salguero September 22, 2021 at 6:56 PM
The problem is related to the hostname.
sent me a docker-compose.yml, a shell script to start the cluster and instructions to update /etc/hosts and I am able to add the instances.
We need to investigate if this is something related to the connection checker, the driver or any other source.
I am attaching a tar.gz file with the scripts

Puneet Kala September 21, 2021 at 9:40 AMEdited
we use some setup on our test instances without custom ports, for example, see this:
While trying to reproduce , I started the mongodb_exporter sandbox which exposes MongoDB instances in non standard ports (17001, ..., 17012) but I cannot add any instance from UI nor from pmm-admin.
The error shows that pmm is using port 27017 even when I've specified a different port
pmm-admin using --host and --port
pmm-admin using URI:
After some investigation I've found the problem is in the connection checker and it might be necessary to update also pmm-agent/QAN.
When the connection is not forced to be direct, it is not possible to connect from a docker container to a remote instance (or running on a different container) since the driver will try to resolve the hostname but that's not possible.
I made a small go program, ran it from a container trying to connect to a remote instance in replicaset and in direct modes.
Using direct mode the connection works fine:
I am also attaching the program used to test.
User Impact:
It it not possible to add an external cluster if you are not using the default ports.
Most users run MongoDB on the default port so this is not critical but we should support running MongoDB on a non-default port.
Workaround
TBD
Proposed resolution
Force direct connection to MongoDB in connection checker and pmm-agent/QAN
How to test
1. Start a MongoDB cluster using docker . It can be the sandbox from mongodb_exporter. If you want to use this sandbox, just clone the repo and run make test-cluster.
2. Start pmm-server docker
3. From the UI add a remote MongoDB instance. Use your host IP address and the port 17001 to connect to the sandbox's primary
4. The connection must succeed.