Skip to content

Commit

Permalink
Add docs for http+unix in Metricbeat (#22891) (#22953)
Browse files Browse the repository at this point in the history
(cherry picked from commit c2272c1)
  • Loading branch information
jsoriano authored Dec 8, 2020
1 parent f70f017 commit 5812c1b
Show file tree
Hide file tree
Showing 32 changed files with 123 additions and 69 deletions.
9 changes: 8 additions & 1 deletion metricbeat/docs/metricbeat-options.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,13 @@ clusters with the same `service.type`.
[[module-http-config-options]]
=== Standard HTTP config options

Modules and metricsets that define the host as an HTTP URL can use the standard
schemes for HTTP (`http://` and `https://`) and the following schemes to connect
to local pipes:

* `http+unix://` to connect to UNIX sockets.
* `http+npipe://` to connect to Windows named pipes.

The following options are available for modules and metricsets that define the
host as an HTTP URL:

Expand Down Expand Up @@ -316,4 +323,4 @@ query:
:modulename!:

// Add Javascript and CSS for tabbed panels
include::{libbeat-dir}/tab-widgets/code.asciidoc[]
include::{libbeat-dir}/tab-widgets/code.asciidoc[]
3 changes: 3 additions & 0 deletions metricbeat/docs/modules/appsearch.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ metricbeat.modules:
#password: "changeme"
----

This module supports TLS connections when using `ssl` config field, as described in <<configuration-ssl>>.
It also supports the options described in <<module-http-config-options>>.

[float]
=== Metricsets

Expand Down
3 changes: 3 additions & 0 deletions metricbeat/docs/modules/consul.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ metricbeat.modules:
----

This module supports TLS connections when using `ssl` config field, as described in <<configuration-ssl>>.
It also supports the options described in <<module-http-config-options>>.

[float]
=== Metricsets

Expand Down
3 changes: 3 additions & 0 deletions metricbeat/docs/modules/couchdb.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ metricbeat.modules:
hosts: ["localhost:5984"]
----

This module supports TLS connections when using `ssl` config field, as described in <<configuration-ssl>>.
It also supports the options described in <<module-http-config-options>>.

[float]
=== Metricsets

Expand Down
2 changes: 2 additions & 0 deletions metricbeat/docs/modules/docker.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ metricbeat.modules:
#key: "/etc/pki/client/cert.key"
----

This module supports TLS connections when using `ssl` config field, as described in <<configuration-ssl>>.

[float]
=== Metricsets

Expand Down
3 changes: 3 additions & 0 deletions metricbeat/docs/modules/envoyproxy.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ metricbeat.modules:
hosts: ["localhost:9901"]
----

This module supports TLS connections when using `ssl` config field, as described in <<configuration-ssl>>.
It also supports the options described in <<module-http-config-options>>.

[float]
=== Metricsets

Expand Down
1 change: 1 addition & 0 deletions metricbeat/docs/modules/ibmmq.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ metricbeat.modules:
metrics_path: /metrics
----

This module supports TLS connections when using `ssl` config field, as described in <<configuration-ssl>>.
It also supports the options described in <<module-http-config-options>>.

[float]
Expand Down
3 changes: 3 additions & 0 deletions metricbeat/docs/modules/istio.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ metricbeat.modules:
hosts: ['localhost:15090']
----

This module supports TLS connections when using `ssl` config field, as described in <<configuration-ssl>>.
It also supports the options described in <<module-http-config-options>>.

[float]
=== Metricsets

Expand Down
3 changes: 3 additions & 0 deletions metricbeat/docs/modules/nats.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ metricbeat.modules:
#route.metrics_path: "/routez"
----

This module supports TLS connections when using `ssl` config field, as described in <<configuration-ssl>>.
It also supports the options described in <<module-http-config-options>>.

[float]
=== Metricsets

Expand Down
3 changes: 3 additions & 0 deletions metricbeat/docs/modules/stan.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ metricbeat.modules:
#subscriptions.metrics_path: "/streaming/channelsz" # we retrieve streaming subscriptions with a detailed query param to the channelsz endpoint
----

This module supports TLS connections when using `ssl` config field, as described in <<configuration-ssl>>.
It also supports the options described in <<module-http-config-options>>.

[float]
=== Metricsets

Expand Down
3 changes: 3 additions & 0 deletions metricbeat/docs/modules/traefik.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ metricbeat.modules:
hosts: ["localhost:8080"]
----

This module supports TLS connections when using `ssl` config field, as described in <<configuration-ssl>>.
It also supports the options described in <<module-http-config-options>>.

[float]
=== Metricsets

Expand Down
125 changes: 68 additions & 57 deletions metricbeat/helper/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (

"github.com/elastic/beats/v7/metricbeat/helper/dialer"
"github.com/elastic/beats/v7/metricbeat/mb"
"github.com/elastic/beats/v7/metricbeat/mb/parse"
)

func TestGetAuthHeaderFromToken(t *testing.T) {
Expand Down Expand Up @@ -196,80 +197,76 @@ func TestOverUnixSocket(t *testing.T) {
return
}

t.Run("at root", func(t *testing.T) {
tmpDir, err := ioutil.TempDir("", "testsocket")
require.NoError(t, err)
defer os.RemoveAll(tmpDir)

sockFile := tmpDir + "/test.sock"
cases := map[string]struct {
hostDataBuilder func(sockFile string) (mb.HostData, error)
}{
"at root": {
hostDataBuilder: func(sockFile string) (mb.HostData, error) {
return mb.HostData{
Transport: dialer.NewUnixDialerBuilder(sockFile),
URI: "http://unix/",
SanitizedURI: "http://unix",
}, nil
},
},
"at specific path": {
hostDataBuilder: func(sockFile string) (mb.HostData, error) {
uri := "http://unix/ok"
return mb.HostData{
Transport: dialer.NewUnixDialerBuilder(sockFile),
URI: uri,
SanitizedURI: uri,
}, nil
},
},
"with parser builder": {
hostDataBuilder: func(sockFile string) (mb.HostData, error) {
parser := parse.URLHostParserBuilder{}.Build()
return parser(&dummyModule{}, "http+unix://"+sockFile)
},
},
}

l, err := net.Listen("unix", sockFile)
serveOnUnixSocket := func(t *testing.T, path string) net.Listener {
l, err := net.Listen("unix", path)
require.NoError(t, err)

defer l.Close()

mux := http.NewServeMux()
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "ehlo!")
})

go http.Serve(l, mux)

cfg := defaultConfig()
hostData := mb.HostData{
Transport: dialer.NewUnixDialerBuilder(sockFile),
URI: "http://unix/",
SanitizedURI: "http://unix",
}

h, err := newHTTPFromConfig(cfg, "test", hostData)
require.NoError(t, err)
return l
}

r, err := h.FetchResponse()
require.NoError(t, err)
defer r.Body.Close()
content, err := ioutil.ReadAll(r.Body)
require.NoError(t, err)
assert.Equal(t, []byte("ehlo!"), content)
})
for title, c := range cases {
t.Run(title, func(t *testing.T) {
tmpDir, err := ioutil.TempDir("", "testsocket")
require.NoError(t, err)
defer os.RemoveAll(tmpDir)

t.Run("at specific path", func(t *testing.T) {
tmpDir, err := ioutil.TempDir("", "testsocket")
require.NoError(t, err)
defer os.RemoveAll(tmpDir)
sockFile := tmpDir + "/test.sock"
l := serveOnUnixSocket(t, sockFile)
defer l.Close()

sockFile := tmpDir + "/test.sock"
uri := "http://unix/ok"
cfg := defaultConfig()

l, err := net.Listen("unix", sockFile)
require.NoError(t, err)
hostData, err := c.hostDataBuilder(sockFile)
require.NoError(t, err)

defer l.Close()
h, err := newHTTPFromConfig(cfg, "test", hostData)
require.NoError(t, err)

mux := http.NewServeMux()
mux.HandleFunc("/ok", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "ehlo!")
r, err := h.FetchResponse()
require.NoError(t, err)
defer r.Body.Close()
content, err := ioutil.ReadAll(r.Body)
require.NoError(t, err)
assert.Equal(t, []byte("ehlo!"), content)
})

go http.Serve(l, mux)

cfg := defaultConfig()
hostData := mb.HostData{
Transport: dialer.NewUnixDialerBuilder(sockFile),
URI: uri,
SanitizedURI: uri,
}

h, err := newHTTPFromConfig(cfg, "test", hostData)
require.NoError(t, err)

r, err := h.FetchResponse()
require.NoError(t, err)
defer r.Body.Close()
content, err := ioutil.ReadAll(r.Body)
require.NoError(t, err)
assert.Equal(t, []byte("ehlo!"), content)
})
}
}

