From 897df4c86911dc1510f358eac80965672e348b34 Mon Sep 17 00:00:00 2001 From: Kevin Lacabane Date: Thu, 6 Jan 2022 14:39:26 +0100 Subject: [PATCH] cluster_stats: use correct license value (#29711) * add integration test * target correct license property * fix license path * cluster_stats: use correct license value * changelog entry --- CHANGELOG.next.asciidoc | 1 + .../module/elasticsearch/cluster_stats/data.go | 17 +---------------- .../module/elasticsearch/test_elasticsearch.py | 11 +++++++++++ 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index 439d1278732..97ff013a69f 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -110,6 +110,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d - Enhance filter check in kubernetes event metricset. {pull}29470[29470] - Fix gcp metrics metricset apply aligner to all metric_types {pull}29514[29513] - Extract correct index property in kibana.stats metricset {pull}29622[29622] +- Fixed bug with `elasticsearch/cluster_stats` metricset not recording license expiration date correctly. {pull}29711[29711] *Packetbeat* diff --git a/metricbeat/module/elasticsearch/cluster_stats/data.go b/metricbeat/module/elasticsearch/cluster_stats/data.go index 8de27d71561..a75f58f3a44 100644 --- a/metricbeat/module/elasticsearch/cluster_stats/data.go +++ b/metricbeat/module/elasticsearch/cluster_stats/data.go @@ -303,22 +303,7 @@ func eventMapping(r mb.ReporterV2, httpClient *helper.HTTP, info elasticsearch.I metricSetFields, _ := schema.Apply(data) metricSetFields.Put("stack", stackData) - metricSetFields.Put("license", struct { - Status string `json:"status"` - Type string `json:"type"` - ExpiryDateMs int `json:"expiry_date_in_millis"` - }{ - Status: license.Status, - Type: license.Type, - ExpiryDateMs: license.ExpiryDateInMillis, - }) - - if license.ExpiryDateInMillis != 0 { - // We don't want to record a 0 expiry date as this means the license has expired - // in the Stack Monitoring UI - metricSetFields.Put("expiry_date_in_millis", license.ExpiryDateInMillis) - } - + metricSetFields.Put("license", l) metricSetFields.Put("state", clusterStateReduced) if err = elasticsearch.PassThruField("version", clusterState, event.ModuleFields); err != nil { diff --git a/metricbeat/module/elasticsearch/test_elasticsearch.py b/metricbeat/module/elasticsearch/test_elasticsearch.py index 7a48efdfb15..9726f26838d 100644 --- a/metricbeat/module/elasticsearch/test_elasticsearch.py +++ b/metricbeat/module/elasticsearch/test_elasticsearch.py @@ -140,6 +140,17 @@ def test_xpack_cluster_stats(self): proc.check_kill_and_wait() self.assert_no_logged_warnings() + docs = self.read_output_json() + for doc in docs: + t = doc["metricset"]["name"] + if t != "cluster_stats": + continue + license = doc["elasticsearch"]["cluster"]["stats"]["license"] + issue_date = license["issue_date_in_millis"] + self.assertIsNot(type(issue_date), float) + + self.assertNotIn("expiry_date_in_millis", license) + def create_ml_job(self): # Check if an ml job already exists response = self.ml_es.get_jobs()