Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cherry-pick #4751 to 6.0: Support npipe URLs in host parser #4762

Merged
merged 1 commit into from
Jul 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ https://github.com/elastic/beats/compare/v6.0.0-beta1...master[Check the HEAD di

*Metricbeat*

- Support `npipe` protocol (Windows) in Docker module. {pull}4751[4751]

*Packetbeat*

*Winlogbeat*
Expand Down
7 changes: 4 additions & 3 deletions metricbeat/mb/parse/url.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ func (b URLHostParserBuilder) Build() mb.HostParser {

// NewHostDataFromURL returns a new HostData based on the contents of the URL.
// If the URLs scheme is "unix" or end is "unix" (e.g. "http+unix://") then
// the HostData.Host field is set to the URLs path instead of the URLs host.
// the HostData.Host field is set to the URLs path instead of the URLs host,
// the same happens for "npipe".
func NewHostDataFromURL(u *url.URL) mb.HostData {
var user, pass string
if u.User != nil {
Expand All @@ -70,7 +71,7 @@ func NewHostDataFromURL(u *url.URL) mb.HostData {
}

host := u.Host
if strings.HasSuffix(u.Scheme, "unix") {
if strings.HasSuffix(u.Scheme, "unix") || strings.HasSuffix(u.Scheme, "npipe") {
host = u.Path
}

Expand Down Expand Up @@ -140,7 +141,7 @@ func getURL(rawURL, scheme, username, password, path, query string) (*url.URL, e

SetURLUser(u, username, password)

if !strings.HasSuffix(u.Scheme, "unix") {
if !strings.HasSuffix(u.Scheme, "unix") && !strings.HasSuffix(u.Scheme, "npipe") {
if u.Host == "" {
return nil, fmt.Errorf("error parsing URL: empty host")
}
Expand Down
12 changes: 12 additions & 0 deletions metricbeat/mb/parse/url_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@ func TestParseURL(t *testing.T) {
}
})

t.Run("npipe", func(t *testing.T) {
rawURL := "npipe://./pipe/docker_engine"
hostData, err := ParseURL(rawURL, "tcp", "", "", "", "")
if assert.NoError(t, err) {
assert.Equal(t, "npipe://./pipe/docker_engine", hostData.URI)
assert.Equal(t, "npipe://./pipe/docker_engine", hostData.SanitizedURI)
assert.Equal(t, "/pipe/docker_engine", hostData.Host)
assert.Equal(t, "", hostData.User)
assert.Equal(t, "", hostData.Password)
}
})

t.Run("set default user", func(t *testing.T) {
rawURL := "http://:secret@localhost"
h, err := ParseURL(rawURL, "https", "root", "passwd", "", "")
Expand Down