Skip to content

Commit

Permalink
Correctly format the path to read data from npipe. (elastic#15997)
Browse files Browse the repository at this point in the history
This is not a fix for elastic#15832 this will be tackle in another PR.
When http+npipe:// scheme were initially parsed by the url parser of
metric the generated PATH wasn't correctly setup up. So I've fixed the
parsing and the tests.

Now to test the behavior on Windows you will need a beat that expose metrics over
npipes, you can do so with a configuration like this.

```yaml
metricbeat.modules:
  - module: system

output.console: ~

http.enabled: true
http.host: \\.\pipe\custom
```yaml

After you can start a Metricbeat instance with the beat modules to
collect the metric information.

```yaml
metricbeat.modules:
- module: beat
  hosts: http+npipe://./pipe/custom
  metricsets:
  - stats
  - state
output.console: ~
```

If you start metricbeat with the `-e -d "*"` flags this will output any
metrics fetched from the running beat instance.

Fixes: elastic#15938
(cherry picked from commit 75ddc22)
  • Loading branch information
ph committed Feb 4, 2020
1 parent 14ea1ab commit 9e1c5ce
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion metricbeat/mb/parse/url.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func getURL(
u.Scheme = "http"
u.Host = "unix"
case "http+npipe":
p := strings.Replace(u.Path, "/pipe", `\\.pipe`, 1)
p := strings.Replace(u.Path, "/pipe", `\\.\pipe`, 1)
p = strings.Replace(p, "/", "\\", -1)
t = dialer.NewNpipeDialerBuilder(p)
u.Path = ""
Expand Down
4 changes: 2 additions & 2 deletions metricbeat/mb/parse/url_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func TestParseURL(t *testing.T) {
if assert.NoError(t, err) {
transport, ok := hostData.Transport.(*dialer.NpipeDialerBuilder)
assert.True(t, ok)
assert.Equal(t, `\\.pipe\custom`, transport.Path)
assert.Equal(t, `\\.\pipe\custom`, transport.Path)
assert.Equal(t, "http://npipe", hostData.URI)
assert.Equal(t, "http://npipe", hostData.SanitizedURI)
assert.Equal(t, "npipe", hostData.Host)
Expand All @@ -112,7 +112,7 @@ func TestParseURL(t *testing.T) {
if assert.NoError(t, err) {
transport, ok := hostData.Transport.(*dialer.NpipeDialerBuilder)
assert.True(t, ok)
assert.Equal(t, `\\.pipe\custom`, transport.Path)
assert.Equal(t, `\\.\pipe\custom`, transport.Path)
assert.Equal(t, "http://npipe/apath", hostData.URI)
assert.Equal(t, "http://npipe/apath", hostData.SanitizedURI)
assert.Equal(t, "npipe", hostData.Host)
Expand Down

0 comments on commit 9e1c5ce

Please sign in to comment.