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
diff --git a/config.yaml b/config.yaml
index afca810..735208e 100644
--- a/config.yaml
+++ b/config.yaml
@@ -1,4 +1,11 @@
1options:1options:
2 access-network:
3 type: string
4 default:
5 description: |
6 The IP address and netmask of the 'access' network (e.g. 192.168.0.0/24)
7 .
8 This network will be used for access to the ceph-exporter metrics.
2 username:9 username:
3 description: Username to use for ceph mons - defaults to prometheus-ceph-exporter.10 description: Username to use for ceph mons - defaults to prometheus-ceph-exporter.
4 type: string11 type: string
diff --git a/reactive/prometheus-ceph-exporter.py b/reactive/prometheus-ceph-exporter.py
index 91de7cc..61de4e3 100644
--- a/reactive/prometheus-ceph-exporter.py
+++ b/reactive/prometheus-ceph-exporter.py
@@ -22,6 +22,7 @@ from charms.reactive import (
22)22)
23from charms.reactive.helpers import any_file_changed, data_changed23from charms.reactive.helpers import any_file_changed, data_changed
24from charmhelpers.contrib.charmsupport import nrpe24from charmhelpers.contrib.charmsupport import nrpe
25from charmhelpers.contrib.network.ip import get_address_in_network
25# from charms.layer import snap26# from charms.layer import snap
2627
27from charmhelpers.fetch import (28from charmhelpers.fetch import (
@@ -117,11 +118,41 @@ def restart_ceph_exporter():
117 remove_state('ceph-exporter.do-restart')118 remove_state('ceph-exporter.do-restart')
118119
119120
121def get_exporter_host(interface='ceph-exporter'):
122 """Get address of local ceph-exporter host for use by http clients
123
124 If an access-network has been configured, expect selected address to be on
125 that network. If none can be found, revert to primary address.
126
127 If network spaces (Juju >= 2.0) are supported, use network-get to retrieve
128 the network binding for the interface
129
130 @param interface: Network space binding to check
131 Usually the relationship name
132 @returns IP for use with http clients
133 """
134 access_network = hookenv.config('access-network')
135 if access_network:
136 return get_address_in_network(access_network)
137 else:
138 try:
139 # NOTE(aluria)
140 # Try to use network spaces to resolve binding for interface, and
141 # to resolve the IP
142 return hookenv.network_get_primary_address(interface)
143 except NotImplementedError:
144 # NOTE(aluria): skip - fallback to previous behaviour (in OS Charms)
145 pass
146
147 return hookenv.unit_get('private-address')
148
149
120# Relations150# Relations
121@when('ceph-exporter.started')151@when('ceph-exporter.started')
122@when('ceph-exporter.available') # Relation name is "ceph-exporter"152@when('ceph-exporter.available') # Relation name is "ceph-exporter"
123def configure_ceph_exporter_relation(target):153def configure_ceph_exporter_relation(target):
124 target.configure(PORT_DEF)154 hostname = get_exporter_host()
155 target.configure(PORT_DEF, hostname=hostname)
125156
126157
127@when('nrpe-external-master.available')158@when('nrpe-external-master.available')

Subscribers

People subscribed via source and target branches