Merge lp:~yellow/charms/trusty/kibana/trunk into lp:charms/trusty/kibana

Proposed by Jay R. Wren
Status: Merged
Merged at revision: 18
Proposed branch: lp:~yellow/charms/trusty/kibana/trunk
Merge into: lp:charms/trusty/kibana
Diff against target: 153 lines (+72/-9)
8 files modified
config.yaml (+9/-0)
hooks/config-changed (+18/-0)
hooks/install (+5/-2)
hooks/start (+1/-3)
hooks/stop (+3/-2)
hooks/web-relation-joined (+3/-1)
metadata.yaml (+1/-1)
tests/12-port-change.py (+32/-0)
To merge this branch: bzr merge lp:~yellow/charms/trusty/kibana/trunk
Reviewer Review Type Date Requested Status
Marco Ceppi (community) Approve
Review via email: mp+262373@code.launchpad.net

Description of the change

Adds nginx tcp port configuration option and a path option for configuring it to be proxy fronted with a path. e.g. /kibana and not at the root of a url.

To post a comment you must log in.
Revision history for this message
Jay R. Wren (evarlast) wrote :
24. By Jay R. Wren

close port only if previously opened

25. By Jay R. Wren

fix idempotency problems

26. By Jay R. Wren

explicitly define empty env var

Revision history for this message
Marco Ceppi (marcoceppi) wrote :

LGTM, I've left a comment on how you could simplify some of the logic, but otherwise +1

review: Approve

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 2014-11-05 05:21:37 +0000
3+++ config.yaml 2015-06-18 20:53:52 +0000
4@@ -11,3 +11,12 @@
5 type: string
6 default: '74c6b8b79d1bfc7e4d5376e3c9ecb0fa1e79c986'
7 description: the sha1sum of the kibana_source
8+ port:
9+ type: int
10+ default: 80
11+ description: The tcp port on which nginx will listen.
12+ path:
13+ type: string
14+ default: ''
15+ description: 'The url path of kibana. This is required if kibana is
16+ proxied at a non root path. e.g. http://example.com/kibana/'
17
18=== added file 'hooks/config-changed'
19--- hooks/config-changed 1970-01-01 00:00:00 +0000
20+++ hooks/config-changed 2015-06-18 20:53:52 +0000
21@@ -0,0 +1,18 @@
22+#!/bin/bash
23+set -eux
24+
25+PORT=$(config-get port)
26+KIBANA_PATH=$(config-get path)
27+
28+sed -i "s/listen.*/listen *:$PORT;/" /etc/nginx/sites-available/kibana
29+
30+sed -i "s@elasticsearch: .*@elasticsearch: '//'+window.location.hostname+'$KIBANA_PATH',@" /srv/kibana3/config.js
31+
32+service nginx reload
33+
34+[[ -r .PREVOPENPORT ]] && PREVOPENPORT=$(cat .PREVOPENPORT) || PREVOPENPORT=''
35+[[ -z "$PREVOPENPORT" ]] || close-port $PREVOPENPORT/tcp
36+
37+open-port $PORT/tcp
38+echo $PORT > .PREVOPENPORT
39+
40
41=== modified file 'hooks/install'
42--- hooks/install 2015-04-01 19:38:58 +0000
43+++ hooks/install 2015-06-18 20:53:52 +0000
44@@ -26,8 +26,10 @@
45
46 pushd /srv
47
48-tar xzvf /tmp/kibana.tgz
49-mv ${KIBANA_SOURCE_UNPACK_DIRECTORY} kibana3
50+if [[ ! -d kibana3 ]]; then
51+ tar xzvf /tmp/kibana.tgz
52+ mv ${KIBANA_SOURCE_UNPACK_DIRECTORY} kibana3
53+fi
54
55 rm -f /etc/nginx/sites-enabled/default
56
57@@ -36,6 +38,7 @@
58 rm -f /srv/kibana3/config.js
59 install -o root -g root -m 0644 files/charm/config.js /srv/kibana3/config.js
60
61+hooks/config-changed
62
63 ln -s /etc/nginx/sites-available/kibana /etc/nginx/sites-enabled/kibana
64 ln -s /etc/nginx/sites-available/es_cluster /etc/nginx/sites-enabled/es_cluster
65
66=== modified file 'hooks/start' (properties changed: +x to -x)
67--- hooks/start 2013-09-29 21:58:50 +0000
68+++ hooks/start 2015-06-18 20:53:52 +0000
69@@ -3,6 +3,4 @@
70 # Note that currently this is run directly after install
71 # i.e. 'service apache2 start'
72
73-initctl start nginx
74-#open-port 5601/tcp
75-open-port 80/tcp
76+service nginx start
77
78=== modified file 'hooks/stop'
79--- hooks/stop 2013-09-29 21:58:50 +0000
80+++ hooks/stop 2015-06-18 20:53:52 +0000
81@@ -6,5 +6,6 @@
82 # balancer to stop sending traffic.
83 # rm /srv/webroot/server-live.txt && sleep 30
84
85-initctl stop nginx
86-close-port 80/tcp
87+service nginx stop
88+[[ -r .PREVOPENPORT ]] && PREVOPENPORT=$(cat .PREVOPENPORT) || PREVOPENPORT=''
89+[[ -z "$PREVOPENPORT" ]] || close-port $PREVOPENPORT/tcp
90
91=== modified file 'hooks/web-relation-joined'
92--- hooks/web-relation-joined 2013-11-26 08:51:58 +0000
93+++ hooks/web-relation-joined 2015-06-18 20:53:52 +0000
94@@ -2,6 +2,8 @@
95 set -eux
96 juju-log $JUJU_REMOTE_UNIT joined
97
98+PORT=$(config-get port)
99+
100 # Set ip/port for web relation
101-relation-set port="80"
102+relation-set port="$PORT"
103 relation-set host=`unit-get private-address`
104
105=== modified file 'metadata.yaml'
106--- metadata.yaml 2014-10-29 15:52:18 +0000
107+++ metadata.yaml 2015-06-18 20:53:52 +0000
108@@ -7,7 +7,7 @@
109 - applications
110 provides:
111 web:
112- interface: kibana
113+ interface: http
114 requires:
115 rest:
116 interface: elasticsearch
117
118=== added file 'tests/12-port-change.py'
119--- tests/12-port-change.py 1970-01-01 00:00:00 +0000
120+++ tests/12-port-change.py 2015-06-18 20:53:52 +0000
121@@ -0,0 +1,32 @@
122+#!/usr/bin/python3
123+
124+import amulet
125+import requests
126+
127+seconds = 20000
128+
129+d = amulet.Deployment(series='trusty')
130+
131+d.add('kibana')
132+d.configure('kibana', {'port': 81})
133+
134+d.expose('kibana')
135+
136+try:
137+ d.setup(timeout=seconds)
138+except amulet.helpers.TimeoutError:
139+ amulet.raise_status(amulet.SKIP, msg="Environment wasn't stood up in time")
140+except:
141+ raise
142+
143+
144+def test_web_interface():
145+ kibana_unit = d.sentry.unit['kibana/0']
146+ url = 'http://%s:81/' % kibana_unit.info['public-address']
147+ r = requests.get(url)
148+ if not r.ok:
149+ amulet.raise_status(amulet.FAIL,
150+ msg="Error getting kibana page.")
151+
152+
153+test_web_interface()

Subscribers

People subscribed via source and target branches