func checkTimeout(t *testing.T, h *HTTP) {
Expand All @@ -291,3 +288,17 @@ func checkTimeout(t *testing.T, h *HTTP) {
t.Fatal("timeout should have happened time ago")
}
}

type dummyModule struct{}

func (*dummyModule) Name() string {
return "dummy"
}

func (*dummyModule) Config() mb.ModuleConfig {
return mb.ModuleConfig{}
}

func (*dummyModule) UnpackConfig(interface{}) error {
return nil
}
1 change: 1 addition & 0 deletions metricbeat/module/consul/_meta/fields.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
description: >
Consul module
release: beta
settings: ["ssl", "http"]
fields:
- name: consul
type: group
Expand Down
2 changes: 1 addition & 1 deletion metricbeat/module/consul/fields.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions metricbeat/module/couchdb/_meta/fields.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
description: >
couchdb module
release: ga
settings: ["ssl", "http"]
fields:
- name: couchdb
type: group
Expand Down
2 changes: 1 addition & 1 deletion metricbeat/module/couchdb/fields.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions metricbeat/module/docker/_meta/fields.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
description: >
Docker stats collected from Docker.
release: ga
settings: ["ssl"]
short_config: false
fields:
- name: docker
Expand Down
2 changes: 1 addition & 1 deletion metricbeat/module/docker/fields.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions metricbeat/module/envoyproxy/_meta/fields.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
description: >
envoyproxy module
release: ga
settings: ["ssl", "http"]
fields:
- name: envoyproxy
type: group
Expand Down
Loading

0 comments on commit 5812c1b

Please sign in to comment.