From 5b9a90b65d62707202c6ae791a45dfafe127202c Mon Sep 17 00:00:00 2001 From: Tim Burke Date: Fri, 1 Oct 2021 14:35:09 -0700 Subject: [PATCH] sharder: Make stats interval configurable Change-Id: Ia794a7e21794d2c1212be0e2d163004f85c2ab78 --- etc/container-server.conf-sample | 3 +++ swift/container/sharder.py | 3 ++- test/unit/container/test_sharder.py | 9 ++++++--- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/etc/container-server.conf-sample b/etc/container-server.conf-sample index 8ae1a71db5..e1f8482c6e 100644 --- a/etc/container-server.conf-sample +++ b/etc/container-server.conf-sample @@ -491,6 +491,9 @@ use = egg:swift#xprofile # us less likely to bomb out on a LockTimeout. # broker_timeout = 60 # +# Time in seconds to wait between emitting stats to logs +# stats_interval = 3600.0 +# # Time in seconds to wait between sharder cycles # interval = 30.0 # diff --git a/swift/container/sharder.py b/swift/container/sharder.py index c4d65e9272..eeaa12f2a9 100644 --- a/swift/container/sharder.py +++ b/swift/container/sharder.py @@ -724,6 +724,7 @@ class ContainerSharder(ContainerSharderConf, ContainerReplicator): raise SystemExit( 'Unable to load internal client from config: %r (%s)' % (internal_client_conf_path, err)) + self.stats_interval = float(conf.get('stats_interval', '3600')) self.reported = 0 def _zero_stats(self): @@ -880,7 +881,7 @@ class ContainerSharder(ContainerSharderConf, ContainerReplicator): self.reported = now def _periodic_report_stats(self): - if (time.time() - self.reported) >= 3600: # once an hour + if (time.time() - self.reported) >= self.stats_interval: self._report_stats() def _check_node(self, node): diff --git a/test/unit/container/test_sharder.py b/test/unit/container/test_sharder.py index f59b6918d6..ca5f73cbb2 100644 --- a/test/unit/container/test_sharder.py +++ b/test/unit/container/test_sharder.py @@ -178,7 +178,8 @@ class TestSharder(BaseTestSharder): 'shard_replication_quorum': 2, 'existing_shard_replication_quorum': 2, 'max_shrinking': 1, - 'max_expanding': -1 + 'max_expanding': -1, + 'stats_interval': 3600, } sharder, mock_ic = self._do_test_init({}, expected, use_logger=False) self.assertEqual( @@ -228,7 +229,8 @@ class TestSharder(BaseTestSharder): 'existing_shard_replication_quorum': 0, 'max_shrinking': 5, 'max_expanding': 4, - 'rows_per_shard': 13000000 + 'rows_per_shard': 13000000, + 'stats_interval': 300, } expected = { 'mount_check': False, 'bind_ip': '10.11.12.13', 'port': 62010, @@ -253,7 +255,8 @@ class TestSharder(BaseTestSharder): 'shard_replication_quorum': 1, 'existing_shard_replication_quorum': 0, 'max_shrinking': 5, - 'max_expanding': 4 + 'max_expanding': 4, + 'stats_interval': 300, } sharder, mock_ic = self._do_test_init(conf, expected) mock_ic.assert_called_once_with(