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
=== modified file 'config.yaml'
--- config.yaml 2014-08-18 20:06:27 +0000
+++ config.yaml 2015-04-17 08:58:06 +0000
@@ -11,3 +11,11 @@
11 type: string11 type: string
12 default: ''12 default: ''
13 description: Space separated list of extra apt packages to install.13 description: Space separated list of extra apt packages to install.
14 ssl_cert:
15 default: ""
16 type: string
17 description: "Base64-encoded SSL certificate"
18 ssl_key:
19 default: ""
20 type: string
21 description: "Base64-encoded SSL key"
1422
=== added directory 'exec.d'
=== modified file 'hooks/config-changed'
--- hooks/config-changed 2014-09-23 18:18:13 +0000
+++ hooks/config-changed 2015-04-17 08:58:06 +0000
@@ -4,6 +4,9 @@
4import shlex4import shlex
5import subprocess5import subprocess
6import sys6import sys
7import pwd
8import grp
9import base64
710
811
9sys.path.insert(0, os.path.join(os.environ['CHARM_DIR'], 'lib'))12sys.path.insert(0, os.path.join(os.environ['CHARM_DIR'], 'lib'))
@@ -33,6 +36,9 @@
33 copy_config()36 copy_config()
34 place_upstart_template()37 place_upstart_template()
3538
39 # This only actually opens the port if we've exposed the service in juju
40 hookenv.open_port(5043)
41
36 # The install hook is idempotent, so re-run it.42 # The install hook is idempotent, so re-run it.
37 subprocess.check_output(shlex.split('hooks/install'))43 subprocess.check_output(shlex.split('hooks/install'))
3844
@@ -40,9 +46,36 @@
40def copy_config():46def copy_config():
41 files = os.listdir('templates')47 files = os.listdir('templates')
42 opts = {'BASEPATH': BASEPATH}48 opts = {'BASEPATH': BASEPATH}
49 lumberjack_template = "input-lumberjack.conf"
50 cert_dir = os.path.join(BASEPATH, 'ssl')
51 cert_file = os.path.join(cert_dir, 'logstash.crt')
52 key_file = os.path.join(cert_dir, 'logstash.key')
53
43 for f in files:54 for f in files:
44 with open(os.path.join(BASEPATH, 'conf.d', f), 'w') as p:55 if os.path.basename(f) != lumberjack_template:
45 p.write(render(os.path.basename(f), opts))56 with open(os.path.join(BASEPATH, 'conf.d', f), 'w') as p:
57 p.write(render(os.path.basename(f), opts))
58
59 config_data = hookenv.config()
60 # Only setup lumberjack protocol if ssl cert and key are configured
61 if config_data['ssl_cert'] and config_data['ssl_key']:
62 if not os.path.exists(cert_dir):
63 os.mkdir(cert_dir, 0770)
64 os.chown(cert_dir, pwd.getpwnam('logstash').pw_uid, grp.getgrnam('logstash').gr_gid)
65
66 # Certificate provided as base64-encoded string.
67 if config_data['ssl_cert']:
68 log("Writing cert from config ssl_cert: %s" % cert_file)
69 with open(cert_file, 'w') as f:
70 f.write(str(base64.b64decode(config_data['ssl_cert'])))
71 # Private key provided as base64-encoded string.
72 if config_data['ssl_key']:
73 log("Writing key from config ssl_key: %s" % key_file)
74 with open(key_file, 'w') as f:
75 f.write(str(base64.b64decode(config_data['ssl_key'])))
76
77 with open(os.path.join(BASEPATH, 'conf.d', lumberjack_template), 'w') as p:
78 p.write(render(os.path.basename(lumberjack_template), opts))
4679
4780
48def place_upstart_template():81def place_upstart_template():
@@ -51,8 +84,7 @@
51 opts = {'BASEPATH': BASEPATH}84 opts = {'BASEPATH': BASEPATH}
5285
53 with open(out, 'w') as p:86 with open(out, 'w') as p:
54 p.write(render('{}.conf'.format(SERVICE), opts, template_dir=templ))87 p.write(render('{}.conf'.format(SERVICE), opts, template_dir=templ))
55
5688
5789
58if __name__ == "__main__":90if __name__ == "__main__":
5991
=== modified file 'hooks/install'
--- hooks/install 2015-03-30 18:36:01 +0000
+++ hooks/install 2015-04-17 08:58:06 +0000
@@ -22,6 +22,8 @@
22 apt_install,22 apt_install,
23)23)
2424
25from charmhelpers.payload.execd import execd_preinstall
26
25hooks = Hooks()27hooks = Hooks()
26log = log28log = log
2729
@@ -31,6 +33,7 @@
3133
32@hooks.hook('install')34@hooks.hook('install')
33def install():35def install():
36 execd_preinstall()
34 log('Installing logstash')37 log('Installing logstash')
35 packages = ['openjdk-7-jre-headless', 'redis-server', 'python-jinja2']38 packages = ['openjdk-7-jre-headless', 'redis-server', 'python-jinja2']
36 extra_packages = config('extra-packages')39 extra_packages = config('extra-packages')
3740
=== added file 'hooks/lumberjack-relation-changed'
--- hooks/lumberjack-relation-changed 1970-01-01 00:00:00 +0000
+++ hooks/lumberjack-relation-changed 2015-04-17 08:58:06 +0000
@@ -0,0 +1,7 @@
1#!/bin/bash
2
3set -eux
4
5hostname=$(unit-get private-address)
6juju-log "Setting lumberjack URL to $hostname:5043"
7relation-set port=5043 hostname=$hostname
08
=== added symlink 'hooks/lumberjack-relation-joined'
=== target is u'lumberjack-relation-changed'
=== modified file 'metadata.yaml'
--- metadata.yaml 2014-10-29 16:10:22 +0000
+++ metadata.yaml 2015-04-17 08:58:06 +0000
@@ -1,6 +1,8 @@
1name: logstash1name: logstash
2summary: "Logstash indexer server"2summary: "Logstash indexer server"
3maintainer: charles <charles.butler@ubuntu.com>3maintainers:
4 - charles <charles.butler@ubuntu.com>
5 - Michael Foley <michael.foley@canonical.com>
4description: |6description: |
5 Installs the logstash indexer. Initially stand alone version with a7 Installs the logstash indexer. Initially stand alone version with a
6 dependency on elasticsearch as the backend provider.8 dependency on elasticsearch as the backend provider.
@@ -12,6 +14,8 @@
12 interface: redis14 interface: redis
13 rest:15 rest:
14 interface: elasticsearch16 interface: elasticsearch
17 lumberjack:
18 interface: http
15requires:19requires:
16 client:20 client:
17 interface: elasticsearch21 interface: elasticsearch
1822
=== added file 'templates/input-lumberjack.conf'
--- templates/input-lumberjack.conf 1970-01-01 00:00:00 +0000
+++ templates/input-lumberjack.conf 2015-04-17 08:58:06 +0000
@@ -0,0 +1,13 @@
1input {
2 lumberjack {
3 # The port to listen on
4 port => 5043
5
6 # The paths to your ssl cert and key
7 ssl_certificate => "{{BASEPATH}}/ssl/logstash.crt"
8 ssl_key => "{{BASEPATH}}/ssl/logstash.key"
9
10 # Set this to whatever you want.
11 type => "lumberjack"
12 }
13}

Subscribers

People subscribed via source and target branches

to all changes: