Merge lp:~verterok/charms/trusty/haproxy/statistics-interface into lp:charms/trusty/haproxy

Proposed by Guillermo Gonzalez
Status: Merged
Merged at revision: 103
Proposed branch: lp:~verterok/charms/trusty/haproxy/statistics-interface
Merge into: lp:charms/trusty/haproxy
Diff against target: 129 lines (+85/-0)
3 files modified
hooks/hooks.py (+22/-0)
hooks/tests/test_statistics_hooks.py (+60/-0)
metadata.yaml (+3/-0)
To merge this branch: bzr merge lp:~verterok/charms/trusty/haproxy/statistics-interface
Reviewer Review Type Date Requested Status
Andrew McLeod (community) Approve
charmers Pending
Review via email: mp+288005@code.launchpad.net

Commit message

Add statistics interface and relation support.

Description of the change

Add statistics interface and relation support.

This is to share the information about the statistics/monitoring endpoint to a subordinate, for example to the telegraf subordinate in order to automatically setup a haproxy input config when telegraf and haproxy are related.

To post a comment you must log in.
Revision history for this message
Andrew McLeod (admcleod) wrote :

Hi Guillermo,

So, bundletester still passes (as expected since there are no related changes) and a 'make build' runs through and works OK...

However, I wasn't sure that was enough so I deployed this and related it to telegraf, and didn't see any hooks fired that were clearly 'statistics interface' related - I assume this is because I didn't relate them specifically enough, but would you be able to provide some instructions on how I can do this to make sure the hooks are firing correctly and successfully?

http://pastebin.ubuntu.com/15347650/

Thanks,
Andrew

review: Needs Information
Revision history for this message
Guillermo Gonzalez (verterok) wrote :

Hi Andrew,

> Hi Guillermo,
>
> So, bundletester still passes (as expected since there are no related changes)
> and a 'make build' runs through and works OK...

Thanks for looking at this.

>
> However, I wasn't sure that was enough so I deployed this and related it to
> telegraf, and didn't see any hooks fired that were clearly 'statistics
> interface' related - I assume this is because I didn't relate them
> specifically enough, but would you be able to provide some instructions on how
> I can do this to make sure the hooks are firing correctly and successfully?
>
> http://pastebin.ubuntu.com/15347650/

You'r right, there is no support for statistics interface in the telegraf charm yet, still waiting for a review on https://code.launchpad.net/~verterok/charms/trusty/telegraf/haproxy-statistics/+merge/288009
But you can test the haproxy side by using the above branch when deploying the telegraf subordinate.

The telegraf charm changes should be landed soon-ish (need to poke/chase some team mates to geta review on it)

Thanks.

Revision history for this message
Andrew McLeod (admcleod) wrote :

I've tested this MR against telegraf with the MR in your comment and it all looks good to me:

+1

review: Approve
Revision history for this message
Cory Johns (johnsca) wrote :

This has been merged and will be available in cs:trusty/haproxy shortly.

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 2016-03-03 16:47:14 +0000
3+++ hooks/hooks.py 2016-03-03 20:15:59 +0000
4@@ -1283,6 +1283,24 @@
5 os.chown(path, uid, -1)
6
7
8+def statistics_interface():
9+ config = config_get()
10+ enable_monitoring = config['enable_monitoring']
11+ monitoring_port = config['monitoring_port']
12+ monitoring_password = get_monitoring_password()
13+ monitoring_username = config['monitoring_username']
14+ for relid in get_relation_ids('statistics'):
15+ if not enable_monitoring:
16+ relation_set(relation_id=relid,
17+ enabled=enable_monitoring)
18+ else:
19+ relation_set(relation_id=relid,
20+ enabled=enable_monitoring,
21+ port=monitoring_port,
22+ password=monitoring_password,
23+ user=monitoring_username)
24+
25+
26 # #############################################################################
27 # Main section
28 # #############################################################################
29@@ -1301,6 +1319,7 @@
30 install_hook()
31 config_changed()
32 update_nrpe_config()
33+ statistics_interface()
34 if config_data.implicit_save:
35 config_data.save()
36 elif hook_name == "start":
37@@ -1326,6 +1345,9 @@
38 elif hook_name in ("nrpe-external-master-relation-joined",
39 "local-monitors-relation-joined"):
40 update_nrpe_config()
41+ elif hook_name in ("statistics-relation-joined",
42+ "statistics-relation-changed"):
43+ statistics_interface()
44 else:
45 print "Unknown hook"
46 sys.exit(1)
47
48=== added symlink 'hooks/statistics-relation-changed'
49=== target is u'hooks.py'
50=== added symlink 'hooks/statistics-relation-joined'
51=== target is u'hooks.py'
52=== added file 'hooks/tests/test_statistics_hooks.py'
53--- hooks/tests/test_statistics_hooks.py 1970-01-01 00:00:00 +0000
54+++ hooks/tests/test_statistics_hooks.py 2016-03-03 20:15:59 +0000
55@@ -0,0 +1,60 @@
56+
57+from testtools import TestCase
58+from mock import patch
59+from charmhelpers.core.hookenv import Config
60+
61+import hooks
62+
63+
64+class StatisticsRelationTest(TestCase):
65+
66+ def setUp(self):
67+ super(StatisticsRelationTest, self).setUp()
68+ config = Config(**{"monitoring_port": 10001,
69+ "monitoring_username": "mon_user",
70+ "enable_monitoring": True})
71+ self.config_get = self.patch_hook("config_get")
72+ self.config_get.return_value = config
73+ # patch changed and save methods to do nothing
74+ self.config_get().changed = lambda x: False
75+ self.config_get().save = lambda: None
76+ self.get_monitoring_password = \
77+ self.patch_hook("get_monitoring_password")
78+ self.get_monitoring_password.return_value = "this-is-a-secret"
79+ self.relation_set = self.patch_hook("relation_set")
80+ self.get_relation_ids = self.patch_hook("get_relation_ids")
81+ self.get_relation_ids.return_value = ['__stats-rel-id__']
82+ self.log = self.patch_hook("log")
83+
84+ def patch_hook(self, hook_name):
85+ mock_controller = patch.object(hooks, hook_name)
86+ mock = mock_controller.start()
87+ self.addCleanup(mock_controller.stop)
88+ return mock
89+
90+ def test_relation_joined(self):
91+ hooks.statistics_interface()
92+ self.get_relation_ids.assert_called_once_with('statistics')
93+ self.relation_set.assert_called_once_with(
94+ relation_id=self.get_relation_ids()[0],
95+ enabled=True,
96+ port=10001,
97+ password="this-is-a-secret",
98+ user="mon_user")
99+
100+ def test_relation_joined_monitoring_disabled(self):
101+ self.config_get.return_value['enable_monitoring'] = False
102+ hooks.statistics_interface()
103+ self.get_relation_ids.assert_called_once_with('statistics')
104+ self.relation_set.assert_called_once_with(
105+ relation_id=self.get_relation_ids()[0],
106+ enabled=False)
107+
108+ def test_called_on_config_change(self):
109+ config_changed = self.patch_hook('config_changed')
110+ update_nrpe_config = self.patch_hook('update_nrpe_config')
111+ statistics_interface = self.patch_hook('statistics_interface')
112+ hooks.main('config-changed')
113+ config_changed.assert_called_once_with()
114+ update_nrpe_config.assert_called_once_with()
115+ statistics_interface.assert_called_once_with()
116
117=== modified file 'metadata.yaml'
118--- metadata.yaml 2015-05-15 16:54:14 +0000
119+++ metadata.yaml 2016-03-03 20:15:59 +0000
120@@ -22,6 +22,9 @@
121 local-monitors:
122 interface: local-monitors
123 scope: container
124+ statistics:
125+ interface: statistics
126+ scope: container
127 peers:
128 peer:
129 interface: haproxy-peer

Subscribers

People subscribed via source and target branches

to all changes: