Browse Source

[2884] insert classname

as an argument of get(), inc() and start_timer()
Naoki Kambe 12 years ago
parent
commit
53f6ad9e37

+ 1 - 0
src/bin/xfrin/tests/xfrin_test.py

@@ -2182,6 +2182,7 @@ class TestStatisticsXfrinConn(TestXfrinConnection):
         name2count.update(overwrite)
         for (name, exp) in name2count.items():
             act = self.conn._counters.get(self.__zones,
+                                          TEST_RRCLASS_STR,
                                           TEST_ZONE_NAME_STR,
                                           name)
             msg = '%s is expected %s but actually %s' % (name, exp, act)

+ 15 - 7
src/bin/xfrin/xfrin.py.in

@@ -875,8 +875,9 @@ class XfrinConnection(asyncore.dispatcher):
 
         self._send_query(RRType.SOA)
         # count soaoutv4 or soaoutv6 requests
-        self._counters.inc('zones', self._zone_name.to_text(),
-                           'soaout' + self._get_ipver_str())
+        self._counters.inc('zones', self._rrclass.to_text(),
+                           self._zone_name.to_text(), 'soaout' +
+                           self._get_ipver_str())
         data_len = self._get_request_response(2)
         msg_len = socket.htons(struct.unpack('H', data_len)[0])
         soa_response = self._get_request_response(msg_len)
@@ -918,12 +919,17 @@ class XfrinConnection(asyncore.dispatcher):
             # Note: If the timer for the zone is already started but
             # not yet stopped due to some error, the last start time
             # is overwritten at this point.
-            self._counters.start_timer('zones', self._zone_name.to_text(),
-                                       'last_' + req_str.lower() + '_duration')
+            self._counters.start_timer('zones',
+                                       self._rrclass.to_text(),
+                                       self._zone_name.to_text(),
+                                       'last_' + req_str.lower() +
+                                       '_duration')
             logger.info(XFRIN_XFR_TRANSFER_STARTED, req_str, self.zone_str())
             # An AXFR or IXFR is being requested.
-            self._counters.inc('zones', self._zone_name.to_text(),
-                               req_str.lower() + 'req' + self._get_ipver_str())
+            self._counters.inc('zones', self._rrclass.to_text(),
+                               self._zone_name.to_text(),
+                               req_str.lower() + 'req' +
+                               self._get_ipver_str())
             self._send_query(self._request_type)
             self.__state = XfrinInitialSOA()
             self._handle_xfrin_responses()
@@ -988,11 +994,13 @@ class XfrinConnection(asyncore.dispatcher):
             # A xfrsuccess or xfrfail counter is incremented depending on
             # the result.
             result = {XFRIN_OK: 'xfrsuccess', XFRIN_FAIL: 'xfrfail'}[ret]
-            self._counters.inc('zones', self._zone_name.to_text(), result)
+            self._counters.inc('zones', self._rrclass.to_text(),
+                               self._zone_name.to_text(), result)
             # The started statistics timer is finally stopped only in
             # a successful case.
             if ret == XFRIN_OK:
                 self._counters.stop_timer('zones',
+                                          self._rrclass.to_text(),
                                           self._zone_name.to_text(),
                                           'last_' + req_str.lower() +
                                           '_duration')

+ 19 - 10
src/bin/xfrout/tests/xfrout_test.py.in

@@ -1,4 +1,4 @@
-# Copyright (C) 2010-2012  Internet Systems Consortium.
+# Copyright (C) 2010-2013  Internet Systems Consortium.
 #
 # Permission to use, copy, modify, and distribute this software for any
 # purpose with or without fee is hereby granted, provided that the above
@@ -441,7 +441,8 @@ class TestXfroutSession(TestXfroutSessionBase):
         # check the 'xfrrej' counter initially
         self.assertRaises(isc.cc.data.DataNotFoundError,
                           self.xfrsess._counters.get, 'zones',
-                          TEST_ZONE_NAME_STR, 'xfrrej')
+                          TEST_RRCLASS.to_text(), TEST_ZONE_NAME_STR,
+                          'xfrrej')
         # Localhost (the default in this test) is accepted
         rcode, msg = self.xfrsess._parse_query_message(self.mdata)
         self.assertEqual(rcode.to_text(), "NOERROR")
@@ -457,7 +458,8 @@ class TestXfroutSession(TestXfroutSessionBase):
         self.assertEqual(rcode.to_text(), "REFUSED")
         # check the 'xfrrej' counter after incrementing
         self.assertEqual(self.xfrsess._counters.get(
-                'zones', TEST_ZONE_NAME_STR, 'xfrrej'), 1)
+                'zones', TEST_RRCLASS.to_text(), TEST_ZONE_NAME_STR,
+                'xfrrej'), 1)
 
         # TSIG signed request
         request_data = self.create_request_data(with_tsig=True)
@@ -488,7 +490,8 @@ class TestXfroutSession(TestXfroutSessionBase):
         self.assertEqual(rcode.to_text(), "REFUSED")
         # check the 'xfrrej' counter after incrementing
         self.assertEqual(self.xfrsess._counters.get(
-                'zones', TEST_ZONE_NAME_STR, 'xfrrej'), 2)
+                'zones', TEST_RRCLASS.to_text(), TEST_ZONE_NAME_STR,
+                'xfrrej'), 2)
 
         # ACL using TSIG: no TSIG; should be rejected
         acl_setter(isc.acl.dns.REQUEST_LOADER.load([
@@ -498,7 +501,8 @@ class TestXfroutSession(TestXfroutSessionBase):
         self.assertEqual(rcode.to_text(), "REFUSED")
         # check the 'xfrrej' counter after incrementing
         self.assertEqual(self.xfrsess._counters.get(
-                'zones', TEST_ZONE_NAME_STR, 'xfrrej'), 3)
+                'zones', TEST_RRCLASS.to_text(), TEST_ZONE_NAME_STR,
+                'xfrrej'), 3)
 
         #
         # ACL using IP + TSIG: both should match
@@ -520,7 +524,8 @@ class TestXfroutSession(TestXfroutSessionBase):
         self.assertEqual(rcode.to_text(), "REFUSED")
         # check the 'xfrrej' counter after incrementing
         self.assertEqual(self.xfrsess._counters.get(
-                'zones', TEST_ZONE_NAME_STR, 'xfrrej'), 4)
+                'zones', TEST_RRCLASS.to_text(), TEST_ZONE_NAME_STR,
+                'xfrrej'), 4)
         # Address matches, but TSIG doesn't (not included)
         self.xfrsess._remote = (socket.AF_INET, socket.SOCK_STREAM,
                                 ('192.0.2.1', 12345))
@@ -528,7 +533,8 @@ class TestXfroutSession(TestXfroutSessionBase):
         self.assertEqual(rcode.to_text(), "REFUSED")
         # check the 'xfrrej' counter after incrementing
         self.assertEqual(self.xfrsess._counters.get(
-                'zones', TEST_ZONE_NAME_STR, 'xfrrej'), 5)
+                'zones', TEST_RRCLASS.to_text(), TEST_ZONE_NAME_STR,
+                'xfrrej'), 5)
         # Neither address nor TSIG matches
         self.xfrsess._remote = (socket.AF_INET, socket.SOCK_STREAM,
                                 ('192.0.2.2', 12345))
@@ -536,7 +542,8 @@ class TestXfroutSession(TestXfroutSessionBase):
         self.assertEqual(rcode.to_text(), "REFUSED")
         # check the 'xfrrej' counter after incrementing
         self.assertEqual(self.xfrsess._counters.get(
-                'zones', TEST_ZONE_NAME_STR, 'xfrrej'), 6)
+                'zones', TEST_RRCLASS.to_text(), TEST_ZONE_NAME_STR,
+                'xfrrej'), 6)
 
     def test_transfer_acl(self):
         # ACL checks only with the default ACL
