Browse Source

[2883] remove _statistics class attribute

and define statistics data and spec inside instance scope
Naoki Kambe 11 years ago
parent
commit
e3dec9b390

+ 10 - 20
src/lib/python/isc/statistics/counters.py

@@ -151,15 +151,6 @@ def _concat(*args, sep='/'):
     """
     """
     return sep.join(args)
     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():
 class Counters():
     """A class for holding and manipulating all statistics counters
     """A class for holding and manipulating all statistics counters
     for a module.  A Counters object may be created by specifying a spec
     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
     timers can be temporarily disabled.  If disabled, counter values are
     not changed even if methods to update them are invoked."""
     not changed even if methods to update them are invoked."""
 
 
-    # default statistics data set
-    _statistics = _Statistics()
-
     def __init__(self, spec_file_name=None):
     def __init__(self, spec_file_name=None):
         """A constructor for the Counters class. A path to the spec file
         """A constructor for the Counters class. A path to the spec file
         can be specified in spec_file_name. Statistics data based on
         can be specified in spec_file_name. Statistics data based on
@@ -190,16 +178,18 @@ class Counters():
         self._start_time = {}
         self._start_time = {}
         self._disabled = False
         self._disabled = False
         self._rlock = threading.RLock()
         self._rlock = threading.RLock()
+        self._statistics_data = {}
+        self._statistics_spec = []
         if not spec_file_name: return
         if not spec_file_name: return
         # change the default statistics spec
         # change the default statistics spec
-        self._statistics._spec = \
+        self._statistics_spec = \
             isc.config.module_spec_from_file(spec_file_name).\
             isc.config.module_spec_from_file(spec_file_name).\
             get_statistics_spec()
             get_statistics_spec()
 
 
     def clear_all(self):
     def clear_all(self):
         """clears all statistics data"""
         """clears all statistics data"""
         with self._rlock:
         with self._rlock:
-            self._statistics._data = {}
+            self._statistics_data = {}
 
 
     def disable(self):
     def disable(self):
         """disables incrementing/decrementing counters"""
         """disables incrementing/decrementing counters"""
@@ -219,8 +209,8 @@ class Counters():
         identifier = _concat(*args)
         identifier = _concat(*args)
         with self._rlock:
         with self._rlock:
             if self._disabled: return
             if self._disabled: return
-            _inc_counter(self._statistics._data,
-                         self._statistics._spec,
+            _inc_counter(self._statistics_data,
+                         self._statistics_spec,
                          identifier, step)
                          identifier, step)
 
 
     def inc(self, *args):
     def inc(self, *args):
@@ -240,7 +230,7 @@ class Counters():
         of the specified counter.  isc.cc.data.DataNotFoundError is
         of the specified counter.  isc.cc.data.DataNotFoundError is
         raised when the counter doesn't have a number yet."""
         raised when the counter doesn't have a number yet."""
         identifier = _concat(*args)
         identifier = _concat(*args)
-        return _get_counter(self._statistics._data, identifier)
+        return _get_counter(self._statistics_data, identifier)
 
 
     def start_timer(self, *args):
     def start_timer(self, *args):
         """Starts a timer which is identified by args and keeps it
         """Starts a timer which is identified by args and keeps it
@@ -271,8 +261,8 @@ class Counters():
             # set the end time
             # set the end time
             _stop_timer(
             _stop_timer(
                 start_time,
                 start_time,
-                self._statistics._data,
-                self._statistics._spec,
+                self._statistics_data,
+                self._statistics_spec,
                 identifier)
                 identifier)
             # A datetime value of once used timer should be deleted
             # A datetime value of once used timer should be deleted
             # for a future use.
             # for a future use.
@@ -293,5 +283,5 @@ class Counters():
         stats module, including each counter. If nothing is counted
         stats module, including each counter. If nothing is counted
         yet, then it returns an empty dictionary."""
         yet, then it returns an empty dictionary."""
         # entire copy
         # entire copy
-        statistics_data = self._statistics._data.copy()
+        statistics_data = self._statistics_data.copy()
         return statistics_data
         return statistics_data

+ 4 - 63
src/lib/python/isc/statistics/dns.py

