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
1diff --git a/config.yaml b/config.yaml
2index 9614533..3245461 100644
3--- a/config.yaml
4+++ b/config.yaml
5@@ -16,7 +16,7 @@ options:
6 type: int
7 default: 2
8 description: |
9- Number of Elasticsearch shards used per index in this index set.
10+ 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.
11 index_rotation_strategy:
12 type: string
13 default: "time"
14diff --git a/reactive/graylog.py b/reactive/graylog.py
15index c465552..13b3881 100644
16--- a/reactive/graylog.py
17+++ b/reactive/graylog.py
18@@ -100,11 +100,24 @@ def configure_index_sets(*discard):
19 index_sets = g.index_set_get()
20 if index_sets is None:
21 return
22+ index_shards = conf['index_shards']
23+ if index_shards is 0:
24+ # Automatically work out the index shards based on how
25+ # many Elasticsearch units.
26+ count = 0
27+ for relid in hookenv.relation_ids('elasticsearch'):
28+ count += len(hookenv.related_units(relid))
29+ if count:
30+ index_shards = count
31+ else:
32+ hookenv.log('Can\'t work out number of elasticsearch units')
33+ return
34+
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- iset['shards'] = conf['index_shards']
40+ if iset['shards'] != index_shards:
41+ log += ' shards from {} to {}'.format(iset['shards'], index_shards)
42+ iset['shards'] = index_shards
43 if iset['replicas'] != conf['index_replicas']:
44 log += ' replicas from {} to {}'.format(iset['replicas'], conf['index_replicas'])
45 iset['replicas'] = conf['index_replicas']

Subscribers

People subscribed via source and target branches

to all changes: