Merge lp:~evarlast/charms/trusty/kibana/add-port-path-config into lp:charms/trusty/kibana

Proposed by Jay R. Wren
Status: Merged
Merged at revision: 18
Proposed branch: lp:~evarlast/charms/trusty/kibana/add-port-path-config
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:~evarlast/charms/trusty/kibana/add-port-path-config
Reviewer Review Type Date Requested Status
Jay R. Wren (community) Needs Resubmitting
Whit Morriss (community) Needs Fixing
Michael Foley (community) Needs Fixing
Charles Butler (community) Needs Fixing
Review via email: mp+255144@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.
19. By Jay R. Wren

fix port and path config settings

add config-changed hook

20. By Jay R. Wren

fix config-changed error

reload nginx after setting port

21. By Jay R. Wren

I've been tired.

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

Greetings Jay,

Thanks for this contribution. I've taken some time to look this over, and I have a few comments:

There's nothing that stands out about the code - however it would be nice to have the tests updated to flex the configuration option and validate that the resulting service is available on the port/path specified with the new configuration options. This will prevent us from breaking it in the future.

I did however notice that the charm when deployed via the tests results in failure. You can view the results here: http://reports.vapour.ws/charm-test-details/charm-bundle-test-parent-229

The Install hook is the culprit for the deployment failure. DEBUG:runner: unit: kibana/0: machine: 1 agent-state: error details: hook failed: "install" So I cannot block on this - but I will block on the lack of test coverage of the new options.

I'm happy to work with you on updating the tests if you need assistance to cover the new options. Feel free to reach out via IRC.

Otherwise, this MP looks good and aside from the minor feedback above is nearly ready for inclusion in the charm.

Thanks again for the submission. I'm going to change status of this MP to "needs work" and when you're ready switch merge status to 'needs review' and someone will be along shortly to review your work.

If you have any questions/comments/concerns about the review contact us in #juju on irc.freenode.net or email the mailing list <email address hidden>, or ask a question tagged with "juju" on http://askubuntu.com.

review: Needs Fixing
Revision history for this message
Michael Foley (foli) wrote :

elasticsearch sed line needs fixing as noted inline.

review: Needs Fixing
22. By Jay R. Wren

use protocol relative url

Revision history for this message
Whit Morriss (whitmo) wrote :

-1. I issued a merge proposal adding a test for configuring the port and a fix for opening a port. The original port will still need to be cleaned up.

review: Disapprove
Revision history for this message
Whit Morriss (whitmo) wrote :

Changing to appropriate status. Still waiting on port fixes.

review: Needs Fixing
23. By Jay R. Wren

close and open port on change

Revision history for this message
Jay R. Wren (evarlast) wrote :

Updated with closing previous port and opening new port. Added amulet test to test requests to configured port.

review: Needs Resubmitting
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

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:39 +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:39 +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:39 +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:39 +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:39 +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:39 +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:39 +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:39 +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