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

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

Open
MosesMooreGameloft opened this issue Aug 30, 2023 · 4 comments
Open

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

MosesMooreGameloft opened this issue Aug 30, 2023 · 4 comments

Comments

@MosesMooreGameloft
Copy link

MosesMooreGameloft commented Aug 30, 2023

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: 59ecd93)
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.

@SuperQ
Copy link
Member

SuperQ commented Sep 11, 2023

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

@MosesMooreGameloft
Copy link
Author

MosesMooreGameloft commented Sep 11, 2023

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.

@SuperQ
Copy link
Member

SuperQ commented Sep 11, 2023

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

} else if prefix := "unix://"; strings.HasPrefix(target, prefix) {
config.Net = "unix"
config.Addr = target[len(prefix):]
. 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.

@grooverdan
Copy link
Contributor

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.

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

No branches or pull requests

3 participants