Merge ~axino/juju-introspection-proxy-charm/+git/juju-introspection-proxy-charm:axino into juju-introspection-proxy-charm:master

Proposed by Junien F
Status: Merged
Approved by: Barry Price
Approved revision: 500dfe7efaef16355e33a958d158203d6ace888f
Merged at revision: b754cc3ff7fc4d2c27bbb17183f0f79f7639daf0
Proposed branch: ~axino/juju-introspection-proxy-charm/+git/juju-introspection-proxy-charm:axino
Merge into: juju-introspection-proxy-charm:master
Diff against target: 163 lines (+127/-0)
6 files modified
README.md (+14/-0)
config.yaml (+6/-0)
layer.yaml (+1/-0)
metadata.yaml (+20/-0)
reactive/juju_introspection_proxy.py (+75/-0)
templates/juju-introspection.service (+11/-0)
Reviewer Review Type Date Requested Status
Barry Price Approve
Review via email: mp+333361@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Barry Price (barryprice) wrote :

Looks good to me, +1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/README.md b/README.md
2new file mode 100644
3index 0000000..edb8bcd
4--- /dev/null
5+++ b/README.md
6@@ -0,0 +1,14 @@
7+Relate this charm to any Juju application to make Juju introspection data
8+available over HTTP (for consumption by prometheus, for example).
9+
10+You will need to build the go binary from
11+https://github.com/axw/juju-introspection-proxy and specify it as the "binary"
12+resource, for example :
13+
14+```
15+$ juju deploy juju-introspection-proxy --resource binary=/path/to/juju-introspection-proxy
16+$ juju add-relation my-awesome-application juju-introspection-proxy
17+$ juju expose juju-introspection-proxy
18+```
19+
20+Metrics will be available at ```http://<unit_ip>:19090/metrics```.
21diff --git a/config.yaml b/config.yaml
22new file mode 100644
23index 0000000..2e3969e
24--- /dev/null
25+++ b/config.yaml
26@@ -0,0 +1,6 @@
27+options:
28+ port:
29+ type: int
30+ default: 19090
31+ description: "Port to listen for connections on"
32+
33diff --git a/layer.yaml b/layer.yaml
34new file mode 100644
35index 0000000..102cf18
36--- /dev/null
37+++ b/layer.yaml
38@@ -0,0 +1 @@
39+includes: ['layer:basic'] # if you use any interfaces, add them here
40diff --git a/metadata.yaml b/metadata.yaml
41new file mode 100644
42index 0000000..6c25bd0
43--- /dev/null
44+++ b/metadata.yaml
45@@ -0,0 +1,20 @@
46+name: juju-introspection-proxy
47+summary: A proxy to the Juju introspection metrics
48+maintainer: Junien Fridrick <junien.fridrick@canonical.com>
49+description: |
50+ A proxy to the Juju introspection metrics
51+tags:
52+ - monitoring
53+ - performance
54+subordinate: true
55+series:
56+ - xenial
57+requires:
58+ container:
59+ interface: juju-info
60+ scope: container
61+resources:
62+ binary:
63+ type: file
64+ filename: juju-introspection-proxy
65+ description: the Juju introspection proxy binary
66diff --git a/reactive/juju_introspection_proxy.py b/reactive/juju_introspection_proxy.py
67new file mode 100644
68index 0000000..7a5ea6f
69--- /dev/null
70+++ b/reactive/juju_introspection_proxy.py
71@@ -0,0 +1,75 @@
72+import os
73+import subprocess
74+
75+from charms.reactive import (
76+ set_state,
77+ when,
78+ when_not,
79+)
80+
81+from charmhelpers.core import (
82+ hookenv,
83+ templating,
84+)
85+
86+INSTALL_ROOT = "/srv/juju-introspection-proxy"
87+INSTALL_PATH = os.path.join(INSTALL_ROOT, 'bin', 'juju-introspection-proxy')
88+
89+
90+@when_not('juju-introspection.installed')
91+def install_juju_introspection():
92+ ''' Install the proxy application '''
93+
94+ try:
95+ binary = hookenv.resource_get('binary')
96+ except Exception:
97+ message = 'Error fetching the binary resource.'
98+ hookenv.log(message)
99+ hookenv.status_set('blocked', message)
100+ return
101+ if not binary:
102+ message = 'Missing binary resource.'
103+ hookenv.log(message)
104+ hookenv.status_set('blocked', message)
105+ return
106+
107+ install = ['install', '-v', '-D', binary, INSTALL_PATH]
108+ subprocess.check_call(install)
109+
110+ # Create a systemd unit file, and open the port.
111+ port = hookenv.config()['port']
112+ write_systemd_unit(port)
113+ subprocess.check_call(['systemctl', 'enable', 'juju-introspection'])
114+ subprocess.check_call(['systemctl', 'start', 'juju-introspection'])
115+ hookenv.open_port(port)
116+ hookenv.status_set('active', 'serving metrics')
117+ set_state('juju-introspection.installed')
118+
119+
120+@when('config.changed.port')
121+def update_systemd_unit():
122+ config = hookenv.config()
123+ new_port = config['port']
124+ old_port = config.previous('port')
125+
126+ write_systemd_unit(new_port)
127+ subprocess.check_call(['systemctl', 'daemon-reload'])
128+ subprocess.check_call(['systemctl', 'restart', 'juju-introspection'])
129+
130+ if old_port:
131+ hookenv.close_port(old_port)
132+ hookenv.open_port(new_port)
133+ hookenv.status_set('active', 'serving metrics')
134+
135+
136+def write_systemd_unit(port):
137+ listen_addr = ':{}'.format(port)
138+ templating.render(
139+ 'juju-introspection.service',
140+ '/etc/systemd/system/juju-introspection.service',
141+ {
142+ 'addr': listen_addr,
143+ 'executable': INSTALL_PATH,
144+ 'unit_name': hookenv.local_unit(),
145+ },
146+ )
147diff --git a/templates/juju-introspection.service b/templates/juju-introspection.service
148new file mode 100644
149index 0000000..2400a76
150--- /dev/null
151+++ b/templates/juju-introspection.service
152@@ -0,0 +1,11 @@
153+[Unit]
154+Description=JujuIntrospection
155+
156+[Service]
157+ExecStart={{executable}} -addr "{{addr}}"
158+Environment="JUJU_UNIT_NAME={{unit_name}}"
159+Restart=on-failure
160+TimeoutSec=300
161+
162+[Install]
163+WantedBy=multi-user.target

Subscribers

People subscribed via source and target branches