Merge ~rharding/charm-telegraf:update-2.3 into ~telegraf-charmers/charm-telegraf:master

Proposed by Richard Harding
Status: Merged
Approved by: Haw Loeung
Approved revision: b621eee2d4324a82ab6b2958278acfb7040dfdaf
Merged at revision: 9512ea7934dba8adff992b6b74228420e3d9fce0
Proposed branch: ~rharding/charm-telegraf:update-2.3
Merge into: ~telegraf-charmers/charm-telegraf:master
Diff against target: 86 lines (+40/-33)
1 file modified
reactive/telegraf.py (+40/-33)
Reviewer Review Type Date Requested Status
Haw Loeung Approve
Review via email: mp+332427@code.launchpad.net

Description of the change

Add support for using network-get in updated charm-helpers to fetch the correct IP address to send across the relation.

Per the new upcoming documentation here:
https://jujucharms.com/docs/devel/developer-network-primitives

This allows for using cross model relations from telegraf to a centralized prometheus instance and is meant to provide an example of charms to leverage network-get to help determine if a public or private address should be sent to a related application.

QA instructions:

CMR QA - Juju 2.3beta

You need two controllers
juju bootstrap google bigbrother
juju bootstrap aws monitorme
juju switch bigbrother
juju deploy cs:~rharding/prometheus-0
juju expose prometheus
juju offer prometheus:target offerprom
juju switch monitorme
juju deploy ubuntu
juju deploy cs:~rharding/telegraf-0
juju relate ubuntu:juju-info telegraf
juju consume bigbrother:/admin/default.offerprom promed
juju relate telegraf:prometheus-client promed:target
juju switch bigbrother
juju show-machine 0
<get the public IP of prometheus and load it in the browser <ip>:9090
<open the status->targets list and make sure you see the CMR with the public IP address of the telegraf unit in AWS>

To post a comment you must log in.
Revision history for this message
Haw Loeung (hloeung) wrote :

LGTM, +1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/reactive/telegraf.py b/reactive/telegraf.py
2index 526ae97..b30bf17 100644
3--- a/reactive/telegraf.py
4+++ b/reactive/telegraf.py
5@@ -648,41 +648,48 @@ def prometheus_client(prometheus):
6 [[outputs.prometheus_client]]
7 listen = "{{ listen }}"
8 """
9- # if juju 2.x+ then we'll attempt to get the network space address
10- try:
11- ip_addr = hookenv.network_get_primary_address('prometheus-client')
12- except NotImplementedError:
13- # if that fails, just let prometheus.configure(...) do it's default
14- ip_addr = None
15- if get_prometheus_port():
16- hookenv.log("Prometheus configured globally, skipping plugin setup")
17- prometheus.configure(get_prometheus_port(),
18+ for relation_id in hookenv.relation_ids('prometheus-client'):
19+ # if juju 2.x+ then we'll attempt to get the network space address
20+ try:
21+ hookenv.log('Network Info')
22+ network_info = hookenv.network_get('prometheus-client', relation_id=relation_id)
23+ hookenv.log(network_info)
24+ if 'ingress-addresses' in network_info:
25+ ip_addr = network_info.get('ingress-addresses')[0]
26+ else:
27+ ip_addr = hookenv.network_get_primary_address('prometheus-client')
28+ except NotImplementedError:
29+ # if that fails, just let prometheus.configure(...) do it's default
30+ ip_addr = None
31+ if get_prometheus_port():
32+ hookenv.log("Prometheus configured globally, skipping plugin setup")
33+ prometheus.configure(get_prometheus_port(),
34+ hostname=ip_addr,
35+ private_address=ip_addr)
36+ # bail out, nothing more need to be configured here
37+ return
38+ port = 9126
39+ extra_options = get_extra_options()
40+ options = extra_options['outputs'].get('prometheus-client', {})
41+ listen = options.pop('listen', None)
42+ if listen is not None:
43+ hookenv.log("Configuring prometheus_client plugin to listen on: '{}'".format(listen))
44+ port = int(listen.split(":", 1)[1])
45+ else:
46+ listen = ":{}".format(port)
47+ check_prometheus_port("prometheus_output", port)
48+ prometheus.configure(port,
49 hostname=ip_addr,
50 private_address=ip_addr)
51- # bail out, nothing more need to be configured here
52- return
53- port = 9126
54- extra_options = get_extra_options()
55- options = extra_options['outputs'].get('prometheus-client', {})
56- listen = options.pop('listen', None)
57- if listen is not None:
58- hookenv.log("Configuring prometheus_client plugin to listen on: '{}'".format(listen))
59- port = int(listen.split(":", 1)[1])
60- else:
61- listen = ":{}".format(port)
62- check_prometheus_port("prometheus_output", port)
63- prometheus.configure(port,
64- hostname=ip_addr,
65- private_address=ip_addr)
66- config_path = '{}/{}.conf'.format(get_configs_dir(), 'prometheus-client')
67- hookenv.log("Updating {} plugin config file".format('prometheus-client'))
68- context = {"listen": listen}
69- content = render_template(template, context) + \
70- render_extra_options("outputs", "prometheus_client",
71- extra_options=extra_options)
72- host.write_file(config_path, content.encode('utf-8'))
73- set_state('plugins.prometheus-client.configured')
74- set_state('telegraf.needs_reload')
75+ config_path = '{}/{}.conf'.format(get_configs_dir(), 'prometheus-client')
76+ hookenv.log("Updating {} plugin config file".format('prometheus-client'))
77+ context = {"listen": listen}
78+ content = render_template(template, context) + \
79+ render_extra_options("outputs", "prometheus_client",
80+ extra_options=extra_options)
81+ host.write_file(config_path, content.encode('utf-8'))
82+ set_state('plugins.prometheus-client.configured')
83+ set_state('telegraf.needs_reload')
84
85
86 @when_not('prometheus-client.available')

Subscribers

People subscribed via source and target branches

to all changes: