Skip to content

Commit

Permalink
Fix invalid DSN after dsnAddTimeout and "" DSN
Browse files Browse the repository at this point in the history
  • Loading branch information
PierreF authored and sparrc committed Mar 1, 2016
1 parent f0747e7 commit ca3a80f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
6 changes: 6 additions & 0 deletions plugins/inputs/mysql/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 1 addition & 5 deletions plugins/inputs/mysql/mysql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)/",
Expand Down

0 comments on commit ca3a80f

Please sign in to comment.