Merge ~hloeung/charm-graylog:master into ~graylog-charmers/charm-graylog:master

Proposed by Haw Loeung
Status: Merged
Merged at revision: fa853dc4a119c7365141d0c7356188a4230a4de9
Proposed branch: ~hloeung/charm-graylog:master
Merge into: ~graylog-charmers/charm-graylog:master
Diff against target: 80 lines (+17/-9)
2 files modified
lib/graylogapi.py (+2/-2)
reactive/graylog.py (+15/-7)
Reviewer Review Type Date Requested Status
Barry Price Approve
Review via email: mp+329877@code.launchpad.net

Description of the change

Add support for Graylog 2.3

Graylog 2.3 changes how it talks to ElasticSearch. Previously, the
binary protocol was used so Graylog would appear in the cluster just
like another Elasticsearch node. It's now changed to using the HTTP
REST API, and with that, the configuration option changed from
elasticsearch_discovery_zen_ping_unicast_hosts to
elasticsearch_hosts. See upgrade docs[1] for details.

[1]http://docs.graylog.org/en/2.3/pages/upgrade/graylog-2.3.html#upgrade-from-22-to-23

To post a comment you must log in.
Revision history for this message
Barry Price (barryprice) wrote :

LGTM +1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/lib/graylogapi.py b/lib/graylogapi.py
index 61393b2..e7a7ef3 100644
--- a/lib/graylogapi.py
+++ b/lib/graylogapi.py
@@ -80,7 +80,7 @@ class GraylogAPI:
80 if index_id:80 if index_id:
81 return self._request('{}/{}'.format(url, index_id))81 return self._request('{}/{}'.format(url, index_id))
82 else:82 else:
83 return self._request(url)['index_sets']83 return self._request(url)['index_sets'] or None
8484
85 def index_set_update(self, index_id, data):85 def index_set_update(self, index_id, data):
86 if not self.token:86 if not self.token:
@@ -95,7 +95,7 @@ class GraylogAPI:
95 if input_id:95 if input_id:
96 return self._request('{}/{}'.format(url, input_id))96 return self._request('{}/{}'.format(url, input_id))
97 else:97 else:
98 return self._request(url)['inputs']98 return self._request(url)['inputs'] or None
9999
100 def log_input_update(self, input_id=None, data=None):100 def log_input_update(self, input_id=None, data=None):
101 if not self.token:101 if not self.token:
diff --git a/reactive/graylog.py b/reactive/graylog.py
index 052ecd3..49902a1 100644
--- a/reactive/graylog.py
+++ b/reactive/graylog.py
@@ -97,7 +97,10 @@ def configure_index_sets(*discard):
97 username='admin',97 username='admin',
98 password=db.get('admin_password'),98 password=db.get('admin_password'),
99 token_name='graylog-charm')99 token_name='graylog-charm')
100 for iset in g.index_set_get():100 index_sets = g.index_set_get()
101 if not index_sets:
102 return
103 for iset in index_sets:
101 log = ''104 log = ''
102 if iset['shards'] != conf['index_shards']:105 if iset['shards'] != conf['index_shards']:
103 log += ' shards from {} to {}'.format(iset['shards'], conf['index_shards'])106 log += ' shards from {} to {}'.format(iset['shards'], conf['index_shards'])
@@ -205,6 +208,8 @@ def configure_inputs(*discard):
205 password=db.get('admin_password'),208 password=db.get('admin_password'),
206 token_name='graylog-charm')209 token_name='graylog-charm')
207 inputs = g.log_input_get()210 inputs = g.log_input_get()
211 if not inputs:
212 return
208 new_opened_ports = []213 new_opened_ports = []
209 new_inputs = []214 new_inputs = []
210 for new in yaml.safe_load(conf['log_inputs']) or {}:215 for new in yaml.safe_load(conf['log_inputs']) or {}:
@@ -258,24 +263,27 @@ def configure_inputs(*discard):
258@when('elasticsearch.available')263@when('elasticsearch.available')
259def configure_elasticsearch_connection(elasticsearch):264def configure_elasticsearch_connection(elasticsearch):
260 cluster = ""265 cluster = ""
261 hosts = []266 # Pre-2.3.x discovery unicast hosts (binary ElasticSearch protocol)
267 discovery_hosts = []
268 # 2.3.x and above HTTP REST API
269 http_hosts = []
262 for unit in elasticsearch.list_unit_data():270 for unit in elasticsearch.list_unit_data():
263 cluster_name = unit['cluster_name']271 cluster_name = unit['cluster_name']
264 if cluster_name is not None:272 if cluster_name is not None:
265 cluster = cluster_name273 cluster = cluster_name
266 # The relation is reporting the http port not the zen discovery port274 http_hosts.append('http://{}:{}'.format(unit['host'], unit['port']))
267 # hosts.append('{}:{}'.format(unit['host'], unit['port']))275 discovery_hosts.append('{}:{}'.format(unit['host'], ELASTICSEARCH_DISCOVERY_PORT))
268 hosts.append('{}:{}'.format(unit['host'], ELASTICSEARCH_DISCOVERY_PORT))
269276
270 if not cluster:277 if not cluster:
271 conf = hookenv.config()278 conf = hookenv.config()
272 cluster = conf['elasticsearch_cluster_name']279 cluster = conf['elasticsearch_cluster_name']
273280
274 if not data_changed('elasticsearch.relation', {'cluster_name': cluster, 'hosts': hosts}):281 if not data_changed('elasticsearch.relation', {'cluster_name': cluster, 'hosts': http_hosts}):
275 return282 return
276283
277 set_conf('elasticsearch_cluster_name', cluster)284 set_conf('elasticsearch_cluster_name', cluster)
278 set_conf('elasticsearch_discovery_zen_ping_unicast_hosts ', ', '.join(hosts))285 set_conf('elasticsearch_discovery_zen_ping_unicast_hosts ', ', '.join(discovery_hosts))
286 set_conf('elasticsearch_hosts', ', '.join(http_hosts))
279 # Elastic search does not reliably pick the right ip to listen on287 # Elastic search does not reliably pick the right ip to listen on
280 set_conf('elasticsearch_network_host', hookenv.unit_private_ip())288 set_conf('elasticsearch_network_host', hookenv.unit_private_ip())
281289

Subscribers

People subscribed via source and target branches

to all changes: