From f0f7af21fbbb127586ae1cdd60984950c6b590fc Mon Sep 17 00:00:00 2001 From: Vijay Samuel Date: Wed, 4 Apr 2018 04:37:29 -0700 Subject: [PATCH] Allow autodiscover to monitor unexposed ports (#6727) The metrics hint builder needs a slight change to allow monitoring of endpoints like `${data.host}:9090`. Currently it blocks such cases. For host network containers, there wouldnt be any port on the configuration as well. We would just spin up metricbeat modules, if port is 0 and the host hint has `data.host` on it. --- CHANGELOG.asciidoc | 1 + metricbeat/autodiscover/builder/hints/metrics.go | 4 +++- metricbeat/autodiscover/builder/hints/metrics_test.go | 4 +++- metricbeat/docs/autodiscover-kubernetes-config.asciidoc | 3 +++ 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index 43753e94bc8..b5b7790ffdb 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -272,6 +272,7 @@ https://github.com/elastic/beats/compare/v6.0.0-beta2...master[Check the HEAD di - Set `namespace` as default metricset in Aerospike module. {pull}6669[6669] - Set `service` as default metricset in Windows module. {pull}6675[6675] - Set all metricsets as default metricsets in uwsgi module. {pull}6688[6688] +- Allow autodiscover to monitor unexposed ports {pull}6727[6727] - Mark kubernetes.event metricset as beta. {pull}6715[6715] - Set all metricsets as default metricsets in couchbase module. {pull}6683[6683] - Mark uwsgi module and metricset as beta. {pull}6717[6717] diff --git a/metricbeat/autodiscover/builder/hints/metrics.go b/metricbeat/autodiscover/builder/hints/metrics.go index 8f86e6e4de2..fc9e284ea96 100644 --- a/metricbeat/autodiscover/builder/hints/metrics.go +++ b/metricbeat/autodiscover/builder/hints/metrics.go @@ -136,7 +136,9 @@ func (m *metricHints) getHostsWithPort(hints common.MapStr, port int) []string { // Only pick hosts that have ${data.port} or the port on current event. This will make // sure that incorrect meta mapping doesn't happen for _, h := range thosts { - if strings.Contains(h, "data.port") || strings.Contains(h, fmt.Sprintf(":%d", port)) { + if strings.Contains(h, "data.port") || strings.Contains(h, fmt.Sprintf(":%d", port)) || + // Use the event that has no port config if there is a ${data.host}:9090 like input + (port == 0 && strings.Contains(h, "data.host")) { result = append(result, h) } } diff --git a/metricbeat/autodiscover/builder/hints/metrics_test.go b/metricbeat/autodiscover/builder/hints/metrics_test.go index e516f0e23f6..332bd88b2b8 100644 --- a/metricbeat/autodiscover/builder/hints/metrics_test.go +++ b/metricbeat/autodiscover/builder/hints/metrics_test.go @@ -109,7 +109,8 @@ func TestGenerateHints(t *testing.T) { }, }, { - message: "Module, namespace, host hint should return valid config without port should not return hosts", + message: "Module, namespace, host hint should return valid config with port should return hosts for " + + "docker host network scenario", event: bus.Event{ "host": "1.2.3.4", "hints": common.MapStr{ @@ -128,6 +129,7 @@ func TestGenerateHints(t *testing.T) { "timeout": "3s", "period": "1m", "enabled": true, + "hosts": []interface{}{"1.2.3.4:9090"}, }, }, { diff --git a/metricbeat/docs/autodiscover-kubernetes-config.asciidoc b/metricbeat/docs/autodiscover-kubernetes-config.asciidoc index 51d2b4e8d54..27c222be5a5 100644 --- a/metricbeat/docs/autodiscover-kubernetes-config.asciidoc +++ b/metricbeat/docs/autodiscover-kubernetes-config.asciidoc @@ -17,3 +17,6 @@ metricbeat.autodiscover: ------------------------------------------------------------------------------------- This configuration launches a `prometheus` module for all containers of pods annotated `prometheus.io.scrape=true`. +There are cases where the PodSpec does not expose a port. In such cases the host can be provided as `${data.host}:9090` +directly. However, the metadata which is used to enrich the metric would not have information regarding the container since +the discovery mechanism would not have information on which container the port maps to.