meln5674 / grafana-mongodb-community-plugin

Open Source Grafana Plugin for querying MongoDB
GNU Affero General Public License v3.0
137 stars 18 forks source link

Issue connecting to mongodb://localhost:27017/ #22

Closed samleeney closed 1 year ago

samleeney commented 1 year ago

After hanging for a while, the following error comes up:

Ping failed: server selection error: server selection timeout, current topology: { Type: Unknown, Servers: [{ Addr: localhost:27017, Type: Unknown, Last error: connection() error occurred during connection handshake: dial tcp: lookup localhost on 131.111.8.42:53: no such host }, ] }

Running grafana locally on archlinux. I can connect to a remote test server, but not my local database.

I had initially thought the issue was due to Docker not communicating with my local host, but I have switched to a barebones install and the issue persists.

meln5674 commented 1 year ago

I don't believe that's an issue in the plugin. If it needs to go to your DNS server for "localhost", that says to me its missing in your /etc/hosts file, as "localhost" on its own has no intrinsic meaning. To test this, try setting your server address to 127.0.0.1 instead of localhost, and see if the error persists, or if you get a different error.

samleeney commented 1 year ago

Thanks for the reply. Unfortunately still getting the same error. I will add that I can connect to the database via mongo compass using the 127.0.0.1:27017.

Ping failed: server selection error: server selection timeout, current topology: { Type: Unknown, Servers: [{ Addr: 127.0.0.1:27017, Type: Unknown, Last error: connection() error occurred during connection handshake: dial tcp 127.0.0.1:27017: connect: connection refused }, ] }

meln5674 commented 1 year ago

Again, that doesn't look like an issue in the plugin, that's simply it saying there's no network connectivity between your grafana and your mongodb, specifically, whatever network interface your grafana considers to be local has nothing listening on the mongo 27017 port. You mentioned you switched to a "barebones" install, am I correct in assuming you mean you are not running either mongo or grafana in docker, and both are running on the same machine you are running your compass on, with no firewall interfering?

samleeney commented 1 year ago

I correct in assuming you mean you are not running either mongo or grafana in docker, and both are running on the same machine you are running your compass on

Yep - grafana and mongo are both running on the same machine I am running compass on. On compass I can connect to mongo with mongodb://localhost:27017/.

that doesn't look like an issue in the plugin

It may very well be user error, but I have tried every which way but cannot seem to figure it out. Networking (even basic) stuff is outside of my field of expertise.

meln5674 commented 1 year ago

The only thing I can think of that would cause this is some kind of firewall, or you are still running in docker and not realizing it.

samleeney commented 1 year ago

Definitely not running in docker - an interaction with a firewall is definitely possible. What I don't understand is why the mongodb-grafana bridge would interact differently with some firewall than compass given they are both connecting through local host. I assume there is some other interaction I am misunderstanding?

meln5674 commented 1 year ago

If you're running something like SELinux or AppArmor, there could be some interaction at the kernel level where compass is explicitly whitelisted as being allowed to connect, while other applications aren't. I'm not an expert in either, but I've seen issues like that in the past. You can try hitting mongodb with curl, which will obviously fail, but if it fails with the same "connection refused" error instead of a "this isn't an http server"-type error, that's an indication that something inbetween grafana and mongodb is interfering. Another idea might be to start a blank docker container or virtual machine, exec in and install mongodb, grafana, and the plugin, and see if anything changes.

samleeney commented 1 year ago

Thanks for the extensive help with this. The problem ended up being related to extremely strict firewall settings on my network interfering with things. It was resolved by connecting on another network, which is not an ideal solution but I think enough to close the issue.