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

Document support for http over unix sockets and named pipes in Metricbeat #22891

Merged
merged 1 commit into from
Dec 7, 2020
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
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 @@ -28,6 +28,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, 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, 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, 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"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great to see this reusable component. @mtojek @ycombinator Would be great to have something like this also for the build process of integrations to pull in shared doc snippets.

fields:
- name: envoyproxy
type: group
Expand Down
Loading