Merge lp:~foli/charms/trusty/logstash/add-lumberjack-protocol into lp:~lazypower/charms/trusty/logstash/trunk

Proposed by Michael Foley
Status: Merged
Merged at revision: 47
Proposed branch: lp:~foli/charms/trusty/logstash/add-lumberjack-protocol
Merge into: lp:~lazypower/charms/trusty/logstash/trunk
Diff against target: 165 lines (+72/-5)
6 files modified
config.yaml (+8/-0)
hooks/config-changed (+36/-4)
hooks/install (+3/-0)
hooks/lumberjack-relation-changed (+7/-0)
metadata.yaml (+5/-1)
templates/input-lumberjack.conf (+13/-0)
To merge this branch: bzr merge lp:~foli/charms/trusty/logstash/add-lumberjack-protocol
Reviewer Review Type Date Requested Status
Charles Butler Approve
Review via email: mp+256630@code.launchpad.net

Description of the change

Have added input-lumberjack.conf file for lumberjack protocol used by logstash-forwarder.

Added code to only install the conf file if necessary SSL certs are available, otherwise logstash fails to start.

Added a relation to haproxy of the lumberjack protocol so that multiple logstash units can be placed behind haproxy.

Tom added support for exec.d infrastructure so we can customise instances.

To post a comment you must log in.
46. By Charles Butler

Removed excess comments from base of charm test

47. By Charles Butler

[r,a=lazypower] Michael Foley 2015-04-17 [foley] Add myself to maintainers field
Michael Foley 2015-04-17 [merge] [mthaddon,r=foli] Add support for exec.d infrastructure so we can customise instances
Tom Haddon 2015-04-16 Add support for exec.d infrastructure so we can customise instances
Michael Foley 2015-04-17 [merge] [foley] merge in upstream changes for fixing local tarball installation
Michael Foley 2015-04-15 [foli] changed lumberjack-relation-joined lumberjack-relation-changed with symlink for joined
Michael Foley 2015-04-15 [foli] add relation for haproxy to proxy lumberjack on port 5043
Michael Foley 2015-04-07 [foli] lumberjack conf file only enabled if ssl cert/key are configured
Michael Foley 2015-04-07 [merge] [mthaddon,r=foli] Open the port we need for the service
Tom Haddon 2015-04-02 Open the port we need for the service
Michael Foley 2015-04-01 [foli] Fix more copy-paste errors by adding necessary imports, fix file perms for ssl
Michael Foley 2015-04-01 [foli] Fix copy-paste error for config_data for ssl cert/key
Michael Foley 2015-03-31 [foli] Added lumberjack input conf file, added ssl_cert & ssl_key configuration

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

All of this looks good to me. I just have a single comment - that we need to get a test built that leverages the lumberjack relationship and validate everything is working so we know if it breaks in the future.

