Skip to content

Commit

Permalink
[6.8] Check license expiry date zero value (#14591) (#14961)
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

* Adding blank line

* Fixing up code

* Updating license URLs

* Fixing up CHANGELOG

* Adding existence check for type field in doc
  • Loading branch information
ycombinator authored Dec 23, 2019
1 parent 29800b8 commit fa94b18
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ https://github.com/elastic/beats/compare/v6.8.0...6.8.1[Check the HEAD diff]

*Metricbeat*

- Fixed bug with `elasticsearch/cluster_stats` metricset not recording license expiration date correctly. {issue}14541[14541] {pull}14591[14591]

*Packetbeat*

Expand Down
5 changes: 3 additions & 2 deletions metricbeat/module/elasticsearch/ccr/ccr.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,10 @@ func (m *MetricSet) Fetch(r mb.ReporterV2) {

if ccrUnavailableMessage != "" {
if time.Since(m.lastCCRLicenseMessageTimestamp) > 1*time.Minute {
err := fmt.Errorf(ccrUnavailableMessage)
elastic.ReportAndLogError(err, r, m.Log)
m.lastCCRLicenseMessageTimestamp = time.Now()
err := fmt.Errorf(ccrUnavailableMessage)
r.Error(err)
m.Log.Debug(ccrUnavailableMessage)
}
return
}
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 @@ -481,19 +481,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,
"uid": 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,
"uid": 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
20 changes: 20 additions & 0 deletions metricbeat/module/elasticsearch/test_elasticsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ def test_xpack_cluster_stats(self):
"""
elasticsearch-xpack module test for type:cluster_stats
"""

es = Elasticsearch(self.get_hosts())
self.start_basic(es)

self.render_config_template(modules=[{
"name": "elasticsearch",
"metricsets": [
Expand Down Expand Up @@ -79,13 +83,17 @@ def test_xpack_cluster_stats(self):

docs = self.read_output_json()
for doc in docs:
if not "type" in doc:
continue
t = doc["type"]
if t != "cluster_stats":
continue
license = doc["license"]
issue_date = license["issue_date_in_millis"]
self.assertIsNot(type(issue_date), float)

self.assertNotIn("expiry_date_in_millis", license)

def get_hosts(self):
return [os.getenv('ES_HOST', 'localhost') + ':' +
os.getenv('ES_PORT', '9200')]
Expand Down Expand Up @@ -155,6 +163,18 @@ def start_trial(self, es):
e = sys.exc_info()[0]
print "Trial already enabled. Error: {}".format(e)

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

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

def check_skip(self, metricset, es):
if metricset != "ccr":
return
Expand Down

0 comments on commit fa94b18

Please sign in to comment.