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
=== modified file 'config.yaml'
--- config.yaml 2016-03-08 16:38:17 +0000
+++ config.yaml 2016-03-10 22:57:41 +0000
@@ -27,3 +27,17 @@
27 By default, the admin and peer ports (9200 and 9300) are only accessible27 By default, the admin and peer ports (9200 and 9300) are only accessible
28 to clients and peers respectively. Switch this to false to enable access28 to clients and peers respectively. Switch this to false to enable access
29 from any machine.29 from any machine.
30 heap_size:
31 type: string
32 default: ""
33 description: |
34 By default, the heap size will be set to the maximum of half of the
35 available memory and 30.5G. A number in gigabytes for the Elasticsearch
36 heap size.
37 nagios_health_color:
38 type: string
39 default: green
40 description: |
41 By default we expect the cluster health to be green, but in some cases,
42 such as deploying a dev setup with a single instance, we can only expect
43 yellow as there is a primary shard but no replicas.
3044
=== added directory 'files/nrpe'
=== added file 'files/nrpe/check_health'
--- files/nrpe/check_health 1970-01-01 00:00:00 +0000
+++ files/nrpe/check_health 2016-03-10 22:57:41 +0000
@@ -0,0 +1,41 @@
1#!/usr/bin/env python
2from __future__ import print_function
3
4import json
5import urllib
6import sys
7
8
9def main(url, override_green):
10 resp = urllib.urlopen(url)
11 if resp.code == 200:
12 info = json.loads(resp.read())
13 status = info['status']
14 if status == "green" or (override_green and override_green == status):
15 print(info)
16 sys.exit(0)
17 elif status == "yellow":
18 print(info)
19 sys.exit(1)
20 elif status == "red":
21 print(info)
22 sys.exit(2)
23 else:
24 print("UNKNOWN status: {} - {}".format(status, info))
25 sys.exit(3)
26 else:
27 print('HTTP CODE: {} - BODY: {}'.format(resp.code, resp.read()))
28 sys.exit(2)
29
30if __name__ == "__main__":
31 import argparse
32 parser = argparse.ArgumentParser()
33 parser.add_argument("health_url")
34 parser.add_argument("--override-green", dest="override_green",
35 required=False, default="")
36 args = parser.parse_args()
37 try:
38 main(args.health_url, args.override_green)
39 except Exception as exc:
40 print(exc)
41 sys.exit(3)
042
=== modified file 'playbook.yaml'
--- playbook.yaml 2015-10-27 22:23:15 +0000
+++ playbook.yaml 2016-03-10 22:57:41 +0000
@@ -1,9 +1,9 @@
1- hosts: localhost1- hosts: localhost
2 roles:2 roles:
3 - role: nrpe3 - role: nrpe
4 check_name: check_http4 check_name: check_health
5 check_params: -H localhost -u /_cluster/health -p 9200 -w 2 -c 3 -s green5 check_params: http://localhost:9200/_cluster/health {{ '--override-green ' + nagios_health_color if nagios_health_color and nagios_health_color != 'green' else '' }}
6 service_description: "Verify the cluster health is green."6 service_description: "Verify the cluster health"
77
8 handlers:8 handlers:
99
@@ -14,6 +14,20 @@
14 - service_name: "{{ local_unit.split('/')[0] }}"14 - service_name: "{{ local_unit.split('/')[0] }}"
1515
16 tasks:16 tasks:
17 - name: Install nrpe plugins
18 tags:
19 - install
20 - upgrade-charm
21 copy: src="{{ charm_dir }}/files/nrpe/" dest="/usr/lib/nagios/plugins" mode=0755
22
23 - name: Remove old http nrpe check
24 tags:
25 - upgrade-charm
26 file: path={{ item.path }} state=absent
27 with_items:
28 - { path: "/etc/nagios/nrpe.d/check_http.cfg" }
29 - { path: "/var/lib/nagios/export/service__{{ relations['nrpe-external-master'][0]['nagios_hostname'] }}_check_http.cfg" }
30 when: '"nrpe-external-master" in relations and relations["nrpe-external-master"]|length > 0 and relations["nrpe-external-master"][0].nagios_hostname is defined'
1731
18 - include: tasks/install-elasticsearch.yml32 - include: tasks/install-elasticsearch.yml
19 - include: tasks/peer-relations.yml33 - include: tasks/peer-relations.yml
@@ -37,6 +51,14 @@
37 notify:51 notify:
38 - Restart ElasticSearch52 - Restart ElasticSearch
3953
54 - name: Update defaults
55 tags:
56 - config-changed
57 template: src={{ charm_dir }}/templates/etc_default.j2
58 dest=/etc/default/elasticsearch
59 notify:
60 - Restart ElasticSearch
61
40 - name: Open ES Port when exposed62 - name: Open ES Port when exposed
41 command: open-port 920063 command: open-port 9200
42 tags:64 tags:
4365
=== modified file 'tasks/install-elasticsearch.yml'
--- tasks/install-elasticsearch.yml 2015-10-01 19:00:31 +0000
+++ tasks/install-elasticsearch.yml 2016-03-10 22:57:41 +0000
@@ -45,3 +45,18 @@
45 - install45 - install
46 - upgrade-charm46 - upgrade-charm
47 when: stat_elasticsearch_deb.stat.exists == true47 when: stat_elasticsearch_deb.stat.exists == true
48
49- name: Set Elasticsearch user limits
50 tags:
51 - upgrade-charm
52 - install
53 template: src={{ charm_dir }}/templates/limits.conf
54 dest=/etc/security/limits.d/elasticsearch.conf
55 notify:
56 - Restart ElasticSearch
57
58- name: Ensure Elasticsearch is started on boot
59 tags:
60 - upgrade-charm
61 - install
62 service: name=elasticsearch enabled=yes
4863
=== modified file 'templates/elasticsearch.yml'
--- templates/elasticsearch.yml 2016-03-08 16:38:17 +0000
+++ templates/elasticsearch.yml 2016-03-10 22:57:41 +0000
@@ -11,3 +11,6 @@
11{% endfor %}11{% endfor %}
12# workaround for Kibana4 Export Everything bug https://github.com/elastic/kibana/issues/552412# workaround for Kibana4 Export Everything bug https://github.com/elastic/kibana/issues/5524
13index.max_result_window: 214748364713index.max_result_window: 2147483647
14
15# https://www.elastic.co/guide/en/elasticsearch/guide/current/heap-sizing.html
16bootstrap.mlockall: true
1417
=== added file 'templates/etc_default.j2'
--- templates/etc_default.j2 1970-01-01 00:00:00 +0000
+++ templates/etc_default.j2 2016-03-10 22:57:41 +0000
@@ -0,0 +1,14 @@
1# See https://www.elastic.co/guide/en/elasticsearch/guide/current/heap-sizing.html
2{% set calculated_heap_size = ansible_memtotal_mb / 1024.0 / 2.0 %}
3{# min/max filters only available in ansible 1.8 #}
4{% if calculated_heap_size >= 31.5 %}{% set calculated_heap_size = 31 %}{% endif %}
5{% set heap_size = heap_size | default(calculated_heap_size, true) | float %}
6# Note: ES doesn't start if the heap size is not an int of either gigabytes (g)
7# or megabytes (m)
8{% if heap_size > 4 %}
9ES_HEAP_SIZE={{ heap_size | int }}g
10{% else %}
11ES_HEAP_SIZE={{ (heap_size * 1024) | int }}m
12{% endif %}
13MAX_OPEN_FILES=65535
14MAX_LOCKED_MEMORY=unlimited
015
=== added file 'templates/limits.conf'
--- templates/limits.conf 1970-01-01 00:00:00 +0000
+++ templates/limits.conf 2016-03-10 22:57:41 +0000
@@ -0,0 +1,3 @@
1# Ensure ES user can run with max open files and unlimited memlock.
2elasticsearch - nofile 65535
3elasticsearch - memlock unlimited

Subscribers

People subscribed via source and target branches