@@ -69,63 +69,6 @@ documentation for isc.statistics.counters for details."""
 import isc.config
 import isc.config
 from isc.statistics import counters
 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):
 class Counters(counters.Counters):
     """A list of counters which can be handled in the class are like
     """A list of counters which can be handled in the class are like
     the following. Also see documentation for
     the following. Also see documentation for
@@ -176,8 +119,6 @@ class Counters(counters.Counters):
     _entire_server = '_SERVER_'
     _entire_server = '_SERVER_'
     # zone names are contained under this dirname in the spec file.
     # zone names are contained under this dirname in the spec file.
     _perzone_prefix = 'zones'
     _perzone_prefix = 'zones'
-    # default statistics data set
-    _statistics = _Statistics()
 
 
     def __init__(self, spec_file_name=None):
     def __init__(self, spec_file_name=None):
         """If the item `zones` is defined in the spec file, it obtains a
         """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__()"""
         isc.statistics.counters.Counters.__init__()"""
         counters.Counters.__init__(self, spec_file_name)
         counters.Counters.__init__(self, spec_file_name)
         if self._perzone_prefix in \
         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(
             self._zones_item_list = isc.config.spec_name_list(
                 isc.config.find_spec_part(
                 isc.config.find_spec_part(
-                    self._statistics._spec,
+                    self._statistics_spec,
                     '%s/%s/%s' % (self._perzone_prefix,
                     '%s/%s/%s' % (self._perzone_prefix,
                                   '_CLASS_', self._entire_server)))
                                   '_CLASS_', self._entire_server)))
 
 
@@ -199,7 +140,7 @@ class Counters(counters.Counters):
         counter. If nothing is counted yet, then it returns an empty
         counter. If nothing is counted yet, then it returns an empty
         dictionary."""
         dictionary."""
         # entire copy
         # entire copy
-        statistics_data = self._statistics._data.copy()
+        statistics_data = self._statistics_data.copy()
         # If there is no 'zones' found in statistics_data,
         # If there is no 'zones' found in statistics_data,
         # i.e. statistics_data contains no per-zone counter, it just
         # i.e. statistics_data contains no per-zone counter, it just
         # returns statistics_data because calculating total counts
         # returns statistics_data because calculating total counts
@@ -208,7 +149,7 @@ class Counters(counters.Counters):
             return statistics_data
             return statistics_data
         zones = statistics_data[self._perzone_prefix]
         zones = statistics_data[self._perzone_prefix]
         # Start calculation for '_SERVER_' counts
         # 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)
                                                self._perzone_prefix)
         zones_data = {}
         zones_data = {}
         for cls in zones.keys():
         for cls in zones.keys():

+ 5 - 5
src/lib/python/isc/statistics/tests/counters_test.py

@@ -131,15 +131,15 @@ class TestBasicMethods(unittest.TestCase):
         start_functor(concurrency, number, self.counters.inc,
         start_functor(concurrency, number, self.counters.inc,
                       counter_name)
                       counter_name)
         counters._stop_timer(start_time,
         counters._stop_timer(start_time,
-                            self.counters._statistics._data,
-                            self.counters._statistics._spec,
+                            self.counters._statistics_data,
+                            self.counters._statistics_spec,
                             timer_name)
                             timer_name)
         self.assertEqual(
         self.assertEqual(
-            counters._get_counter(self.counters._statistics._data,
+            counters._get_counter(self.counters._statistics_data,
                                  counter_name),
                                  counter_name),
             concurrency * number)
             concurrency * number)
         self.assertGreaterEqual(
         self.assertGreaterEqual(
-            counters._get_counter(self.counters._statistics._data,
+            counters._get_counter(self.counters._statistics_data,
                                  timer_name), 0.0)
                                  timer_name), 0.0)
 
 
     def test_concat(self):
     def test_concat(self):
@@ -186,7 +186,7 @@ class BaseTestCounters():
         else:
         else:
             self.assertTrue(isc.config.ModuleSpec(
             self.assertTrue(isc.config.ModuleSpec(
                     {'module_name': 'Foo',
                     {'module_name': 'Foo',
-                     'statistics': self.counters._statistics._spec}
+                     'statistics': self.counters._statistics_spec}
                     ).validate_statistics(
                     ).validate_statistics(
                     False, self._statistics_data))
                     False, self._statistics_data))
 
 

+ 2 - 2
src/lib/python/isc/statistics/tests/dns_test.py

@@ -73,7 +73,7 @@ class BaseTestCounters(counters_test.BaseTestCounters):
         # for counters of xfer running
         # for counters of xfer running
         _suffix = 'xfr_running'
         _suffix = 'xfr_running'
         _xfrrunning_names = \
         _xfrrunning_names = \
-            isc.config.spec_name_list(self.counters._statistics._spec,
+            isc.config.spec_name_list(self.counters._statistics_spec,
                                       "", True)
                                       "", True)
         for name in _xfrrunning_names:
         for name in _xfrrunning_names:
             if name.find(_suffix) != 1: continue
             if name.find(_suffix) != 1: continue
@@ -102,7 +102,7 @@ class BaseTestCounters(counters_test.BaseTestCounters):
         # for ipsocket/unixsocket counters
         # for ipsocket/unixsocket counters
         _prefix = 'socket/'
         _prefix = 'socket/'
         _socket_names = \
         _socket_names = \
-            isc.config.spec_name_list(self.counters._statistics._spec,
+            isc.config.spec_name_list(self.counters._statistics_spec,
                                       "", True)
                                       "", True)
         for name in _socket_names:
         for name in _socket_names:
             if name.find(_prefix) != 0: continue
             if name.find(_prefix) != 0: continue