Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.x] Check license expiry date zero value (#14591) #14603

Merged
merged 2 commits into from
Nov 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- Fix cloudwatch metricset with names and dimensions in config. {issue}14376[14376] {pull}14391[14391]
- Fix marshaling of ms-since-epoch values in `elasticsearch/cluster_stats` metricset. {pull}14378[14378]
- 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