Skip to content

Commit

Permalink
Merge pull request #707 from yosida95/unix-domain-socket
Browse files Browse the repository at this point in the history
Add UNIX domain socket support for multi-target scraping
  • Loading branch information
SuperQ committed Apr 14, 2023
2 parents 7f4eb83 + 0c4f492 commit 34817b7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"net"
"os"
"strconv"
"strings"
"sync"

"github.com/go-kit/log"
Expand Down Expand Up @@ -193,6 +194,9 @@ func (m MySqlConfig) FormDSN(target string) (string, error) {
config.Net = "unix"
config.Addr = m.Socket
}
} else if prefix := "unix://"; strings.HasPrefix(target, prefix) {
config.Net = "unix"
config.Addr = target[len(prefix):]
} else {
if _, _, err = net.SplitHostPort(target); err != nil {
return "", fmt.Errorf("failed to parse target: %s", err)
Expand Down
8 changes: 8 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,14 @@ func TestFormDSN(t *testing.T) {
}
convey.So(dsn, convey.ShouldEqual, "test:foo@tcp(server1:5000)/")
})
convey.Convey("UNIX domain socket", func() {
cfg := c.GetConfig()
section := cfg.Sections["client.server1"]
if dsn, err = section.FormDSN("unix:///run/mysqld/mysqld.sock"); err != nil {
t.Error(err)
}
convey.So(dsn, convey.ShouldEqual, "test:foo@unix(/run/mysqld/mysqld.sock)/")
})
})
}

Expand Down

0 comments on commit 34817b7

Please sign in to comment.