From 0e3a8d8205a79fb08f34606314e5ae793cc9afaa Mon Sep 17 00:00:00 2001 From: Pierre Fersing Date: Mon, 29 Feb 2016 19:39:22 +0100 Subject: [PATCH] Fix invalid DSN after dsnAddTimeout and "" DSN --- plugins/inputs/mysql/mysql.go | 6 ++++++ plugins/inputs/mysql/mysql_test.go | 6 +----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/plugins/inputs/mysql/mysql.go b/plugins/inputs/mysql/mysql.go index cd9e7ae28..474067716 100644 --- a/plugins/inputs/mysql/mysql.go +++ b/plugins/inputs/mysql/mysql.go @@ -216,6 +216,12 @@ func (m *Mysql) gatherServer(serv string, acc telegraf.Accumulator) 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) if err != nil { return "", err diff --git a/plugins/inputs/mysql/mysql_test.go b/plugins/inputs/mysql/mysql_test.go index 0b25fe2be..50c1ed7b7 100644 --- a/plugins/inputs/mysql/mysql_test.go +++ b/plugins/inputs/mysql/mysql_test.go @@ -92,11 +92,7 @@ func TestMysqlDNSAddTimeout(t *testing.T) { }{ { "", - "?timeout=5s", - }, - { - "127.0.0.1", - "127.0.0.1?timeout=5s", + "/?timeout=5", }, { "tcp(192.168.1.1:3306)/",