@@ -936,12 +943,14 @@ class TestXfroutSession(TestXfroutSessionBase):
 
         self.assertRaises(isc.cc.data.DataNotFoundError,
                           self.xfrsess._counters.get,
-                          'zones', TEST_ZONE_NAME_STR, 'xfrreqdone')
+                          'zones', TEST_RRCLASS.to_text(),
+                          TEST_ZONE_NAME_STR, 'xfrreqdone')
         self.xfrsess._reply_xfrout_query = myreply
         self.xfrsess.dns_xfrout_start(self.sock, self.mdata)
         self.assertEqual(self.sock.readsent(), b"success")
         self.assertGreater(self.xfrsess._counters.get(
-            'zones', TEST_ZONE_NAME_STR, 'xfrreqdone'), 0)
+            'zones', TEST_RRCLASS.to_text(), TEST_ZONE_NAME_STR,
+            'xfrreqdone'), 0)
 
     def test_reply_xfrout_query_axfr(self):
         self.xfrsess._soa = self.soa_rrset

+ 4 - 2
src/bin/xfrout/xfrout.py.in

@@ -301,7 +301,8 @@ class XfroutSession():
             return None, None
         elif acl_result == REJECT:
             # count rejected Xfr request by each zone name
-            self._counters.inc('zones', zone_name.to_text(), 'xfrrej')
+            self._counters.inc('zones', zone_class.to_text(),
+                               zone_name.to_text(), 'xfrrej')
             logger.debug(DBG_XFROUT_TRACE, XFROUT_QUERY_REJECTED,
                          self._request_type, format_addrinfo(self._remote),
                          format_zone_str(zone_name, zone_class))
@@ -571,7 +572,8 @@ class XfroutSession():
             else:
                 self._counters.dec('ixfr_running')
         # count done Xfr requests by each zone name
-        self._counters.inc('zones', zone_name.to_text(), 'xfrreqdone')
+        self._counters.inc('zones', zone_class.to_text(),
+                           zone_name.to_text(), 'xfrreqdone')
         logger.info(XFROUT_XFR_TRANSFER_DONE, self._request_typestr,
                     format_addrinfo(self._remote), zone_str)
 

+ 6 - 2
src/lib/python/isc/notify/notify_out.py

@@ -509,10 +509,14 @@ class NotifyOut:
             sock.sendto(render.get_data(), 0, addrinfo)
             # count notifying by IPv4 or IPv6 for statistics
             if zone_notify_info.get_socket().family == socket.AF_INET:
-                self._counters.inc('zones', zone_notify_info.zone_name,
+                self._counters.inc('zones',
+                                   zone_notify_info.zone_class,
+                                   zone_notify_info.zone_name,
                                   'notifyoutv4')
             elif zone_notify_info.get_socket().family == socket.AF_INET6:
-                self._counters.inc('zones', zone_notify_info.zone_name,
+                self._counters.inc('zones',
+                                   zone_notify_info.zone_class,
+                                   zone_notify_info.zone_name,
                                   'notifyoutv6')
             logger.info(NOTIFY_OUT_SENDING_NOTIFY, AddressFormatter(addrinfo))
         except (socket.error, addr.InvalidAddress) as err:

+ 12 - 12
src/lib/python/isc/notify/tests/notify_out_test.py

@@ -304,10 +304,10 @@ class TestNotifyOut(unittest.TestCase):
 
         self.assertRaises(isc.cc.data.DataNotFoundError,
                           self._notify._counters.get,
-                          'zones', 'example.net.', 'notifyoutv4')
+                          'zones', 'IN', 'example.net.', 'notifyoutv4')
         self.assertRaises(isc.cc.data.DataNotFoundError,
                           self._notify._counters.get,
-                          'zones', 'example.net.', 'notifyoutv6')
+                          'zones', 'IN', 'example.net.', 'notifyoutv6')
 
         example_com_info.prepare_notify_out()
         ret = self._notify._send_notify_message_udp(example_com_info,
@@ -315,38 +315,38 @@ class TestNotifyOut(unittest.TestCase):
         self.assertTrue(ret)
         self.assertEqual(socket.AF_INET, example_com_info.sock_family)
         self.assertEqual(self._notify._counters.get(
-                'zones', 'example.net.', 'notifyoutv4'), 1)
+                'zones', 'IN', 'example.net.', 'notifyoutv4'), 1)
         self.assertEqual(self._notify._counters.get(
-                'zones', 'example.net.', 'notifyoutv6'), 0)
+                'zones', 'IN', 'example.net.', 'notifyoutv6'), 0)
 
     def test_send_notify_message_udp_ipv6(self):
         example_com_info = self._notify._notify_infos[('example.net.', 'IN')]
 
         self.assertRaises(isc.cc.data.DataNotFoundError,
                           self._notify._counters.get,
-                          'zones', 'example.net.', 'notifyoutv4')
+                          'zones', 'IN', 'example.net.', 'notifyoutv4')
         self.assertRaises(isc.cc.data.DataNotFoundError,
                           self._notify._counters.get,
-                          'zones', 'example.net.', 'notifyoutv6')
+                          'zones', 'IN', 'example.net.', 'notifyoutv6')
 
         ret = self._notify._send_notify_message_udp(example_com_info,
                                                     ('2001:db8::53', 53))
         self.assertTrue(ret)
         self.assertEqual(socket.AF_INET6, example_com_info.sock_family)
         self.assertEqual(self._notify._counters.get(
-                'zones', 'example.net.', 'notifyoutv4'), 0)
+                'zones', 'IN', 'example.net.', 'notifyoutv4'), 0)
         self.assertEqual(self._notify._counters.get(
-                'zones', 'example.net.', 'notifyoutv6'), 1)
+                'zones', 'IN', 'example.net.', 'notifyoutv6'), 1)
 
     def test_send_notify_message_with_bogus_address(self):
         example_com_info = self._notify._notify_infos[('example.net.', 'IN')]
 
         self.assertRaises(isc.cc.data.DataNotFoundError,
                           self._notify._counters.get,
-                          'zones', 'example.net.', 'notifyoutv4')
+                          'zones', 'IN', 'example.net.', 'notifyoutv4')
         self.assertRaises(isc.cc.data.DataNotFoundError,
                           self._notify._counters.get,
-                          'zones', 'example.net.', 'notifyoutv6')
+                          'zones', 'IN', 'example.net.', 'notifyoutv6')
 
         # As long as the underlying data source validates RDATA this shouldn't
         # happen, but right now it's not actually the case.  Even if the
@@ -358,10 +358,10 @@ class TestNotifyOut(unittest.TestCase):
 
         self.assertRaises(isc.cc.data.DataNotFoundError,
                           self._notify._counters.get,
-                          'zones', 'example.net.', 'notifyoutv4')
+                          'zones', 'IN', 'example.net.', 'notifyoutv4')
         self.assertRaises(isc.cc.data.DataNotFoundError,
                           self._notify._counters.get,
-                          'zones', 'example.net.', 'notifyoutv4')
+                          'zones', 'IN', 'example.net.', 'notifyoutv4')
 
     def test_zone_notify_handler(self):
         sent_addrs = []

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

@@ -1,4 +1,4 @@
-# Copyright (C) 2012  Internet Systems Consortium.
+# Copyright (C) 2012-2013  Internet Systems Consortium.
 #
 # Permission to use, copy, modify, and distribute this software for any
 # purpose with or without fee is hereby granted, provided that the above
@@ -23,6 +23,7 @@ import imp
 import isc.config
 
 TEST_ZONE_NAME_STR = "example.com."
+TEST_ZONE_CLASS_STR = "IN"
 TESTDATA_SRCDIR = os.getenv("TESTDATASRCDIR")
 
 from isc.statistics import counters
@@ -196,7 +197,8 @@ class BaseTestCounters():
     def test_perzone_counters(self):
         # for per-zone counters
         for name in self.counters._zones_item_list:
-            args = (self._perzone_prefix, TEST_ZONE_NAME_STR, name)
+            args = (self._perzone_prefix, TEST_ZONE_CLASS_STR,
+                    TEST_ZONE_NAME_STR, name)
             if name.find('last_') == 0 and name.endswith('_duration'):
                 self.counters.start_timer(*args)
                 self.counters.stop_timer(*args)
@@ -204,7 +206,8 @@ class BaseTestCounters():
                 sec = self.counters.get(*args)
                 for zone_str in (self._entire_server, TEST_ZONE_NAME_STR):
                     isc.cc.data.set(self._statistics_data,
-                                    '%s/%s/%s' % (args[0], zone_str, name), sec)
+                                    '%s/%s/%s/%s' % (args[0], args[1],
+                                                     zone_str, name), sec)
                 # twice exec stopper, then second is not changed
                 self.counters.stop_timer(*args)
                 self.assertEqual(self.counters.get(*args), sec)
@@ -220,7 +223,8 @@ class BaseTestCounters():
                 self.assertEqual(self.counters.get(*args), 2)
                 for zone_str in (self._entire_server, TEST_ZONE_NAME_STR):
                     isc.cc.data.set(self._statistics_data,
-                                    '%s/%s/%s' % (args[0], zone_str, name), 2)
+                                    '%s/%s/%s/%s' % (args[0], args[1],
+                                                     zone_str, name), 2)
         self.check_get_statistics()
 
     def test_xfrrunning_counters(self):
@@ -277,7 +281,8 @@ class BaseTestCounters():
     def test_perzone_zero_counters(self):
         # setting all counters to zero
         for name in self.counters._zones_item_list:
-            args = (self._perzone_prefix, TEST_ZONE_NAME_STR, name)
+            args = (self._perzone_prefix, TEST_ZONE_CLASS_STR,
+                    TEST_ZONE_NAME_STR, name)
             if name.find('last_') == 0 and name.endswith('_duration'):
                 zero = 0.0
             else:
@@ -286,7 +291,8 @@ class BaseTestCounters():
             self.counters._incdec(*args, step=zero)
             for zone_str in (self._entire_server, TEST_ZONE_NAME_STR):
                 isc.cc.data.set(self._statistics_data,
-                                '%s/%s/%s' % (args[0], zone_str, name), zero)
+                                '%s/%s/%s/%s' % (args[0], args[1],
+                                                 zone_str, name), zero)
         self.check_get_statistics()
 
     def test_undefined_item(self):
@@ -352,15 +358,19 @@ class DummyNotifyOut(BaseDummyModule):
 
     def inc_counters(self):
         """increments counters"""
-        self.counters.inc('zones', TEST_ZONE_NAME_STR, 'notifyoutv4')
-        self.counters.inc('zones', TEST_ZONE_NAME_STR, 'notifyoutv6')
+        self.counters.inc('zones', TEST_ZONE_CLASS_STR,
+                          TEST_ZONE_NAME_STR, 'notifyoutv4')
+        self.counters.inc('zones', TEST_ZONE_CLASS_STR,
+                          TEST_ZONE_NAME_STR, 'notifyoutv6')
 
 class DummyXfroutSession(BaseDummyModule):
     """A dummy class equivalent to XfroutSession in b10-xfrout"""
     def inc_counters(self):
         """increments counters"""
-        self.counters.inc('zones', TEST_ZONE_NAME_STR, 'xfrreqdone')
-        self.counters.inc('zones', TEST_ZONE_NAME_STR, 'xfrrej')
+        self.counters.inc('zones', TEST_ZONE_CLASS_STR,
+                          TEST_ZONE_NAME_STR, 'xfrreqdone')
+        self.counters.inc('zones', TEST_ZONE_CLASS_STR,
+                          TEST_ZONE_NAME_STR, 'xfrrej')
         self.counters.inc('axfr_running')
         self.counters.inc('ixfr_running')
         self.counters.dec('axfr_running')