Skip to content

Commit

Permalink
cluster_stats: use correct license value (#29711)
Browse files Browse the repository at this point in the history
* add integration test

* target correct license property

* fix license path

* cluster_stats: use correct license value

* changelog entry
  • Loading branch information
klacabane authored Jan 6, 2022
1 parent f8247f7 commit 897df4c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -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*

Expand Down
17 changes: 1 addition & 16 deletions metricbeat/module/elasticsearch/cluster_stats/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
11 changes: 11 additions & 0 deletions metricbeat/module/elasticsearch/test_elasticsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 897df4c

Please sign in to comment.