Merge lp:~michael.nelson/charms/trusty/elasticsearch/merge-elasticsearch2-branch into lp:charms/trusty/elasticsearch

Proposed by Michael Nelson
Status: Needs review
Proposed branch: lp:~michael.nelson/charms/trusty/elasticsearch/merge-elasticsearch2-branch
Merge into: lp:charms/trusty/elasticsearch
Diff against target: 182 lines (+115/-3)
7 files modified
config.yaml (+14/-0)
files/nrpe/check_health (+41/-0)
playbook.yaml (+25/-3)
tasks/install-elasticsearch.yml (+15/-0)
templates/elasticsearch.yml (+3/-0)
templates/etc_default.j2 (+14/-0)
templates/limits.conf (+3/-0)
To merge this branch: bzr merge lp:~michael.nelson/charms/trusty/elasticsearch/merge-elasticsearch2-branch
Reviewer Review Type Date Requested Status
charmers Pending
Review via email: mp+288721@code.launchpad.net

Commit message

Add heap_size option defaulting to half of available mem (and memlock for better performance).
Add nagios_health_color options so development deploys of 1 unit can be yellow without nagios failures.
Ensure ES is restarted on boot.

Description of the change

Since we're updating the defaults in the stable ES charm, here are the other changes we'd since added and tested with ES2. They don't seem to be ES2 specific, but I've not verified with ES1.x.

To post a comment you must log in.
Revision history for this message
Chris Glass (tribaal) wrote :

Hi, thanks a lot for sending in your code!

It generally looks good, but I have small concerns with the parameters (see inline comments).

Revision history for this message
Charles Butler (lazypower) wrote :

Awesome! I like it. I'm going to +1 on tribaal's comments about the nagios context. Thats my only real nit here. otherwise LGTM as is.

Unmerged revisions

43. By Michael Nelson

