-
Notifications
You must be signed in to change notification settings - Fork 10
Add support for Elasticsearch 7.x #19
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
base: master
Are you sure you want to change the base?
Changes from all commits
70b206e
ca460e7
50cc60d
72b72f1
53b3c12
e56077f
bd7875f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,6 @@ | ||
| # 1.2.0 | ||
|
|
||
| - Add support for Elasticsearch 7.x | ||
|
|
||
| # 1.1.1 | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,7 +6,7 @@ keywords: | |
| - elasticsearch | ||
| - curator | ||
| - databases | ||
| version: 1.1.1 | ||
| version: 1.2.0 | ||
| author : StackStorm, Inc. | ||
| email : [email protected] | ||
| python_versions: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| elasticsearch-curator==5.4.0 | ||
nmaludy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| easydict | ||
| elasticsearch-curator==5.8.1 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,9 +8,9 @@ class ElasticsearchCountSensor(PollingSensor): | |
|
|
||
| def setup(self): | ||
| self.host = self.config.get('host', None) | ||
| self.port = self.config.get('port', None) | ||
| self.http_auth = self.config.get('http_auth', None) | ||
| self.use_ssl = self.config.get('use_ssl', False) | ||
| self.port = self.config.get('port', None) | ||
| self.http_auth = self.config.get('http_auth', None) | ||
| self.use_ssl = self.config.get('use_ssl', False) | ||
| self.query_window = self.config.get('query_window', 60) | ||
| self.query_string = self.config.get('query_string', '{}') | ||
| self.cooldown_multiplier = self.config.get('cooldown_multiplier', 0) | ||
|
|
@@ -22,9 +22,9 @@ def setup(self): | |
| self.es = None | ||
|
|
||
| try: | ||
| self.es = Elasticsearch([{'host': self.host, 'port': self.port, | ||
| 'http_auth': self.http_auth, | ||
| 'use_ssl': self.use_ssl}]) | ||
| self.es = Elasticsearch([{'host': self.host, 'port': self.port, | ||
| 'http_auth': self.http_auth, | ||
| 'use_ssl': self.use_ssl}]) | ||
| except Exception: | ||
| raise | ||
|
|
||
|
|
@@ -40,7 +40,23 @@ def poll(self): | |
| data = self.es.search(index=self.index, body=query_payload) | ||
|
|
||
| hits = data.get('hits', None) | ||
| if hits.get('total', 0) > self.count_threshold: | ||
| if hits is None: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would be great to see some unit tests for these new conditions.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @nmaludy I was unable to find any tests apart from the bash scripts in
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @AbhyudayaSharma Unit tests go in the |
||
| raise RuntimeError('No hits in search response.') | ||
|
|
||
| total = hits.get('total', None) | ||
| if total is None: | ||
| raise RuntimeError('Total not present in search response.' + | ||
| 'Did you disable track_total_hits?\n' + | ||
| 'https://www.elastic.co/guide/en/elasticsearch/reference/current/breaking-changes-7.0.html#hits-total-omitted-if-disabled') # noqa | ||
|
|
||
| if isinstance(int, total): | ||
| hit_count = total | ||
| elif isinstance(dict, total): # for Elasticsearch >= 7.0 | ||
| hit_count = total['value'] | ||
| else: | ||
| raise RuntimeError('Unsupported type of hit.total') | ||
|
|
||
| if hit_count > self.count_threshold: | ||
| payload = dict() | ||
| payload['results'] = hits | ||
| payload['results']['query'] = query_payload | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.