Merge ~aluria/charm-prometheus-ceph-exporter:lp1743763 into ~prometheus-charmers/charm-prometheus-ceph-exporter/+git/prometheus-ceph-exporter-charm:master

Proposed by Alvaro Uria
Status: Merged
Merged at revision: 874d889bd8889291631d48604dfa34ced18dea70
Proposed branch: ~aluria/charm-prometheus-ceph-exporter:lp1743763
Merge into: ~prometheus-charmers/charm-prometheus-ceph-exporter/+git/prometheus-ceph-exporter-charm:master
Diff against target: 71 lines (+39/-1)
2 files modified
config.yaml (+7/-0)
reactive/prometheus-ceph-exporter.py (+32/-1)
Reviewer Review Type Date Requested Status
Drew Freiberger (community) Approve
Review via email: mp+336219@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Drew Freiberger (afreiberger) wrote :

lgtm

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/config.yaml b/config.yaml
2index afca810..735208e 100644
3--- a/config.yaml
4+++ b/config.yaml
5@@ -1,4 +1,11 @@
6 options:
7+ access-network:
8+ type: string
9+ default:
10+ description: |
11+ The IP address and netmask of the 'access' network (e.g. 192.168.0.0/24)
12+ .
13+ This network will be used for access to the ceph-exporter metrics.
14 username:
15 description: Username to use for ceph mons - defaults to prometheus-ceph-exporter.
16 type: string
17diff --git a/reactive/prometheus-ceph-exporter.py b/reactive/prometheus-ceph-exporter.py
18index 91de7cc..61de4e3 100644
19--- a/reactive/prometheus-ceph-exporter.py
20+++ b/reactive/prometheus-ceph-exporter.py
21@@ -22,6 +22,7 @@ from charms.reactive import (
22 )
23 from charms.reactive.helpers import any_file_changed, data_changed
24 from charmhelpers.contrib.charmsupport import nrpe
25+from charmhelpers.contrib.network.ip import get_address_in_network
26 # from charms.layer import snap
27
28 from charmhelpers.fetch import (
29@@ -117,11 +118,41 @@ def restart_ceph_exporter():
30 remove_state('ceph-exporter.do-restart')
31
32
33+def get_exporter_host(interface='ceph-exporter'):
34+ """Get address of local ceph-exporter host for use by http clients
35+
36+ If an access-network has been configured, expect selected address to be on
37+ that network. If none can be found, revert to primary address.
38+
39+ If network spaces (Juju >= 2.0) are supported, use network-get to retrieve
40+ the network binding for the interface
41+
42+ @param interface: Network space binding to check
43+ Usually the relationship name
44+ @returns IP for use with http clients
45+ """
46+ access_network = hookenv.config('access-network')
47+ if access_network:
48+ return get_address_in_network(access_network)
49+ else:
50+ try:
51+ # NOTE(aluria)
52+ # Try to use network spaces to resolve binding for interface, and
53+ # to resolve the IP
54+ return hookenv.network_get_primary_address(interface)
55+ except NotImplementedError:
56+ # NOTE(aluria): skip - fallback to previous behaviour (in OS Charms)
57+ pass
58+
59+ return hookenv.unit_get('private-address')
60+
61+
62 # Relations
63 @when('ceph-exporter.started')
64 @when('ceph-exporter.available') # Relation name is "ceph-exporter"
65 def configure_ceph_exporter_relation(target):
66- target.configure(PORT_DEF)
67+ hostname = get_exporter_host()
68+ target.configure(PORT_DEF, hostname=hostname)
69
70
71 @when('nrpe-external-master.available')

Subscribers

People subscribed via source and target branches