Merge onlineservices elasticsearch2 branch.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'config.yaml'
2--- config.yaml 2016-03-08 16:38:17 +0000
3+++ config.yaml 2016-03-10 22:57:41 +0000
4@@ -27,3 +27,17 @@
5 By default, the admin and peer ports (9200 and 9300) are only accessible
6 to clients and peers respectively. Switch this to false to enable access
7 from any machine.
8+ heap_size:
9+ type: string
10+ default: ""
11+ description: |
12+ By default, the heap size will be set to the maximum of half of the
13+ available memory and 30.5G. A number in gigabytes for the Elasticsearch
14+ heap size.
15+ nagios_health_color:
16+ type: string
17+ default: green
18+ description: |
19+ By default we expect the cluster health to be green, but in some cases,
20+ such as deploying a dev setup with a single instance, we can only expect
21+ yellow as there is a primary shard but no replicas.
22
23=== added directory 'files/nrpe'
24=== added file 'files/nrpe/check_health'
25--- files/nrpe/check_health 1970-01-01 00:00:00 +0000
26+++ files/nrpe/check_health 2016-03-10 22:57:41 +0000
27@@ -0,0 +1,41 @@
28+#!/usr/bin/env python
29+from __future__ import print_function
30+
31+import json
32+import urllib
33+import sys
34+
35+
36+def main(url, override_green):
37+ resp = urllib.urlopen(url)
38+ if resp.code == 200:
39+ info = json.loads(resp.read())
40+ status = info['status']
41+ if status == "green" or (override_green and override_green == status):
42+ print(info)
43+ sys.exit(0)
44+ elif status == "yellow":
45+ print(info)
46+ sys.exit(1)
47+ elif status == "red":
48+ print(info)
49+ sys.exit(2)
50+ else:
51+ print("UNKNOWN status: {} - {}".format(status, info))
52+ sys.exit(3)
53+ else:
54+ print('HTTP CODE: {} - BODY: {}'.format(resp.code, resp.read()))
55+ sys.exit(2)
56+
57+if __name__ == "__main__":
58+ import argparse
59+ parser = argparse.ArgumentParser()
60+ parser.add_argument("health_url")
61+ parser.add_argument("--override-green", dest="override_green",
62+ required=False, default="")
63+ args = parser.parse_args()
64+ try:
65+ main(args.health_url, args.override_green)
66+ except Exception as exc:
67+ print(exc)
68+ sys.exit(3)
69
70=== modified file 'playbook.yaml'
71--- playbook.yaml 2015-10-27 22:23:15 +0000
72+++ playbook.yaml 2016-03-10 22:57:41 +0000
73@@ -1,9 +1,9 @@
74 - hosts: localhost
75 roles:
76 - role: nrpe
77- check_name: check_http
78- check_params: -H localhost -u /_cluster/health -p 9200 -w 2 -c 3 -s green
79- service_description: "Verify the cluster health is green."
80+ check_name: check_health
81+ check_params: http://localhost:9200/_cluster/health {{ '--override-green ' + nagios_health_color if nagios_health_color and nagios_health_color != 'green' else '' }}
82+ service_description: "Verify the cluster health"
83
84 handlers:
85
86@@ -14,6 +14,20 @@
87 - service_name: "{{ local_unit.split('/')[0] }}"
88
89 tasks:
90+ - name: Install nrpe plugins
91+ tags:
92+ - install
93+ - upgrade-charm
94+ copy: src="{{ charm_dir }}/files/nrpe/" dest="/usr/lib/nagios/plugins" mode=0755
95+
96+ - name: Remove old http nrpe check
97+ tags:
98+ - upgrade-charm
99+ file: path={{ item.path }} state=absent
100+ with_items:
101+ - { path: "/etc/nagios/nrpe.d/check_http.cfg" }
102+ - { path: "/var/lib/nagios/export/service__{{ relations['nrpe-external-master'][0]['nagios_hostname'] }}_check_http.cfg" }
103+ when: '"nrpe-external-master" in relations and relations["nrpe-external-master"]|length > 0 and relations["nrpe-external-master"][0].nagios_hostname is defined'
104
105 - include: tasks/install-elasticsearch.yml
106 - include: tasks/peer-relations.yml
107@@ -37,6 +51,14 @@
108 notify:
109 - Restart ElasticSearch
110
111+ - name: Update defaults
112+ tags:
113+ - config-changed
114+ template: src={{ charm_dir }}/templates/etc_default.j2
115+ dest=/etc/default/elasticsearch
116+ notify:
117+ - Restart ElasticSearch
118+
119 - name: Open ES Port when exposed
120 command: open-port 9200
121 tags:
122
123=== modified file 'tasks/install-elasticsearch.yml'
124--- tasks/install-elasticsearch.yml 2015-10-01 19:00:31 +0000
125+++ tasks/install-elasticsearch.yml 2016-03-10 22:57:41 +0000
126@@ -45,3 +45,18 @@
127 - install
128 - upgrade-charm
129 when: stat_elasticsearch_deb.stat.exists == true
130+
131+- name: Set Elasticsearch user limits
132+ tags:
133+ - upgrade-charm
134+ - install
135+ template: src={{ charm_dir }}/templates/limits.conf
136+ dest=/etc/security/limits.d/elasticsearch.conf
137+ notify:
138+ - Restart ElasticSearch
139+
140+- name: Ensure Elasticsearch is started on boot
141+ tags:
142+ - upgrade-charm
143+ - install
144+ service: name=elasticsearch enabled=yes
145
146=== modified file 'templates/elasticsearch.yml'
147--- templates/elasticsearch.yml 2016-03-08 16:38:17 +0000
148+++ templates/elasticsearch.yml 2016-03-10 22:57:41 +0000
149@@ -11,3 +11,6 @@
150 {% endfor %}
151 # workaround for Kibana4 Export Everything bug https://github.com/elastic/kibana/issues/5524
152 index.max_result_window: 2147483647
153+
154+# https://www.elastic.co/guide/en/elasticsearch/guide/current/heap-sizing.html
155+bootstrap.mlockall: true
156
157=== added file 'templates/etc_default.j2'
158--- templates/etc_default.j2 1970-01-01 00:00:00 +0000
159+++ templates/etc_default.j2 2016-03-10 22:57:41 +0000
160@@ -0,0 +1,14 @@
161+# See https://www.elastic.co/guide/en/elasticsearch/guide/current/heap-sizing.html
162+{% set calculated_heap_size = ansible_memtotal_mb / 1024.0 / 2.0 %}
163+{# min/max filters only available in ansible 1.8 #}
164+{% if calculated_heap_size >= 31.5 %}{% set calculated_heap_size = 31 %}{% endif %}
165+{% set heap_size = heap_size | default(calculated_heap_size, true) | float %}
166+# Note: ES doesn't start if the heap size is not an int of either gigabytes (g)
167+# or megabytes (m)
168+{% if heap_size > 4 %}
169+ES_HEAP_SIZE={{ heap_size | int }}g
170+{% else %}
171+ES_HEAP_SIZE={{ (heap_size * 1024) | int }}m
172+{% endif %}
173+MAX_OPEN_FILES=65535
174+MAX_LOCKED_MEMORY=unlimited
175
176=== added file 'templates/limits.conf'
177--- templates/limits.conf 1970-01-01 00:00:00 +0000
178+++ templates/limits.conf 2016-03-10 22:57:41 +0000
179@@ -0,0 +1,3 @@
180+# Ensure ES user can run with max open files and unlimited memlock.
181+elasticsearch - nofile 65535
182+elasticsearch - memlock unlimited

Subscribers

People subscribed via source and target branches