mysqld_exporter icon indicating copy to clipboard operation
mysqld_exporter copied to clipboard

can't use socket files with '@' in the name

Open MosesMooreGameloft opened this issue 2 years ago • 4 comments

Host operating system: output of uname -a

Linux [hostname] 4.19.0-8-amd64 #1 SMP Debian 4.19.98-1 (2020-01-26) x86_64 GNU/Linux

mysqld_exporter version: output of mysqld_exporter --version

mysqld_exporter, version 0.15.0 (branch: main, revision: 59ecd933087164022e18f67b18e5f80494658f11) build user: mmoore@[hostname] build date: 20230824-14:45:11 go version: go1.20 platform: linux/amd64 tags: netgo

MySQL server version

percona-server-common-5.7 5.7.28-31-1.buster

mysqld_exporter command line flags

/usr/bin/prometheus-mysqld-exporter --web.listen-address 127.0.0.1:9104 \
   --config.my-cnf /etc/prometheus/.my.cnf --collect.info_schema.innodb_metrics \
   --no-collect.info_schema.tables

contents of .my.cnf

[client]
user=prometheus
password=[redacted]

What did you do that produced an error?

We have multiple mysql instances on each machine, and we had to use multiple simultaneous daemons each configured for one of the instances. I'm hoping to use new /probe endpoint.

$ ls /run/mysqld
mysqld@mdb_olympus.pid
mysqld@mdb_olympus.sock
mysqld@mdb_ararat.pid
mysqld@mdb_ararat.sock
mysqld@mdb_killaraus.pid
mysqld@mdb_killaraus.sock
$ curl 'http://localhost:9104/probe?target=unix:///run/mysqld/mysqld@mdb_olympus.sock'

What did you expect to see?

  • mysql_up 1

What did you see instead?

  • mysql_up 0
  • in the stderr for mysqld_exporter I see level=error msg="Error opening connection to database" err="default addr for network 'mdb_olympus.sock)' unknown

If I do this:

ln -s mysqld@mdb_olympus.sock /run/mysqld/mysqld_mdb_olympus.sock
curl 'http://localhost:9104/probe?target=unix:///run/mysqld/mysqld_mdb_olympus.sock'

Now I get the metrics I hoped for. So I believe the '@' in the target parameter is doing something unexpected. I also tried substituting %40 for @ and still got the "default addr for network 'mdb_olympus.sock)' unknown". The @ signs are there because we're using systemd units to start/stop/restart the mysqld instances.

I can use mysql --socket=/run/mysqld/mysqld@mdb_olympus.sock without trouble so I don't believe '@' characters are illegal for mysql.

MosesMooreGameloft avatar Aug 30 '23 17:08 MosesMooreGameloft

This could be a URL encode/decode issue with the target parameter handling.

SuperQ avatar Sep 11 '23 14:09 SuperQ

I doubt it's a URI encoding issue. Likely it's a tokenizing problem since if there is // followed by @ sign in a URI then the string between those two is supposed to be the userinfo... but then %40 should work as a safe character to use in the path part, and I get the same error message.

  • {{scheme}}:{{path}}
  • {{scheme}}://{{host}}{{path}}
  • {{scheme}}://{{userinfo}}@{{host}}{{path}}

EDIT: now that I look more closely at the URI definition, I shouldn't need a // between unix: and /var/run/mysqld.sock but it doesn't work unless I do that... which implies a null string as the "host" part of the URI. weird.

MosesMooreGameloft avatar Sep 11 '23 15:09 MosesMooreGameloft

The exporter uses the Go mysql driver Config to format the connection.

In order to determine the Net type, we parse the target parameter in https://github.com/prometheus/mysqld_exporter/blob/59ecd933087164022e18f67b18e5f80494658f11/config/config.go#L194-L196. We require the target contain the string unix:// in order to activate unix socket connections. We then strip that string from the target string.

So, we need a debug line to find out exactly what is being passed to the Config.Addr.

SuperQ avatar Sep 11 '23 16:09 SuperQ

Related for mainly informational purposes is that MariaDB in server configuration and parsing using MariaDB Connector C will use a leading @ in the socket variable as an indicator for an abstract (not on filesystem) socket in the same way that systemd does. The Go MySQL Driver doesn't do this currently.

grooverdan avatar Jan 28 '25 23:01 grooverdan