Skip to content

Commit

Permalink
[7.5] Check license expiry date zero value (#14591) (#14604)
Browse files Browse the repository at this point in the history
* Check license expiry date zero value (#14591)

* Check license expiry date zero value

* Adding check to system test

* Refactoring: moving fix to better location in code

* Adding CHANGELOG entry

* Fixing typo

Co-Authored-By: kaiyan-sheng <kaiyan.sheng@elastic.co>

* Change CCR log message to debug

* Start basic license

* Fixing up CHANGELOG
  • Loading branch information
ycombinator authored Nov 19, 2019
1 parent 865fad4 commit 3f0296e
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
*Metricbeat*

- Fix checking tagsFilter using length in cloudwatch metricset. {pull}14525[14525]
- Fixed bug with `elasticsearch/cluster_stats` metricset not recording license expiration date correctly. {issue}14541[14541] {pull}14591[14591]

*Packetbeat*

Expand Down
2 changes: 1 addition & 1 deletion metricbeat/module/elasticsearch/ccr/ccr.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (m *MetricSet) Fetch(r mb.ReporterV2) error {
if ccrUnavailableMessage != "" {
if time.Since(m.lastCCRLicenseMessageTimestamp) > 1*time.Minute {
m.lastCCRLicenseMessageTimestamp = time.Now()
m.Logger().Warn(ccrUnavailableMessage)
m.Logger().Debug(ccrUnavailableMessage)
}
return nil
}
Expand Down
32 changes: 20 additions & 12 deletions metricbeat/module/elasticsearch/elasticsearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -485,19 +485,27 @@ func (l *License) IsOneOf(candidateLicenses ...string) bool {
// particular it ensures that ms-since-epoch values are marshaled as longs
// and not floats in scientific notation as Elasticsearch does not like that.
func (l *License) ToMapStr() common.MapStr {
return common.MapStr{
"status": l.Status,
"id": l.ID,
"type": l.Type,
"issue_date": l.IssueDate,
"issue_date_in_millis": l.IssueDateInMillis,
"expiry_date": l.ExpiryDate,
"expiry_date_in_millis": l.ExpiryDateInMillis,
"max_nodes": l.MaxNodes,
"issued_to": l.IssuedTo,
"issuer": l.Issuer,
"start_date_in_millis": l.StartDateInMillis,

m := common.MapStr{
"status": l.Status,
"id": l.ID,
"type": l.Type,
"issue_date": l.IssueDate,
"issue_date_in_millis": l.IssueDateInMillis,
"expiry_date": l.ExpiryDate,
"max_nodes": l.MaxNodes,
"issued_to": l.IssuedTo,
"issuer": l.Issuer,
"start_date_in_millis": l.StartDateInMillis,
}

if l.ExpiryDateInMillis != 0 {
// We don't want to record a 0 expiry date as this means the license has expired
// in the Stack Monitoring UI
m["expiry_date_in_millis"] = l.ExpiryDateInMillis
}

return m
}

func getSettingGroup(allSettings common.MapStr, groupKey string) (common.MapStr, error) {
Expand Down
17 changes: 17 additions & 0 deletions metricbeat/module/elasticsearch/test_elasticsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ def test_xpack_cluster_stats(self):
"""
elasticsearch-xpack module test for type:cluster_stats
"""

self.start_basic()

self.render_config_template(modules=[{
"name": "elasticsearch",
"metricsets": [
Expand Down Expand Up @@ -149,6 +152,8 @@ def test_xpack_cluster_stats(self):
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 Expand Up @@ -295,6 +300,18 @@ def start_trial(self):
e = sys.exc_info()[0]
print "Trial already enabled. Error: {}".format(e)

def start_basic(self):
# Check if basic license is already enabled
response = self.es.transport.perform_request('GET', self.license_url)
if response["license"]["type"] == "basic":
return

try:
self.es.transport.perform_request('POST', self.license_url + "/start_basic?acknowledge=true")
except:
e = sys.exc_info()[0]
print "Basic license already enabled. Error: {}".format(e)

def check_skip(self, metricset):
if metricset == 'ccr' and not self.is_ccr_available():
raise SkipTest("elasticsearch/ccr metricset system test only valid with Elasticsearch versions >= 6.5.0")
Expand Down

0 comments on commit 3f0296e

Please sign in to comment.