vexxhost / openstack_database_exporter

OpenStack Database Exporter for Prometheus
6 stars 0 forks source link

Error while adding custom parameters to DSN #8

Open thundertaker opened 3 months ago

thundertaker commented 3 months ago

I tried to do add custom parameters to my DSN, something like

NEUTRON_DSN="neutron:supersecretpass@tcp(db-host.my.domain:3306)/neutron?tls=skip-verify"

and got this error:

ts=2024-08-19T17:38:27.302Z caller=openstack_database_exporter.go:54 level=info msg="Starting openstack_database_exporter" version="(version=, branch=, revision=914d467f37b78efaf516588789c6263bd7d22838-modified)"
ts=2024-08-19T17:38:27.302Z caller=openstack_database_exporter.go:55 level=info msg="Build context" build_context="(go=go1.22.1, platform=linux/amd64, user=, date=, tags=unknown)"
ts=2024-08-19T17:38:27.302Z caller=gorm_logger.go:42 level=error failedtoinitializedatabase,goterror%v="unsupported value type"
panic: failed to connect database
goroutine 1 [running]:
github.com/vexxhost/openstack_database_exporter/collector.NewNeutronDatabaseCollector({0xb80680, 0xc0001d9a80}, {0xc00002a00c?, 0x5?})
        /data/builds/ops/rpm-specs/infra/prometheus-exporters/openstack-database-exporter/rpmbuild/BUILD/openstack-database-exporter/collector/neutron.go:98 +0x225
main.main()
        /data/builds/ops/rpm-specs/infra/prometheus-exporters/openstack-database-exporter/rpmbuild/BUILD/openstack-database-exporter/openstack_database_exporter.go:59 +0x64b

After inspecting the source code I found out that here:

https://github.com/vexxhost/openstack_database_exporter/blob/8bed552323ecc6f2511a8f74bdd31735c2b157a5/collector/neutron.go#L91

you unconditionally append ?parseTime=True to DSN string, and if the latter already contains ?someparam=value, it breaks. Same for other datasources.

mnaser commented 3 months ago

Ah yes, good catch, ideally, we should add the parseTime=True in a clean way onto parsing the existing it.