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

Check license expiry date zero value #14591

Merged
merged 8 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 @@ -255,6 +255,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- 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]
- Log bulk failures from bulk API requests to monitoring cluster. {issue}14303[14303] {pull}14356[14356]
- 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)
Copy link
Contributor Author

@ycombinator ycombinator Nov 18, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made this change for two reasons:

  1. It's consistent with a similar logging behavior seen in the elasticsearch/enrich metricset:

    m.Logger().Debug(enrichUnavailableMessage)

  2. By changing the log level to debug here (instead of warn), this check in the system test doesn't fail:

    self.assert_no_logged_warnings()

}
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