From 442257c42dad0ad789aa7b0bedf27647d7247cc6 Mon Sep 17 00:00:00 2001 From: cdelgado Date: Fri, 14 Jan 2022 12:12:46 +0100 Subject: [PATCH 01/13] Add xpack.enabled: true to Enterprise Search metricbeat module --- metricbeat/helper/elastic/elastic.go | 5 +++++ .../module/enterprisesearch/docker-compose.yml | 2 +- .../module/enterprisesearch/health/data.go | 10 +++++++++- .../module/enterprisesearch/health/health.go | 15 +++++++++++++-- .../module/enterprisesearch/stats/data.go | 10 +++++++++- .../module/enterprisesearch/stats/stats.go | 15 +++++++++++++-- 6 files changed, 50 insertions(+), 7 deletions(-) diff --git a/metricbeat/helper/elastic/elastic.go b/metricbeat/helper/elastic/elastic.go index 837ff6150646..c51179747e16 100644 --- a/metricbeat/helper/elastic/elastic.go +++ b/metricbeat/helper/elastic/elastic.go @@ -44,6 +44,9 @@ const ( // Beats product Beats + + // Enterprise Search product + EnterpriseSearch ) func (p Product) xPackMonitoringIndexString() string { @@ -52,6 +55,7 @@ func (p Product) xPackMonitoringIndexString() string { "kibana", "logstash", "beats", + "ent-search", } if int(p) < 0 || int(p) > len(indexProductNames) { @@ -67,6 +71,7 @@ func (p Product) String() string { "kibana", "logstash", "beats", + "enterprisesearch", } if int(p) < 0 || int(p) > len(productNames) { diff --git a/x-pack/metricbeat/module/enterprisesearch/docker-compose.yml b/x-pack/metricbeat/module/enterprisesearch/docker-compose.yml index 3e9dbfdf9bf7..09d7addb71c2 100644 --- a/x-pack/metricbeat/module/enterprisesearch/docker-compose.yml +++ b/x-pack/metricbeat/module/enterprisesearch/docker-compose.yml @@ -24,7 +24,7 @@ services: - 3002:3002 elasticsearch: - image: docker.elastic.co/integrations-ci/beats-elasticsearch:${ELASTICSEARCH_VERSION:-7.15.0}-1 + image: docker.elastic.co/integrations-ci/beats-elasticsearch:${ELASTICSEARCH_VERSION:-8.0.0-SNAPSHOT}-1 build: args: ELASTICSEARCH_VERSION: ${ELASTICSEARCH_VERSION:-7.15.0} diff --git a/x-pack/metricbeat/module/enterprisesearch/health/data.go b/x-pack/metricbeat/module/enterprisesearch/health/data.go index 517b0d1fbbc9..32fa38497888 100644 --- a/x-pack/metricbeat/module/enterprisesearch/health/data.go +++ b/x-pack/metricbeat/module/enterprisesearch/health/data.go @@ -13,6 +13,7 @@ import ( "github.com/elastic/beats/v7/libbeat/common" s "github.com/elastic/beats/v7/libbeat/common/schema" c "github.com/elastic/beats/v7/libbeat/common/schema/mapstriface" + "github.com/elastic/beats/v7/metricbeat/helper/elastic" "github.com/elastic/beats/v7/metricbeat/mb" ) @@ -73,7 +74,7 @@ var ( } ) -func eventMapping(report mb.ReporterV2, input []byte) error { +func eventMapping(report mb.ReporterV2, input []byte, isXpack bool) error { var data map[string]interface{} err := json.Unmarshal(input, &data) if err != nil { @@ -115,6 +116,13 @@ func eventMapping(report mb.ReporterV2, input []byte) error { // Set the process info we have collected data["process"] = process + // xpack.enabled in config using standalone metricbeat writes to `.monitoring` instead of `metricbeat-*` + // When using Agent, the index name is overwritten anyways. + if isXpack { + index := elastic.MakeXPackMonitoringIndexName(elastic.EnterpriseSearch) + event.Index = index + } + event.MetricSetFields, err = schema.Apply(data) if err != nil { errs = append(errs, errors.Wrap(err, "failure to apply health schema")) diff --git a/x-pack/metricbeat/module/enterprisesearch/health/health.go b/x-pack/metricbeat/module/enterprisesearch/health/health.go index e649748c2b74..d263314bf952 100644 --- a/x-pack/metricbeat/module/enterprisesearch/health/health.go +++ b/x-pack/metricbeat/module/enterprisesearch/health/health.go @@ -38,7 +38,8 @@ func init() { type MetricSet struct { mb.BaseMetricSet - http *helper.HTTP + http *helper.HTTP + XPackEnabled bool } func New(base mb.BaseMetricSet) (mb.MetricSet, error) { @@ -48,9 +49,19 @@ func New(base mb.BaseMetricSet) (mb.MetricSet, error) { if err != nil { return nil, err } + config := struct { + XPackEnabled bool `config:"xpack.enabled"` + }{ + XPackEnabled: false, + } + if err := base.Module().UnpackConfig(&config); err != nil { + return nil, err + } + return &MetricSet{ base, http, + config.XPackEnabled, }, nil } @@ -63,7 +74,7 @@ func (m *MetricSet) Fetch(report mb.ReporterV2) error { return errors.Wrap(err, "error in fetch") } - err = eventMapping(report, content) + err = eventMapping(report, content, m.XPackEnabled) if err != nil { return errors.Wrap(err, "error converting event") } diff --git a/x-pack/metricbeat/module/enterprisesearch/stats/data.go b/x-pack/metricbeat/module/enterprisesearch/stats/data.go index 049145dda19f..d11767b316eb 100644 --- a/x-pack/metricbeat/module/enterprisesearch/stats/data.go +++ b/x-pack/metricbeat/module/enterprisesearch/stats/data.go @@ -13,6 +13,7 @@ import ( "github.com/elastic/beats/v7/libbeat/common" s "github.com/elastic/beats/v7/libbeat/common/schema" c "github.com/elastic/beats/v7/libbeat/common/schema/mapstriface" + "github.com/elastic/beats/v7/metricbeat/helper/elastic" "github.com/elastic/beats/v7/metricbeat/mb" ) @@ -155,7 +156,7 @@ var ( } ) -func eventMapping(report mb.ReporterV2, input []byte) error { +func eventMapping(report mb.ReporterV2, input []byte, isXpack bool) error { var data map[string]interface{} err := json.Unmarshal(input, &data) if err != nil { @@ -185,6 +186,13 @@ func eventMapping(report mb.ReporterV2, input []byte) error { errs = append(errs, errors.New("queues is not a map")) } + // xpack.enabled in config using standalone metricbeat writes to `.monitoring` instead of `metricbeat-*` + // When using Agent, the index name is overwritten anyways. + if isXpack { + index := elastic.MakeXPackMonitoringIndexName(elastic.EnterpriseSearch) + event.Index = index + } + event.MetricSetFields, err = schema.Apply(data) if err != nil { errs = append(errs, errors.Wrap(err, "failure to apply stats schema")) diff --git a/x-pack/metricbeat/module/enterprisesearch/stats/stats.go b/x-pack/metricbeat/module/enterprisesearch/stats/stats.go index 8a1f20362351..c59b3481af4e 100644 --- a/x-pack/metricbeat/module/enterprisesearch/stats/stats.go +++ b/x-pack/metricbeat/module/enterprisesearch/stats/stats.go @@ -38,7 +38,8 @@ func init() { type MetricSet struct { mb.BaseMetricSet - http *helper.HTTP + http *helper.HTTP + XPackEnabled bool } func New(base mb.BaseMetricSet) (mb.MetricSet, error) { @@ -48,9 +49,19 @@ func New(base mb.BaseMetricSet) (mb.MetricSet, error) { if err != nil { return nil, err } + + config := struct { + XPackEnabled bool `config:"xpack.enabled"` + }{ + XPackEnabled: false, + } + if err := base.Module().UnpackConfig(&config); err != nil { + return nil, err + } return &MetricSet{ base, http, + config.XPackEnabled, }, nil } @@ -63,7 +74,7 @@ func (m *MetricSet) Fetch(report mb.ReporterV2) error { return errors.Wrap(err, "error in fetch") } - err = eventMapping(report, content) + err = eventMapping(report, content, m.XPackEnabled) if err != nil { return errors.Wrap(err, "error converting event") } From 236c050f6c540f20c083fe7d8f502d58012084dd Mon Sep 17 00:00:00 2001 From: cdelgado Date: Mon, 17 Jan 2022 12:11:09 +0100 Subject: [PATCH 02/13] Added config-xpack.yml, minor fixes to config files --- .../module/enterprisesearch/_meta/config-xpack.yml | 8 ++++++++ .../metricbeat/module/enterprisesearch/_meta/config.yml | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 x-pack/metricbeat/module/enterprisesearch/_meta/config-xpack.yml diff --git a/x-pack/metricbeat/module/enterprisesearch/_meta/config-xpack.yml b/x-pack/metricbeat/module/enterprisesearch/_meta/config-xpack.yml new file mode 100644 index 000000000000..d80e6d349b6e --- /dev/null +++ b/x-pack/metricbeat/module/enterprisesearch/_meta/config-xpack.yml @@ -0,0 +1,8 @@ +- module: enterprisesearch + xpack.enabled: true + metricsets: ["health", "stats"] + enabled: true + period: 10s + hosts: ["http://localhost:3002"] + #username: "user" + #password: "secret" diff --git a/x-pack/metricbeat/module/enterprisesearch/_meta/config.yml b/x-pack/metricbeat/module/enterprisesearch/_meta/config.yml index 7c2efca0a610..e90fa79f9ff4 100644 --- a/x-pack/metricbeat/module/enterprisesearch/_meta/config.yml +++ b/x-pack/metricbeat/module/enterprisesearch/_meta/config.yml @@ -3,5 +3,5 @@ enabled: true period: 10s hosts: ["http://localhost:3002"] - username: elastic - password: changeme + #username: "user" + #password: "secret" From 4f1e1575cee0b010835cfec1431cffed3a86485e Mon Sep 17 00:00:00 2001 From: cdelgado Date: Mon, 17 Jan 2022 12:20:17 +0100 Subject: [PATCH 03/13] Added doc changes --- .../module/enterprisesearch/_meta/docs.asciidoc | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/x-pack/metricbeat/module/enterprisesearch/_meta/docs.asciidoc b/x-pack/metricbeat/module/enterprisesearch/_meta/docs.asciidoc index 3251d02c09af..e417e57b682f 100644 --- a/x-pack/metricbeat/module/enterprisesearch/_meta/docs.asciidoc +++ b/x-pack/metricbeat/module/enterprisesearch/_meta/docs.asciidoc @@ -7,3 +7,14 @@ The module has been tested with Enterprise Search versions 7.16.0 and higher. Ve [float] === Usage The Enterprise Search module requires a set of credentials (a username and a password) for an Elasticserch user for a user that has a `monitor` https://www.elastic.co/guide/en/elasticsearch/reference/current/security-privileges.html#privileges-list-cluster[cluster privilege]. + +[float] +=== Usage for {stack} Monitoring + +The Enterprise Search module can be used to collect metrics shown in our {stack-monitor-app} +UI in {kib}. To enable this usage, set `xpack.enabled: true` in configuration. + +NOTE: When this module is used for {stack} Monitoring, it sends metrics to the +monitoring index instead of the default index typically used by {metricbeat}. +For more details about the monitoring index, see +{ref}/config-monitoring-indices.html[Configuring indices for monitoring]. From 8551f9318d2473e55a7e8afb5e9cf7b294033250 Mon Sep 17 00:00:00 2001 From: cdelgado Date: Mon, 17 Jan 2022 13:01:52 +0100 Subject: [PATCH 04/13] Add tests for xpack.enabled: true --- .../enterprisesearch/test_enterprisesearch.py | 35 ++++++++++++++----- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/x-pack/metricbeat/module/enterprisesearch/test_enterprisesearch.py b/x-pack/metricbeat/module/enterprisesearch/test_enterprisesearch.py index cba273bc7eec..b82c17b6a09e 100644 --- a/x-pack/metricbeat/module/enterprisesearch/test_enterprisesearch.py +++ b/x-pack/metricbeat/module/enterprisesearch/test_enterprisesearch.py @@ -11,11 +11,19 @@ class Test(XPackTest): # ------------------------------------------------------------------------- @unittest.skipUnless(metricbeat.INTEGRATION_TESTS, 'integration test') - def test_health(self): - """Tests the Health API and the associated metricset""" + def test_health_xpack_disabled(self, xpackEnabled): + """Tests the Health API and the associated metricset with XPack disabled""" + test_health(xpackEnabled=False) + + @unittest.skipUnless(metricbeat.INTEGRATION_TESTS, 'integration test') + def test_health_xpack_enabled(self, xpackEnabled): + """Tests the Health API and the associated metricset with XPack enabled""" + test_health(xpackEnabled=True) + + def test_health(self, xpackEnabled): # Setup the environment - self.setup_environment(metricset="health") + self.setup_environment(metricset="health", xpackEnabled=xpackEnabled) # Get a single event for testing evt = self.get_event() @@ -25,14 +33,23 @@ def test_health(self): health = evt["enterprisesearch"]["health"] self.assertIn("jvm", health) + self.assertEqual(evt["index"].startsWith(".monitoring-"), xpackEnabled) # ------------------------------------------------------------------------- @unittest.skipUnless(metricbeat.INTEGRATION_TESTS, 'integration test') - def test_stats(self): - """Tests the Stats API and the associated metricset""" + def test_stats_xpack_disabled(self): + """Tests the Stats API and the associated metricset with XPack disabled""" + test_stats(xpackEnabled=False) + + @unittest.skipUnless(metricbeat.INTEGRATION_TESTS, 'integration test') + def test_stats_xpack_enabled(self): + """Tests the Stats API and the associated metricset with XPack enabled""" + test_stats(xpackEnabled=True) + + def test_stats(self, xpackEnabled): # Setup the environment - self.setup_environment(metricset="stats") + self.setup_environment(metricset="stats", xpackEnabled=xpackEnabled) # Get a single event for testing evt = self.get_event() @@ -42,9 +59,10 @@ def test_stats(self): stats = evt["enterprisesearch"]["stats"] self.assertIn("http", stats) + self.assertEqual(evt["index"].startsWith(".monitoring-"), xpackEnabled) # ------------------------------------------------------------------------- - def setup_environment(self, metricset): + def setup_environment(self, metricset, xpackEnabled): """Sets up the testing environment and starts all components needed""" self.render_config_template(modules=[{ @@ -53,7 +71,8 @@ def setup_environment(self, metricset): "hosts": [self.compose_host(service="enterprise_search")], "username": self.get_username(), "password": self.get_password(), - "period": "5s" + "period": "5s", + "xpack.enabled": xpackEnabled }]) proc = self.start_beat(home=self.beat_path) From 482936e9bcd58f7cd47f763aac277844cc628543 Mon Sep 17 00:00:00 2001 From: cdelgado Date: Mon, 17 Jan 2022 13:13:31 +0100 Subject: [PATCH 05/13] Added changelog --- CHANGELOG.next.asciidoc | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index a2a9ba049ebb..f8095f363dca 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -175,6 +175,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d - Add k8s metadata in state_cronjob metricset. {pull}29572[29572] - Add `elasticsearch.cluster.id` field to Beat and Kibana modules. {pull}29577[29577] - Add `elasticsearch.cluster.id` field to Logstash module. {pull}29625[29625] +- Add `xpack.enabled` support for Enterprise Search module. {pull}29871[29871] *Packetbeat* @@ -211,9 +212,3 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d ==== Known Issue *Journalbeat* - - - - - - From 70d0fbc58ba7130d2c6daaf3fabc992c33770551 Mon Sep 17 00:00:00 2001 From: cdelgado Date: Mon, 17 Jan 2022 13:43:37 +0100 Subject: [PATCH 06/13] Trigger CI From 58387498057fe5e74405f572405b8d4bd3842587 Mon Sep 17 00:00:00 2001 From: cdelgado Date: Mon, 17 Jan 2022 16:28:20 +0100 Subject: [PATCH 07/13] Trigger CI From e441eee6e8b988e1639624e3e68f98d38e0bfa32 Mon Sep 17 00:00:00 2001 From: cdelgado Date: Mon, 17 Jan 2022 18:20:06 +0100 Subject: [PATCH 08/13] Added enterprisesearch-xpack.yml.disabled --- .../modules.d/enterprisesearch-xpack.yml.disabled | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 x-pack/metricbeat/modules.d/enterprisesearch-xpack.yml.disabled diff --git a/x-pack/metricbeat/modules.d/enterprisesearch-xpack.yml.disabled b/x-pack/metricbeat/modules.d/enterprisesearch-xpack.yml.disabled new file mode 100644 index 000000000000..e42dde843c2a --- /dev/null +++ b/x-pack/metricbeat/modules.d/enterprisesearch-xpack.yml.disabled @@ -0,0 +1,11 @@ +# Module: enterprisesearch +# Docs: https://www.elastic.co/guide/en/beats/metricbeat/master/metricbeat-module-enterprisesearch.html + +- module: enterprisesearch + xpack.enabled: true + metricsets: ["health", "stats"] + enabled: true + period: 10s + hosts: ["http://localhost:3002"] + #username: "user" + #password: "secret" From a024092ced76ae536fe1be7131b6250a0c9c87cd Mon Sep 17 00:00:00 2001 From: cdelgado Date: Mon, 17 Jan 2022 20:35:02 +0100 Subject: [PATCH 09/13] Include mage update changes --- x-pack/metricbeat/metricbeat.reference.yml | 4 ++-- x-pack/metricbeat/modules.d/enterprisesearch.yml.disabled | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/x-pack/metricbeat/metricbeat.reference.yml b/x-pack/metricbeat/metricbeat.reference.yml index 2c3a35d801be..61875105aaeb 100644 --- a/x-pack/metricbeat/metricbeat.reference.yml +++ b/x-pack/metricbeat/metricbeat.reference.yml @@ -510,8 +510,8 @@ metricbeat.modules: enabled: true period: 10s hosts: ["http://localhost:3002"] - username: elastic - password: changeme + #username: "user" + #password: "secret" #------------------------------ Envoyproxy Module ------------------------------ - module: envoyproxy diff --git a/x-pack/metricbeat/modules.d/enterprisesearch.yml.disabled b/x-pack/metricbeat/modules.d/enterprisesearch.yml.disabled index 78c9ca01448a..241791cc203c 100644 --- a/x-pack/metricbeat/modules.d/enterprisesearch.yml.disabled +++ b/x-pack/metricbeat/modules.d/enterprisesearch.yml.disabled @@ -6,5 +6,5 @@ enabled: true period: 10s hosts: ["http://localhost:3002"] - username: elastic - password: changeme + #username: "user" + #password: "secret" From d2014ab8042725a20fcfad79f3604cee7430b4b8 Mon Sep 17 00:00:00 2001 From: cdelgado Date: Mon, 17 Jan 2022 23:00:10 +0100 Subject: [PATCH 10/13] Add documentation --- metricbeat/docs/modules/enterprisesearch.asciidoc | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/metricbeat/docs/modules/enterprisesearch.asciidoc b/metricbeat/docs/modules/enterprisesearch.asciidoc index 1f34a3158f1a..a7c0948012aa 100644 --- a/metricbeat/docs/modules/enterprisesearch.asciidoc +++ b/metricbeat/docs/modules/enterprisesearch.asciidoc @@ -20,6 +20,17 @@ The module has been tested with Enterprise Search versions 7.16.0 and higher. Ve === Usage The Enterprise Search module requires a set of credentials (a username and a password) for an Elasticserch user for a user that has a `monitor` https://www.elastic.co/guide/en/elasticsearch/reference/current/security-privileges.html#privileges-list-cluster[cluster privilege]. +[float] +=== Usage for {stack} Monitoring + +The Enterprise Search module can be used to collect metrics shown in our {stack-monitor-app} +UI in {kib}. To enable this usage, set `xpack.enabled: true` in configuration. + +NOTE: When this module is used for {stack} Monitoring, it sends metrics to the +monitoring index instead of the default index typically used by {metricbeat}. +For more details about the monitoring index, see +{ref}/config-monitoring-indices.html[Configuring indices for monitoring]. + [float] === Example configuration @@ -35,8 +46,8 @@ metricbeat.modules: enabled: true period: 10s hosts: ["http://localhost:3002"] - username: elastic - password: changeme + #username: "user" + #password: "secret" ---- This module supports TLS connections when using `ssl` config field, as described in <>. From 3a431907d0b90c971dfd7736bf97efabe8fd98de Mon Sep 17 00:00:00 2001 From: cdelgado Date: Tue, 18 Jan 2022 00:09:17 +0100 Subject: [PATCH 11/13] Fixed integration tests --- .../module/enterprisesearch/test_enterprisesearch.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/x-pack/metricbeat/module/enterprisesearch/test_enterprisesearch.py b/x-pack/metricbeat/module/enterprisesearch/test_enterprisesearch.py index b82c17b6a09e..9b91f94749d6 100644 --- a/x-pack/metricbeat/module/enterprisesearch/test_enterprisesearch.py +++ b/x-pack/metricbeat/module/enterprisesearch/test_enterprisesearch.py @@ -13,12 +13,12 @@ class Test(XPackTest): @unittest.skipUnless(metricbeat.INTEGRATION_TESTS, 'integration test') def test_health_xpack_disabled(self, xpackEnabled): """Tests the Health API and the associated metricset with XPack disabled""" - test_health(xpackEnabled=False) + self.test_health(xpackEnabled=False) @unittest.skipUnless(metricbeat.INTEGRATION_TESTS, 'integration test') def test_health_xpack_enabled(self, xpackEnabled): """Tests the Health API and the associated metricset with XPack enabled""" - test_health(xpackEnabled=True) + self.test_health(xpackEnabled=True) def test_health(self, xpackEnabled): @@ -39,12 +39,12 @@ def test_health(self, xpackEnabled): @unittest.skipUnless(metricbeat.INTEGRATION_TESTS, 'integration test') def test_stats_xpack_disabled(self): """Tests the Stats API and the associated metricset with XPack disabled""" - test_stats(xpackEnabled=False) + self.test_stats(xpackEnabled=False) @unittest.skipUnless(metricbeat.INTEGRATION_TESTS, 'integration test') def test_stats_xpack_enabled(self): """Tests the Stats API and the associated metricset with XPack enabled""" - test_stats(xpackEnabled=True) + self.test_stats(xpackEnabled=True) def test_stats(self, xpackEnabled): From ecc267642b5c2df73a940d2dc0b7e695902e827e Mon Sep 17 00:00:00 2001 From: cdelgado Date: Tue, 18 Jan 2022 10:08:12 +0100 Subject: [PATCH 12/13] Fix integration tests --- .../module/enterprisesearch/test_enterprisesearch.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/x-pack/metricbeat/module/enterprisesearch/test_enterprisesearch.py b/x-pack/metricbeat/module/enterprisesearch/test_enterprisesearch.py index 9b91f94749d6..73d0af2e8bbc 100644 --- a/x-pack/metricbeat/module/enterprisesearch/test_enterprisesearch.py +++ b/x-pack/metricbeat/module/enterprisesearch/test_enterprisesearch.py @@ -13,14 +13,14 @@ class Test(XPackTest): @unittest.skipUnless(metricbeat.INTEGRATION_TESTS, 'integration test') def test_health_xpack_disabled(self, xpackEnabled): """Tests the Health API and the associated metricset with XPack disabled""" - self.test_health(xpackEnabled=False) + self.health_check(xpackEnabled=False) @unittest.skipUnless(metricbeat.INTEGRATION_TESTS, 'integration test') def test_health_xpack_enabled(self, xpackEnabled): """Tests the Health API and the associated metricset with XPack enabled""" - self.test_health(xpackEnabled=True) + self.health_check(xpackEnabled=True) - def test_health(self, xpackEnabled): + def health_check(self, xpackEnabled): # Setup the environment self.setup_environment(metricset="health", xpackEnabled=xpackEnabled) @@ -39,14 +39,14 @@ def test_health(self, xpackEnabled): @unittest.skipUnless(metricbeat.INTEGRATION_TESTS, 'integration test') def test_stats_xpack_disabled(self): """Tests the Stats API and the associated metricset with XPack disabled""" - self.test_stats(xpackEnabled=False) + self.stats_check(xpackEnabled=False) @unittest.skipUnless(metricbeat.INTEGRATION_TESTS, 'integration test') def test_stats_xpack_enabled(self): """Tests the Stats API and the associated metricset with XPack enabled""" - self.test_stats(xpackEnabled=True) + self.stats_check(xpackEnabled=True) - def test_stats(self, xpackEnabled): + def stats_check(self, xpackEnabled): # Setup the environment self.setup_environment(metricset="stats", xpackEnabled=xpackEnabled) From 1d70a33bde50f7c533a50c5c91bafe4a21ddd0a3 Mon Sep 17 00:00:00 2001 From: cdelgado Date: Tue, 18 Jan 2022 12:09:14 +0100 Subject: [PATCH 13/13] Event index is not available on integration test --- .../enterprisesearch/test_enterprisesearch.py | 35 +++++-------------- 1 file changed, 8 insertions(+), 27 deletions(-) diff --git a/x-pack/metricbeat/module/enterprisesearch/test_enterprisesearch.py b/x-pack/metricbeat/module/enterprisesearch/test_enterprisesearch.py index 73d0af2e8bbc..cba273bc7eec 100644 --- a/x-pack/metricbeat/module/enterprisesearch/test_enterprisesearch.py +++ b/x-pack/metricbeat/module/enterprisesearch/test_enterprisesearch.py @@ -11,19 +11,11 @@ class Test(XPackTest): # ------------------------------------------------------------------------- @unittest.skipUnless(metricbeat.INTEGRATION_TESTS, 'integration test') - def test_health_xpack_disabled(self, xpackEnabled): - """Tests the Health API and the associated metricset with XPack disabled""" - self.health_check(xpackEnabled=False) - - @unittest.skipUnless(metricbeat.INTEGRATION_TESTS, 'integration test') - def test_health_xpack_enabled(self, xpackEnabled): - """Tests the Health API and the associated metricset with XPack enabled""" - self.health_check(xpackEnabled=True) - - def health_check(self, xpackEnabled): + def test_health(self): + """Tests the Health API and the associated metricset""" # Setup the environment - self.setup_environment(metricset="health", xpackEnabled=xpackEnabled) + self.setup_environment(metricset="health") # Get a single event for testing evt = self.get_event() @@ -33,23 +25,14 @@ def health_check(self, xpackEnabled): health = evt["enterprisesearch"]["health"] self.assertIn("jvm", health) - self.assertEqual(evt["index"].startsWith(".monitoring-"), xpackEnabled) # ------------------------------------------------------------------------- @unittest.skipUnless(metricbeat.INTEGRATION_TESTS, 'integration test') - def test_stats_xpack_disabled(self): - """Tests the Stats API and the associated metricset with XPack disabled""" - self.stats_check(xpackEnabled=False) - - @unittest.skipUnless(metricbeat.INTEGRATION_TESTS, 'integration test') - def test_stats_xpack_enabled(self): - """Tests the Stats API and the associated metricset with XPack enabled""" - self.stats_check(xpackEnabled=True) - - def stats_check(self, xpackEnabled): + def test_stats(self): + """Tests the Stats API and the associated metricset""" # Setup the environment - self.setup_environment(metricset="stats", xpackEnabled=xpackEnabled) + self.setup_environment(metricset="stats") # Get a single event for testing evt = self.get_event() @@ -59,10 +42,9 @@ def stats_check(self, xpackEnabled): stats = evt["enterprisesearch"]["stats"] self.assertIn("http", stats) - self.assertEqual(evt["index"].startsWith(".monitoring-"), xpackEnabled) # ------------------------------------------------------------------------- - def setup_environment(self, metricset, xpackEnabled): + def setup_environment(self, metricset): """Sets up the testing environment and starts all components needed""" self.render_config_template(modules=[{ @@ -71,8 +53,7 @@ def setup_environment(self, metricset, xpackEnabled): "hosts": [self.compose_host(service="enterprise_search")], "username": self.get_username(), "password": self.get_password(), - "period": "5s", - "xpack.enabled": xpackEnabled + "period": "5s" }]) proc = self.start_beat(home=self.beat_path)