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

Proposed by Haw Loeung
Status: Merged
Merged at revision: b9240cb9b78f4d6ef6b845ae6e382cd3c9087cb0
Proposed branch: ~hloeung/charm-graylog:master
Merge into: ~graylog-charmers/charm-graylog:master
Diff against target: 45 lines (+17/-4)
2 files modified
config.yaml (+1/-1)
reactive/graylog.py (+16/-3)
Reviewer Review Type Date Requested Status
Stuart Bishop (community) Approve
Review via email: mp+332468@code.launchpad.net

Description of the change

Add automatically determine no. of index shards

Update index_shards config option to allow the charm to automatically
work out how many index shards to use based on how many elasticsearch
units are available.

To post a comment you must log in.
Revision history for this message
Stuart Bishop (stub) wrote :

Fine.

I worry about what happens if the shard count changes, and if users need to be warned. Or maybe graylog and/or elasticsearch doesn't suck and things get rebalanced magically.

Style comments inline.

review: Approve
Revision history for this message
Haw Loeung (hloeung) wrote :

> I worry about what happens if the shard count changes, and if users need to be
> warned. Or maybe graylog and/or elasticsearch doesn't suck and things get
> rebalanced magically.

Nothing happens to the existing data when shards are changed, even if you reduce the number of shards. It only applies to new index sets (either automatically rotated out as configured or manually via the UI/API).

So let's say you have 5 indices already and the index set was previously set to 4 shards. You add more elasticsearch units and bump the index set to 6, the 5 old indices will remain as is sharded across 4 (instead of 6). Elasticsearch will most likely relocate the shards or replicas to the new elasticsearch units but that's it.

Same goes for if you're removing and reducing down to say 3 elasticsearch units. Old indicies will still be sharded across 4 with Elasticsearch automatically relocating shards/replicas:

0 1 2 (unit)
1 2 3 (shards)
4 (shards)

With automatic index shards set, it can also take a while to apply because there's no way that I know of to detect additional elasticsearch unit changes unless something is done to the elasticsearch relation to pass that back.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/config.yaml b/config.yaml
index 9614533..3245461 100644
--- a/config.yaml
+++ b/config.yaml
@@ -16,7 +16,7 @@ options:
16 type: int16 type: int
17 default: 217 default: 2
18 description: |18 description: |
19 Number of Elasticsearch shards used per index in this index set.19 Number of Elasticsearch shards used per index in this index set. Set this to '0' to let the charm automatically calculate based on how many Elasticsearch units.
20 index_rotation_strategy:20 index_rotation_strategy:
21 type: string21 type: string
22 default: "time"22 default: "time"
diff --git a/reactive/graylog.py b/reactive/graylog.py
index c465552..13b3881 100644
--- a/reactive/graylog.py
+++ b/reactive/graylog.py
@@ -100,11 +100,24 @@ def configure_index_sets(*discard):
100 index_sets = g.index_set_get()100 index_sets = g.index_set_get()
101 if index_sets is None:101 if index_sets is None:
102 return102 return
103 index_shards = conf['index_shards']
104 if index_shards is 0:
105 # Automatically work out the index shards based on how
106 # many Elasticsearch units.
107 count = 0
108 for relid in hookenv.relation_ids('elasticsearch'):
109 count += len(hookenv.related_units(relid))
110 if count:
111 index_shards = count
112 else:
113 hookenv.log('Can\'t work out number of elasticsearch units')
114 return
115
103 for iset in index_sets:116 for iset in index_sets:
104 log = ''117 log = ''
105 if iset['shards'] != conf['index_shards']:118 if iset['shards'] != index_shards:
106 log += ' shards from {} to {}'.format(iset['shards'], conf['index_shards'])119 log += ' shards from {} to {}'.format(iset['shards'], index_shards)
107 iset['shards'] = conf['index_shards']120 iset['shards'] = index_shards
108 if iset['replicas'] != conf['index_replicas']:121 if iset['replicas'] != conf['index_replicas']:
109 log += ' replicas from {} to {}'.format(iset['replicas'], conf['index_replicas'])122 log += ' replicas from {} to {}'.format(iset['replicas'], conf['index_replicas'])
110 iset['replicas'] = conf['index_replicas']123 iset['replicas'] = conf['index_replicas']

Subscribers

People subscribed via source and target branches

to all changes: