Merge lp:~cjwatson/charm-haproxy/listener-address-localhost into lp:charm-haproxy

Proposed by Colin Watson
Status: Merged
Approved by: Tom Haddon
Approved revision: 162
Merged at revision: 162
Proposed branch: lp:~cjwatson/charm-haproxy/listener-address-localhost
Merge into: lp:charm-haproxy
Diff against target: 65 lines (+17/-14)
2 files modified
hooks/hooks.py (+7/-9)
hooks/tests/test_statistics_hooks.py (+10/-5)
To merge this branch: bzr merge lp:~cjwatson/charm-haproxy/listener-address-localhost
Reviewer Review Type Date Requested Status
Tom Haddon Approve
Arturo Enrique Seijas Fernández (community) Approve
Canonical IS Reviewers Pending
Review via email: mp+449723@code.launchpad.net

Commit message

Set statistics listener-address to 127.0.0.1.

Description of the change

If `listener-address` isn't set on the relation, the telegraf charm defaults to using the unit's `private-address`; but `monitoring_allowed_cidr` defaults to `127.0.0.1/32`, so if telegraf tries to talk to haproxy on the unit's private address then it will get a 403 error unless `monitoring_allowed_cidr` has been specifically configured to allow the unit's private address. Doing that is inconvenient in bundles that are to be deployed in multiple network environments.

The statistics relation has `scope: container`, so the other end of it is always going to be on the same machine, and it makes sense to just advertise 127.0.0.1. This matches the behaviour of the content-cache charm.

To post a comment you must log in.
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

This merge proposal is being monitored by mergebot. Change the status to Approved to merge.

Revision history for this message
Arturo Enrique Seijas Fernández (arturo-seijas) wrote :

LGTM

review: Approve
Revision history for this message
Tom Haddon (mthaddon) wrote :

LGTM, thx

review: Approve
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

Change successfully merged at revision 162

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'hooks/hooks.py'
2--- hooks/hooks.py 2023-08-09 07:20:52 +0000
3+++ hooks/hooks.py 2023-08-23 11:47:55 +0000
4@@ -1454,15 +1454,13 @@
5 monitoring_password = get_monitoring_password()
6 monitoring_username = config['monitoring_username']
7 for relid in get_relation_ids('statistics'):
8- if not enable_monitoring:
9- relation_set(relation_id=relid,
10- enabled=enable_monitoring)
11- else:
12- relation_set(relation_id=relid,
13- enabled=enable_monitoring,
14- port=monitoring_port,
15- password=monitoring_password,
16- user=monitoring_username)
17+ relation_settings = {'enabled': enable_monitoring}
18+ if enable_monitoring:
19+ relation_settings['listener-address'] = '127.0.0.1'
20+ relation_settings['port'] = monitoring_port
21+ relation_settings['password'] = monitoring_password
22+ relation_settings['user'] = monitoring_username
23+ relation_set(relation_id=relid, relation_settings=relation_settings)
24
25
26 def configure_logrotate(logrotate_config):
27
28=== modified file 'hooks/tests/test_statistics_hooks.py'
29--- hooks/tests/test_statistics_hooks.py 2016-03-03 20:14:22 +0000
30+++ hooks/tests/test_statistics_hooks.py 2023-08-23 11:47:55 +0000
31@@ -37,10 +37,13 @@
32 self.get_relation_ids.assert_called_once_with('statistics')
33 self.relation_set.assert_called_once_with(
34 relation_id=self.get_relation_ids()[0],
35- enabled=True,
36- port=10001,
37- password="this-is-a-secret",
38- user="mon_user")
39+ relation_settings={
40+ 'enabled': True,
41+ 'listener-address': '127.0.0.1',
42+ 'port': 10001,
43+ 'password': "this-is-a-secret",
44+ 'user': "mon_user",
45+ })
46
47 def test_relation_joined_monitoring_disabled(self):
48 self.config_get.return_value['enable_monitoring'] = False
49@@ -48,13 +51,15 @@
50 self.get_relation_ids.assert_called_once_with('statistics')
51 self.relation_set.assert_called_once_with(
52 relation_id=self.get_relation_ids()[0],
53- enabled=False)
54+ relation_settings={'enabled': False})
55
56 def test_called_on_config_change(self):
57 config_changed = self.patch_hook('config_changed')
58 update_nrpe_config = self.patch_hook('update_nrpe_config')
59 statistics_interface = self.patch_hook('statistics_interface')
60+ assess_status = self.patch_hook('assess_status')
61 hooks.main('config-changed')
62 config_changed.assert_called_once_with()
63 update_nrpe_config.assert_called_once_with()
64 statistics_interface.assert_called_once_with()
65+ assess_status.assert_called_once_with()

Subscribers

People subscribed via source and target branches

to all changes: