Fix invalid DSN after dsnAddTimeout and "" DSN

This commit is contained in:
Pierre Fersing 2016-02-29 19:39:22 +01:00 committed by Cameron Sparr
parent f0747e76da
commit ca3a80fbe1
2 changed files with 7 additions and 5 deletions

View File

@ -216,6 +216,12 @@ func (m *Mysql) gatherServer(serv string, acc telegraf.Accumulator) error {
} }
func dsnAddTimeout(dsn string) (string, error) { func dsnAddTimeout(dsn string) (string, error) {
// DSN "?timeout=5s" is not valid, but "/?timeout=5s" is valid ("" and "/"
// are the same DSN)
if dsn == "" {
dsn = "/"
}
u, err := url.Parse(dsn) u, err := url.Parse(dsn)
if err != nil { if err != nil {
return "", err return "", err

View File

@ -92,11 +92,7 @@ func TestMysqlDNSAddTimeout(t *testing.T) {
}{ }{
{ {
"", "",
"?timeout=5s", "/?timeout=5",
},
{
"127.0.0.1",
"127.0.0.1?timeout=5s",
}, },
{ {
"tcp(192.168.1.1:3306)/", "tcp(192.168.1.1:3306)/",