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
1diff --git a/lib/graylogapi.py b/lib/graylogapi.py
2index 61393b2..e7a7ef3 100644
3--- a/lib/graylogapi.py
4+++ b/lib/graylogapi.py
5@@ -80,7 +80,7 @@ class GraylogAPI:
6 if index_id:
7 return self._request('{}/{}'.format(url, index_id))
8 else:
9- return self._request(url)['index_sets']
10+ return self._request(url)['index_sets'] or None
11
12 def index_set_update(self, index_id, data):
13 if not self.token:
14@@ -95,7 +95,7 @@ class GraylogAPI:
15 if input_id:
16 return self._request('{}/{}'.format(url, input_id))
17 else:
18- return self._request(url)['inputs']
19+ return self._request(url)['inputs'] or None
20
21 def log_input_update(self, input_id=None, data=None):
22 if not self.token:
23diff --git a/reactive/graylog.py b/reactive/graylog.py
24index 052ecd3..49902a1 100644
25--- a/reactive/graylog.py
26+++ b/reactive/graylog.py
27@@ -97,7 +97,10 @@ def configure_index_sets(*discard):
28 username='admin',
29 password=db.get('admin_password'),
30 token_name='graylog-charm')
31- for iset in g.index_set_get():
32+ index_sets = g.index_set_get()
33+ if not index_sets:
34+ return
35+ for iset in index_sets:
36 log = ''
37 if iset['shards'] != conf['index_shards']:
38 log += ' shards from {} to {}'.format(iset['shards'], conf['index_shards'])
39@@ -205,6 +208,8 @@ def configure_inputs(*discard):
40 password=db.get('admin_password'),
41 token_name='graylog-charm')
42 inputs = g.log_input_get()
43+ if not inputs:
44+ return
45 new_opened_ports = []
46 new_inputs = []
47 for new in yaml.safe_load(conf['log_inputs']) or {}:
48@@ -258,24 +263,27 @@ def configure_inputs(*discard):
49 @when('elasticsearch.available')
50 def configure_elasticsearch_connection(elasticsearch):
51 cluster = ""
52- hosts = []
53+ # Pre-2.3.x discovery unicast hosts (binary ElasticSearch protocol)
54+ discovery_hosts = []
55+ # 2.3.x and above HTTP REST API
56+ http_hosts = []
57 for unit in elasticsearch.list_unit_data():
58 cluster_name = unit['cluster_name']
59 if cluster_name is not None:
60 cluster = cluster_name
61- # The relation is reporting the http port not the zen discovery port
62- # hosts.append('{}:{}'.format(unit['host'], unit['port']))
63- hosts.append('{}:{}'.format(unit['host'], ELASTICSEARCH_DISCOVERY_PORT))
64+ http_hosts.append('http://{}:{}'.format(unit['host'], unit['port']))
65+ discovery_hosts.append('{}:{}'.format(unit['host'], ELASTICSEARCH_DISCOVERY_PORT))
66
67 if not cluster:
68 conf = hookenv.config()
69 cluster = conf['elasticsearch_cluster_name']
70
71- if not data_changed('elasticsearch.relation', {'cluster_name': cluster, 'hosts': hosts}):
72+ if not data_changed('elasticsearch.relation', {'cluster_name': cluster, 'hosts': http_hosts}):
73 return
74
75 set_conf('elasticsearch_cluster_name', cluster)
76- set_conf('elasticsearch_discovery_zen_ping_unicast_hosts ', ', '.join(hosts))
77+ set_conf('elasticsearch_discovery_zen_ping_unicast_hosts ', ', '.join(discovery_hosts))
78+ set_conf('elasticsearch_hosts', ', '.join(http_hosts))
79 # Elastic search does not reliably pick the right ip to listen on
80 set_conf('elasticsearch_network_host', hookenv.unit_private_ip())
81

Subscribers

People subscribed via source and target branches

to all changes: