Merge ~vultaire/charm-nagios:remove-legacy-deduping into charm-nagios:master

Proposed by Paul Goins
Status: Merged
Merged at revision: 1425e19f775dfcdad94518e79848f5fa88d29e37
Proposed branch: ~vultaire/charm-nagios:remove-legacy-deduping
Merge into: charm-nagios:master
Prerequisite: ~vultaire/charm-nagios:speed-optimizations
Diff against target: 178 lines (+4/-58)
4 files modified
hooks/common.py (+1/-8)
hooks/monitors_relation_changed.py (+2/-23)
tests/unit/test_common.py (+1/-13)
tests/unit/test_monitor_relation_changed.py (+0/-14)
Reviewer Review Type Date Requested Status
Garrett Neugent (community) Approve
Xav Paice (community) Approve
🤖 prod-jenkaas-bootstack (community) continuous-integration Approve
BootStack Reviewers Pending
Review via email: mp+407756@code.launchpad.net

Commit message

Removed fallback deduping methodology

On reflection, I don't believe this provided much benefit. The needed
updates to charm-nrpe were provided at nearly the same time as
charm-nagios to support the main deduping methodology. Rather than
maintaining 2 methods, we should probably maintain just one.

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
🤖 prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote :

A CI job is currently in progress. A follow up comment will be added when it completes.

Revision history for this message
🤖 prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
🤖 prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote :

A CI job is currently in progress. A follow up comment will be added when it completes.

Revision history for this message
🤖 prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Paul Goins (vultaire) wrote :

Tested in my test environment where I had both "legacy" and model UUID SHA-based prefixes in play.

Upon charm upgrade, the config got rewritten, with the hosts with the "legacy" prefix dropping the prefix and instead simply using the original hostname. The hosts with the model-id present on the relation are continuing to use the prefix. In other words, this is working exactly as I expect.

The test failures here were some sort of CI timeout; I've kicked off a rebuild.

Revision history for this message
🤖 prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
🤖 prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
🤖 prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote :
review: Approve (continuous-integration)
Revision history for this message
Xav Paice (xavpaice) wrote :

LGTM, tests OK

review: Approve
Revision history for this message
Xav Paice (xavpaice) wrote :

With this change, I've got two bundles in two models, and a cross model relation, see https://pastebin.canonical.com/p/vZ26FkpRK6/ for the detail.

The Nagios host is now monitoring rabbit and ubuntu on one host, machine 1 in the 'nagios' model, and because I'm using unit for the hostname type, I see two machines defined in Nagios. That's expected, I'd have to set `nagios_hostname_type=host` in nrpe to fix that.

