sql_exporter
sql_exporter copied to clipboard
Metric label collision
I want to select user-level stats from a database and naturally I added user as a label for my metrics. Unfortunately, sql_exporter crashed immediately, because it adds a lot of own labels:
panic: descriptor Desc{fqName: "sql_clickhouse_user_query_read_rows", help: "Rows read in queries", constLabels: {}, variableLabels: [user type driver host database user col]} is invalid: duplicate label names
goroutine 1 [running]:
github.com/justwatchcom/sql_exporter/vendor/github.com/prometheus/client_golang/prometheus.(*Registry).MustRegister(0xc420044880, 0xc4202ac850, 0x1, 0x1)
/Users/bobrik/projects/sql_exporter/src/github.com/justwatchcom/sql_exporter/vendor/github.com/prometheus/client_golang/prometheus/registry.go:353 +0x92
github.com/justwatchcom/sql_exporter/vendor/github.com/prometheus/client_golang/prometheus.MustRegister(0xc4202ac850, 0x1, 0x1)
/Users/bobrik/projects/sql_exporter/src/github.com/justwatchcom/sql_exporter/vendor/github.com/prometheus/client_golang/prometheus/registry.go:152 +0x53
main.main()
/Users/bobrik/projects/sql_exporter/src/github.com/justwatchcom/sql_exporter/main.go:63 +0x7a5
Relabeling later in Prometheus seems cumbersome. Not sure what's the cleanest way forward here.
Thank you for bringing this up.
I see two options here: Either you don't use conflicting rows names in your queries, or we rename these fields in the SQL exporter. As they are very generic it may make sense to do so.
I'm not quite sure what the best naming would be. Maybe something like sql_connection_user?
Of course this could conflict as well, if someone wants to return an row named sql_connection_user.
sql_exporter_ may be a more specific prefix than sql_connection_.