I'll assign a bug for this and happily merge. Thanks for the contributions!

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-08-18 20:06:27 +0000
3+++ config.yaml 2015-04-17 08:58:06 +0000
4@@ -11,3 +11,11 @@
5 type: string
6 default: ''
7 description: Space separated list of extra apt packages to install.
8+ ssl_cert:
9+ default: ""
10+ type: string
11+ description: "Base64-encoded SSL certificate"
12+ ssl_key:
13+ default: ""
14+ type: string
15+ description: "Base64-encoded SSL key"
16
17=== added directory 'exec.d'
18=== modified file 'hooks/config-changed'
19--- hooks/config-changed 2014-09-23 18:18:13 +0000
20+++ hooks/config-changed 2015-04-17 08:58:06 +0000
21@@ -4,6 +4,9 @@
22 import shlex
23 import subprocess
24 import sys
25+import pwd
26+import grp
27+import base64
28
29
30 sys.path.insert(0, os.path.join(os.environ['CHARM_DIR'], 'lib'))
31@@ -33,6 +36,9 @@
32 copy_config()
33 place_upstart_template()
34
35+ # This only actually opens the port if we've exposed the service in juju
36+ hookenv.open_port(5043)
37+
38 # The install hook is idempotent, so re-run it.
39 subprocess.check_output(shlex.split('hooks/install'))
40
41@@ -40,9 +46,36 @@
42 def copy_config():
43 files = os.listdir('templates')
44 opts = {'BASEPATH': BASEPATH}
45+ lumberjack_template = "input-lumberjack.conf"
46+ cert_dir = os.path.join(BASEPATH, 'ssl')
47+ cert_file = os.path.join(cert_dir, 'logstash.crt')
48+ key_file = os.path.join(cert_dir, 'logstash.key')
49+
50 for f in files:
51- with open(os.path.join(BASEPATH, 'conf.d', f), 'w') as p:
52- p.write(render(os.path.basename(f), opts))
53+ if os.path.basename(f) != lumberjack_template:
54+ with open(os.path.join(BASEPATH, 'conf.d', f), 'w') as p:
55+ p.write(render(os.path.basename(f), opts))
56+
57+ config_data = hookenv.config()
58+ # Only setup lumberjack protocol if ssl cert and key are configured
59+ if config_data['ssl_cert'] and config_data['ssl_key']:
60+ if not os.path.exists(cert_dir):
61+ os.mkdir(cert_dir, 0770)
62+ os.chown(cert_dir, pwd.getpwnam('logstash').pw_uid, grp.getgrnam('logstash').gr_gid)
63+
64+ # Certificate provided as base64-encoded string.
65+ if config_data['ssl_cert']:
66+ log("Writing cert from config ssl_cert: %s" % cert_file)
67+ with open(cert_file, 'w') as f:
68+ f.write(str(base64.b64decode(config_data['ssl_cert'])))
69+ # Private key provided as base64-encoded string.
70+ if config_data['ssl_key']:
71+ log("Writing key from config ssl_key: %s" % key_file)
72+ with open(key_file, 'w') as f:
73+ f.write(str(base64.b64decode(config_data['ssl_key'])))
74+
75+ with open(os.path.join(BASEPATH, 'conf.d', lumberjack_template), 'w') as p:
76+ p.write(render(os.path.basename(lumberjack_template), opts))
77
78
79 def place_upstart_template():
80@@ -51,8 +84,7 @@
81 opts = {'BASEPATH': BASEPATH}
82
83 with open(out, 'w') as p:
84- p.write(render('{}.conf'.format(SERVICE), opts, template_dir=templ))
85-
86+ p.write(render('{}.conf'.format(SERVICE), opts, template_dir=templ))
87
88
89 if __name__ == "__main__":
90
91=== modified file 'hooks/install'
92--- hooks/install 2015-03-30 18:36:01 +0000
93+++ hooks/install 2015-04-17 08:58:06 +0000
94@@ -22,6 +22,8 @@
95 apt_install,
96 )
97
98+from charmhelpers.payload.execd import execd_preinstall
99+
100 hooks = Hooks()
101 log = log
102
103@@ -31,6 +33,7 @@
104
105 @hooks.hook('install')
106 def install():
107+ execd_preinstall()
108 log('Installing logstash')
109 packages = ['openjdk-7-jre-headless', 'redis-server', 'python-jinja2']
110 extra_packages = config('extra-packages')
111
112=== added file 'hooks/lumberjack-relation-changed'
113--- hooks/lumberjack-relation-changed 1970-01-01 00:00:00 +0000
114+++ hooks/lumberjack-relation-changed 2015-04-17 08:58:06 +0000
115@@ -0,0 +1,7 @@
116+#!/bin/bash
117+
118+set -eux
119+
120+hostname=$(unit-get private-address)
121+juju-log "Setting lumberjack URL to $hostname:5043"
122+relation-set port=5043 hostname=$hostname
123
124=== added symlink 'hooks/lumberjack-relation-joined'
125=== target is u'lumberjack-relation-changed'
126=== modified file 'metadata.yaml'
127--- metadata.yaml 2014-10-29 16:10:22 +0000
128+++ metadata.yaml 2015-04-17 08:58:06 +0000
129@@ -1,6 +1,8 @@
130 name: logstash
131 summary: "Logstash indexer server"
132-maintainer: charles <charles.butler@ubuntu.com>
133+maintainers:
134+ - charles <charles.butler@ubuntu.com>
135+ - Michael Foley <michael.foley@canonical.com>
136 description: |
137 Installs the logstash indexer. Initially stand alone version with a
138 dependency on elasticsearch as the backend provider.
139@@ -12,6 +14,8 @@
140 interface: redis
141 rest:
142 interface: elasticsearch
143+ lumberjack:
144+ interface: http
145 requires:
146 client:
147 interface: elasticsearch
148
149=== added file 'templates/input-lumberjack.conf'
150--- templates/input-lumberjack.conf 1970-01-01 00:00:00 +0000
151+++ templates/input-lumberjack.conf 2015-04-17 08:58:06 +0000
152@@ -0,0 +1,13 @@
153+input {
154+ lumberjack {
155+ # The port to listen on
156+ port => 5043
157+
158+ # The paths to your ssl cert and key
159+ ssl_certificate => "{{BASEPATH}}/ssl/logstash.crt"
160+ ssl_key => "{{BASEPATH}}/ssl/logstash.key"
161+
162+ # Set this to whatever you want.
163+ type => "lumberjack"
164+ }
165+}

Subscribers

People subscribed via source and target branches

to all changes: