From: Naoki Kambe Date: Wed, 7 Aug 2013 06:25:15 +0000 (+0900) Subject: [2883] remove _statistics class attribute X-Git-Tag: bind10-1.2.0beta1-release~236^2~12 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e3dec9b39035a59bbdb561c12817872d66f34fbd;p=thirdparty%2Fkea.git [2883] remove _statistics class attribute and define statistics data and spec inside instance scope --- diff --git a/src/lib/python/isc/statistics/counters.py b/src/lib/python/isc/statistics/counters.py index 87355be070..4476442260 100644 --- a/src/lib/python/isc/statistics/counters.py +++ b/src/lib/python/isc/statistics/counters.py @@ -151,15 +151,6 @@ def _concat(*args, sep='/'): """ return sep.join(args) -class _Statistics(): - """Statistics data set. This class will be remove in the future - release.""" - # default statistics data - _data = {} - # default statistics spec used in case the specfile is omitted when - # constructing a Counters() object - _spec = [] - class Counters(): """A class for holding and manipulating all statistics counters for a module. A Counters object may be created by specifying a spec @@ -174,9 +165,6 @@ class Counters(): timers can be temporarily disabled. If disabled, counter values are not changed even if methods to update them are invoked.""" - # default statistics data set - _statistics = _Statistics() - def __init__(self, spec_file_name=None): """A constructor for the Counters class. A path to the spec file can be specified in spec_file_name. Statistics data based on @@ -190,16 +178,18 @@ class Counters(): self._start_time = {} self._disabled = False self._rlock = threading.RLock() + self._statistics_data = {} + self._statistics_spec = [] if not spec_file_name: return # change the default statistics spec - self._statistics._spec = \ + self._statistics_spec = \ isc.config.module_spec_from_file(spec_file_name).\ get_statistics_spec() def clear_all(self): """clears all statistics data""" with self._rlock: - self._statistics._data = {} + self._statistics_data = {} def disable(self): """disables incrementing/decrementing counters""" @@ -219,8 +209,8 @@ class Counters(): identifier = _concat(*args) with self._rlock: if self._disabled: return - _inc_counter(self._statistics._data, - self._statistics._spec, + _inc_counter(self._statistics_data, + self._statistics_spec, identifier, step) def inc(self, *args): @@ -240,7 +230,7 @@ class Counters(): of the specified counter. isc.cc.data.DataNotFoundError is raised when the counter doesn't have a number yet.""" identifier = _concat(*args) - return _get_counter(self._statistics._data, identifier) + return _get_counter(self._statistics_data, identifier) def start_timer(self, *args): """Starts a timer which is identified by args and keeps it @@ -271,8 +261,8 @@ class Counters(): # set the end time _stop_timer( start_time, - self._statistics._data, - self._statistics._spec, + self._statistics_data, + self._statistics_spec, identifier) # A datetime value of once used timer should be deleted # for a future use. @@ -293,5 +283,5 @@ class Counters(): stats module, including each counter. If nothing is counted yet, then it returns an empty dictionary.""" # entire copy - statistics_data = self._statistics._data.copy() + statistics_data = self._statistics_data.copy() return statistics_data diff --git a/src/lib/python/isc/statistics/dns.py b/src/lib/python/isc/statistics/dns.py index c224687e8a..e563d9937e 100644 --- a/src/lib/python/isc/statistics/dns.py +++ b/src/lib/python/isc/statistics/dns.py @@ -69,63 +69,6 @@ documentation for isc.statistics.counters for details.""" import isc.config from isc.statistics import counters -class _Statistics(): - """Statistics data set. This class will be removed in the future - release.""" - # default statistics data - _data = {} - # default statistics spec used in case the specfile is omitted when - # constructing a Counters() object - _spec = [ - { - "item_name": "zones", - "item_type": "named_set", - "item_optional": False, - "item_default": { - "_SERVER_" : { - "notifyoutv4" : 0, - "notifyoutv6" : 0 - } - }, - "item_title": "Zone names", - "item_description": "Zone names", - "named_set_item_spec": { - "item_name": "classname", - "item_type": "named_set", - "item_optional": False, - "item_default": {}, - "item_title": "RR class name", - "item_description": "RR class name", - "named_set_item_spec": { - "item_name": "zonename", - "item_type": "map", - "item_optional": False, - "item_default": {}, - "item_title": "Zone name", - "item_description": "Zone name", - "map_item_spec": [ - { - "item_name": "notifyoutv4", - "item_type": "integer", - "item_optional": False, - "item_default": 0, - "item_title": "IPv4 notifies", - "item_description": "Number of IPv4 notifies per zone name sent out" - }, - { - "item_name": "notifyoutv6", - "item_type": "integer", - "item_optional": False, - "item_default": 0, - "item_title": "IPv6 notifies", - "item_description": "Number of IPv6 notifies per zone name sent out" - } - ] - } - } - } - ] - class Counters(counters.Counters): """A list of counters which can be handled in the class are like the following. Also see documentation for @@ -176,8 +119,6 @@ class Counters(counters.Counters): _entire_server = '_SERVER_' # zone names are contained under this dirname in the spec file. _perzone_prefix = 'zones' - # default statistics data set - _statistics = _Statistics() def __init__(self, spec_file_name=None): """If the item `zones` is defined in the spec file, it obtains a @@ -186,10 +127,10 @@ class Counters(counters.Counters): isc.statistics.counters.Counters.__init__()""" counters.Counters.__init__(self, spec_file_name) if self._perzone_prefix in \ - isc.config.spec_name_list(self._statistics._spec): + isc.config.spec_name_list(self._statistics_spec): self._zones_item_list = isc.config.spec_name_list( isc.config.find_spec_part( - self._statistics._spec, + self._statistics_spec, '%s/%s/%s' % (self._perzone_prefix, '_CLASS_', self._entire_server))) @@ -199,7 +140,7 @@ class Counters(counters.Counters): counter. If nothing is counted yet, then it returns an empty dictionary.""" # entire copy - statistics_data = self._statistics._data.copy() + statistics_data = self._statistics_data.copy() # If there is no 'zones' found in statistics_data, # i.e. statistics_data contains no per-zone counter, it just # returns statistics_data because calculating total counts @@ -208,7 +149,7 @@ class Counters(counters.Counters): return statistics_data zones = statistics_data[self._perzone_prefix] # Start calculation for '_SERVER_' counts - zones_spec = isc.config.find_spec_part(self._statistics._spec, + zones_spec = isc.config.find_spec_part(self._statistics_spec, self._perzone_prefix) zones_data = {} for cls in zones.keys(): diff --git a/src/lib/python/isc/statistics/tests/counters_test.py b/src/lib/python/isc/statistics/tests/counters_test.py index 6b9dd8e5d9..75905e44ff 100644 --- a/src/lib/python/isc/statistics/tests/counters_test.py +++ b/src/lib/python/isc/statistics/tests/counters_test.py @@ -131,15 +131,15 @@ class TestBasicMethods(unittest.TestCase): start_functor(concurrency, number, self.counters.inc, counter_name) counters._stop_timer(start_time, - self.counters._statistics._data, - self.counters._statistics._spec, + self.counters._statistics_data, + self.counters._statistics_spec, timer_name) self.assertEqual( - counters._get_counter(self.counters._statistics._data, + counters._get_counter(self.counters._statistics_data, counter_name), concurrency * number) self.assertGreaterEqual( - counters._get_counter(self.counters._statistics._data, + counters._get_counter(self.counters._statistics_data, timer_name), 0.0) def test_concat(self): @@ -186,7 +186,7 @@ class BaseTestCounters(): else: self.assertTrue(isc.config.ModuleSpec( {'module_name': 'Foo', - 'statistics': self.counters._statistics._spec} + 'statistics': self.counters._statistics_spec} ).validate_statistics( False, self._statistics_data)) diff --git a/src/lib/python/isc/statistics/tests/dns_test.py b/src/lib/python/isc/statistics/tests/dns_test.py index 59187d9dfb..b40fd63976 100644 --- a/src/lib/python/isc/statistics/tests/dns_test.py +++ b/src/lib/python/isc/statistics/tests/dns_test.py @@ -73,7 +73,7 @@ class BaseTestCounters(counters_test.BaseTestCounters): # for counters of xfer running _suffix = 'xfr_running' _xfrrunning_names = \ - isc.config.spec_name_list(self.counters._statistics._spec, + isc.config.spec_name_list(self.counters._statistics_spec, "", True) for name in _xfrrunning_names: if name.find(_suffix) != 1: continue @@ -102,7 +102,7 @@ class BaseTestCounters(counters_test.BaseTestCounters): # for ipsocket/unixsocket counters _prefix = 'socket/' _socket_names = \ - isc.config.spec_name_list(self.counters._statistics._spec, + isc.config.spec_name_list(self.counters._statistics_spec, "", True) for name in _socket_names: if name.find(_prefix) != 0: continue