diff options
author | Zuul <zuul@review.opendev.org> | 2022-09-24 12:12:09 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2022-09-24 12:12:09 +0000 |
commit | 9cd3a05798d99d5f58e142616af601918ca2cb74 (patch) | |
tree | 83f0f24850390e9337cc4642b30d9492be1e31dd | |
parent | 260d6ec8ddf982566e6833e3993685a9a507e0f8 (diff) | |
parent | d0ade7e48c0f3da88e8e90aa1ff54dbd3d8efc12 (diff) | |
download | neutron-9cd3a05798d99d5f58e142616af601918ca2cb74.tar.gz |
Merge "[OVN] Rate limit the "Disallow caching" log from hash ring" into stable/ussuri
-rw-r--r-- | neutron/common/ovn/hash_ring_manager.py | 15 | ||||
-rw-r--r-- | neutron/tests/unit/common/ovn/test_hash_ring_manager.py | 11 |
2 files changed, 22 insertions, 4 deletions
diff --git a/neutron/common/ovn/hash_ring_manager.py b/neutron/common/ovn/hash_ring_manager.py index c27f3ae936..f746d3effd 100644 --- a/neutron/common/ovn/hash_ring_manager.py +++ b/neutron/common/ovn/hash_ring_manager.py @@ -36,6 +36,8 @@ class HashRingManager(object): self._last_time_loaded = None self._check_hashring_startup = True self._group = group_name + # Flag to rate limit the caching log + self._prev_num_nodes = -1 self.admin_ctx = context.get_admin_context() @property @@ -57,11 +59,18 @@ class HashRingManager(object): self.admin_ctx, constants.HASH_RING_CACHE_TIMEOUT, self._group, from_host=True) - if len(nodes) >= api_workers: - LOG.debug("Allow caching, nodes %s>=%s", len(nodes), api_workers) + num_nodes = len(nodes) + if num_nodes >= api_workers: + LOG.debug("Allow caching, nodes %s>=%s", num_nodes, api_workers) self._check_hashring_startup = False return False - LOG.debug("Disallow caching, nodes %s<%s", len(nodes), api_workers) + + # NOTE(lucasagomes): We only log when the number of connected + # nodes are different to prevent this message from being spammed + if self._prev_num_nodes != num_nodes: + LOG.debug("Disallow caching, nodes %s<%s", num_nodes, api_workers) + self._prev_num_nodes = num_nodes + return True def _load_hash_ring(self, refresh=False): diff --git a/neutron/tests/unit/common/ovn/test_hash_ring_manager.py b/neutron/tests/unit/common/ovn/test_hash_ring_manager.py index d3a2c41a9b..3c67b72686 100644 --- a/neutron/tests/unit/common/ovn/test_hash_ring_manager.py +++ b/neutron/tests/unit/common/ovn/test_hash_ring_manager.py @@ -110,14 +110,23 @@ class TestHashRingManager(testlib_api.SqlTestCaseLight): # The ring should re-balance and as it was before self._verify_hashes(hash_dict_before) + @mock.patch.object(hash_ring_manager.LOG, 'debug') @mock.patch.object(service, '_get_api_workers', return_value=2) - def test__wait_startup_before_caching(self, api_workers): + def test__wait_startup_before_caching(self, api_workers, mock_log): db_hash_ring.add_node(self.admin_ctx, HASH_RING_TEST_GROUP, 'node-1') # Assert it will return True until until we equal api_workers self.assertTrue(self.hash_ring_manager._wait_startup_before_caching) self.assertTrue(self.hash_ring_manager._check_hashring_startup) + # Call it again with the same number of workers to test the + # log rating + self.assertTrue(self.hash_ring_manager._wait_startup_before_caching) + self.assertTrue(self.hash_ring_manager._check_hashring_startup) + + # Assert the cache message has been logged only once + self.assertEqual(1, mock_log.call_count) + db_hash_ring.add_node(self.admin_ctx, HASH_RING_TEST_GROUP, 'node-2') # Assert it's now False. Waiting is not needed anymore |