The Nagios host also monitors two machines, separate, named `juju-ubuntu-0`. I only see one in the Nagios host definitions, which is from the model 'notnagios'. The unit `rabbitmq-server-0` covers monitoring for the machine in the `nagios` model (I'm regretting these names now).

I don't know, at this stage, if the host names should have a prefix of some description, and when I look at host `juju-ubuntu-0` I don't know which it is unless I look at it's IP address.

When running this same test from HEAD at 29dce00c69f68ac3d1e14af2e450e96ca4603021 (current master), I get a list of hosts including all and the duplicates have a relation prefix to split them out.

review: Needs Fixing
Revision history for this message
Paul Goins (vultaire) wrote :

The intent here is to eliminate the "fallback" deduping strategy.

Based on the model from your pastebin, the NRPE apps in use are from the present nrpe release (cs:nrpe rather than the llama-charmers-next version), so they lack the model-id field in their relation data. After this change, I would expect that only one shows up, because they would not be de-duped. This is intentional as I wish to remove this particular fallback methodology for the sake of having less code to maintain; its benefit in being left in the code is really quite minimal.

If you do a "juju upgrade-charm -m <model> nrpe --switch cs:~llama-charmers-next/nrpe" on each of the nrpe apps in your model, you'll see that the deduplication logic will work, since that version of charm-nrpe has the needed model-id in the relation data.

Revision history for this message
Xav Paice (xavpaice) wrote :

Discussed this change on Mattermost. The change requires changes in NRPE that are not yet released, but will be included in 21.10. Tested again with that NRPE, and this change works well.

review: Approve
Revision history for this message
Garrett Neugent (thogarre) wrote :

LGTM as well.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/hooks/common.py b/hooks/common.py
2index f4e5443..adc77b7 100644
3--- a/hooks/common.py
4+++ b/hooks/common.py
5@@ -14,8 +14,6 @@ from charmhelpers.core.hookenv import (
6 network_get,
7 network_get_primary_address,
8 relation_get,
9- relation_id,
10- remote_unit,
11 unit_get,
12 )
13
14@@ -502,17 +500,12 @@ def _get_minimal_related_config_paths():
15 # duplicate host names from different models.
16 # Case 1: Direct match
17 paths_to_remove.append(template.format(target_name))
18- # Case 2: Deduped match, main algorithm, glob on first 7 chars of sha256sum
19+ # Case 2: Deduped match, glob on first 7 chars of sha256sum
20 if MODEL_ID_KEY in relation_data:
21 model_id = relation_data[MODEL_ID_KEY]
22 sha_prefix = get_model_id_sha(model_id)[:HOST_PREFIX_MIN_LENGTH]
23 glob_pattern = template.format("{}*_{}".format(sha_prefix, target_name))
24 paths_to_remove.extend(glob.glob(glob_pattern))
25- # Case 3: Deduped match, fallback algorithm
26- relid_unit_prefix = get_relid_unit_prefix(relation_id(), remote_unit())
27- paths_to_remove.append(
28- template.format("{}_{}".format(relid_unit_prefix, target_name))
29- )
30 return paths_to_remove
31
32
33diff --git a/hooks/monitors_relation_changed.py b/hooks/monitors_relation_changed.py
34index a6f66b2..2a201c6 100755
35--- a/hooks/monitors_relation_changed.py
36+++ b/hooks/monitors_relation_changed.py
37@@ -48,7 +48,6 @@ from common import (
38 get_nagios_host_config_path,
39 get_pynag_host,
40 get_pynag_service,
41- get_relid_unit_prefix,
42 initialize_inprogress_config,
43 refresh_hostgroups,
44 )
45@@ -92,11 +91,6 @@ def _prepare_relation_data(unit, rid):
46
47 return {}
48
49- relation_data["metadata"] = {
50- "unit": unit,
51- "rid": rid,
52- }
53-
54 return relation_data
55
56
57@@ -168,12 +162,9 @@ def main(argv, full_rewrite=False): # noqa: C901
58 for target_id, relation_settings_list in hosts_to_settings.items():
59 for relation_settings in relation_settings_list:
60 model_id = relation_settings.get(MODEL_ID_KEY)
61- if len(relation_settings_list) > 1:
62+ if model_id and len(relation_settings_list) > 1:
63 duplicate_hostnames.add(target_id)
64- if model_id:
65- unique_prefix = host_prefixes[model_id]
66- else:
67- unique_prefix = compute_fallback_host_prefix(relation_settings)
68+ unique_prefix = host_prefixes[model_id]
69 relation_settings[TARGET_ID_KEY] = "{}_{}".format(
70 unique_prefix, target_id
71 )
72@@ -263,18 +254,6 @@ def compute_host_prefixes(model_ids):
73 return result
74
75
76-def compute_fallback_host_prefix(relation_settings):
77- """Compute short unique identifiers, fallback method.
78-
79- This method uses the relation ID (e.g. monitors:1), in conjunction with the remote
80- unit ID as seen via the relation (e.g. app/1 or
81- remote-0123456789abcdef0123456789abcdef/1), to create a unique identifier.
82- """
83- return get_relid_unit_prefix(
84- relation_settings["metadata"]["rid"], relation_settings["metadata"]["unit"]
85- )
86-
87-
88 def apply_relation_config(relid, units, all_hosts): # noqa: C901
89 for unit, relation_settings in units.iteritems():
90 target_id = relation_settings[TARGET_ID_KEY]
91diff --git a/tests/unit/test_common.py b/tests/unit/test_common.py
92index 91bb4cf..c386865 100644
93--- a/tests/unit/test_common.py
94+++ b/tests/unit/test_common.py
95@@ -57,11 +57,9 @@ class TestInitializeInprogressConfigFileCleanup:
96 rget_mock.return_value = None
97 self._run_test(existing_files, expected_files_to_delete)
98
99- @patch("common.remote_unit")
100- @patch("common.relation_id")
101 @patch("common.get_model_id_sha")
102 @patch("common.relation_get")
103- def test_with_related_unit(self, rget_mock, sha_mock, rid_mock, runit_mock, tmpdir):
104+ def test_with_related_unit(self, rget_mock, sha_mock, tmpdir):
105 """Related unit case.
106
107 If there is a related unit, we should remove:
108@@ -82,36 +80,26 @@ class TestInitializeInprogressConfigFileCleanup:
109 common.OLD_CHARM_CFG,
110 common.HOST_TEMPLATE.format("host-1"),
111 common.HOST_TEMPLATE.format("host-2"),
112- common.HOST_TEMPLATE.format("monitors:42_7_host-2"),
113 common.HOST_TEMPLATE.format("fakesha_host-2"),
114 common.HOST_TEMPLATE.format("host-3"),
115- common.HOST_TEMPLATE.format("monitors:42_8_host-3"),
116 common.HOST_TEMPLATE.format("fakesha_host-3"),
117 common.HOSTGROUP_TEMPLATE.format("host"),
118- common.HOSTGROUP_TEMPLATE.format("monitors:42_7_host"),
119- common.HOSTGROUP_TEMPLATE.format("monitors:42_8_host"),
120 common.HOSTGROUP_TEMPLATE.format("fakesha_host"),
121 ]
122 expected_files_to_delete = [
123 common.OLD_CHARM_CFG,
124 common.HOST_TEMPLATE.format("host-2"),
125- common.HOST_TEMPLATE.format("monitors:42_7_host-2"),
126 common.HOST_TEMPLATE.format("fakesha_host-2"),
127 common.HOSTGROUP_TEMPLATE.format("host"),
128- common.HOSTGROUP_TEMPLATE.format("monitors:42_7_host"),
129 common.HOSTGROUP_TEMPLATE.format("fakesha_host"),
130 ]
131 fake_sha = "fakesha"
132- fake_relation_id = "monitors:42"
133- fake_remote_unit = "foo/7"
134
135 rget_mock.return_value = {
136 common.TARGET_ID_KEY: related_unit_hostname,
137 common.MODEL_ID_KEY: "fake",
138 }
139 sha_mock.return_value = fake_sha
140- rid_mock.return_value = fake_relation_id
141- runit_mock.return_value = fake_remote_unit
142 self._run_test(existing_files, expected_files_to_delete)
143
144 def _run_test(self, existing_files, expected_files_to_delete):
145diff --git a/tests/unit/test_monitor_relation_changed.py b/tests/unit/test_monitor_relation_changed.py
146index 09c0bc1..8578af2 100644
147--- a/tests/unit/test_monitor_relation_changed.py
148+++ b/tests/unit/test_monitor_relation_changed.py
149@@ -72,18 +72,6 @@ class TestComputeHostPrefixes:
150 assert prefixes == expected_result
151
152
153-def test_compute_fallback_host_prefix():
154- prefix = monitors_relation_changed.compute_fallback_host_prefix(
155- {
156- "metadata": {
157- "rid": "monitors:1",
158- "unit": "remote-0123456789abcdef0123456789abcdef/1",
159- }
160- }
161- )
162- assert prefix == "monitors:1_1"
163-
164-
165 class TestCleanupLeftoverHosts:
166 def test_cleanup_leftover_hosts(self, tmpdir):
167 mock_host_template = "{}/juju-host_{{}}.cfg".format(tmpdir)
168@@ -94,11 +82,9 @@ class TestCleanupLeftoverHosts:
169 ) as _2: # noqa: F841
170 existing_files = [
171 monitors_relation_changed.HOST_TEMPLATE.format("host-2"),
172- monitors_relation_changed.HOST_TEMPLATE.format("monitors:42_7_host-2"),
173 monitors_relation_changed.HOST_TEMPLATE.format("fakesha_host-2"),
174 ]
175 expected_files_to_delete = [
176- monitors_relation_changed.HOST_TEMPLATE.format("monitors:42_7_host-2"),
177 monitors_relation_changed.HOST_TEMPLATE.format("fakesha_host-2"),
178 ]
179

Subscribers

People subscribed via source and target branches

to all changes: