Browse Source

[2155] update for structured statistics items

Yoshitaka Aharen 12 years ago
parent
commit
a8a40b6805

+ 6 - 8
src/bin/auth/statistics.cc

@@ -61,8 +61,6 @@ public:
 private:
     // counter for query/response
     Counter server_qr_counter_;
-    // counter for socket
-    Counter socket_counter_;
     // set of counters for zones
     CounterDictionary zone_qr_counters_;
     // validator
@@ -71,9 +69,7 @@ private:
 
 CountersImpl::CountersImpl() :
     // size of server_qr_counter_, zone_qr_counters_: QR_COUNTER_TYPES
-    // size of server_socket_counter_: SOCKET_COUNTER_TYPES
     server_qr_counter_(QR_COUNTER_TYPES),
-    socket_counter_(SOCKET_COUNTER_TYPES),
     zone_qr_counters_(QR_COUNTER_TYPES),
     validator_()
 {}
@@ -229,16 +225,18 @@ CountersImpl::getStatistics() const {
     for (int i = QR_OPCODE_QUERY; i <= QR_OPCODE_OTHER; ++i) {
         const Counter::Type counter = server_qr_counter_.get(i);
         if (counter != 0) {
-            statistics_string << ", \"" << QRCounterItemName[i] << "\": "
-                              << counter;
+            statistics_string << ", \"" << "opcode." <<
+                                 QRCounterOpcode[i - QR_OPCODE_QUERY].name <<
+                                 "\": " << counter;
         }
     }
     // Insert non 0 Rcode counters.
     for (int i = QR_RCODE_NOERROR; i <= QR_RCODE_OTHER; ++i) {
         const Counter::Type counter = server_qr_counter_.get(i);
         if (counter != 0) {
-            statistics_string << ", \"" << QRCounterItemName[i] << "\": "
-                              << counter;
+            statistics_string << ", \"" << "rcode." <<
+                                 QRCounterRcode[i - QR_RCODE_NOERROR].name <<
+                                 "\": " << counter;
         }
     }
     statistics_string << "}";

+ 13 - 4
src/bin/auth/tests/auth_srv_unittest.cc

@@ -1183,7 +1183,10 @@ TEST_F(AuthSrvTest, queryCounterOpcodes) {
     for (int i = 0; i < 6; ++i) {
         // The counter should be initialized to 0.
         expectCounterItem(server.getStatistics(),
-                          QRCounterItemName[QROpCodeToQRCounterType[i]], 0);
+                          std::string("opcode.") +
+                              QRCounterOpcode[QROpCodeToQRCounterType[i] -
+                                                  QR_OPCODE_QUERY].name,
+                          0);
 
         // For each possible opcode, create a request message and send it
         UnitTestUtil::createRequestMessage(request_message, Opcode(i),
@@ -1202,7 +1205,9 @@ TEST_F(AuthSrvTest, queryCounterOpcodes) {
 
         // Confirm the counter.
         expectCounterItem(server.getStatistics(),
-                          QRCounterItemName[QROpCodeToQRCounterType[i]],
+                          std::string("opcode.") +
+                              QRCounterOpcode[QROpCodeToQRCounterType[i] -
+                                                  QR_OPCODE_QUERY].name,
                           i + 1);
     }
     // Check for 6..15
@@ -1212,7 +1217,9 @@ TEST_F(AuthSrvTest, queryCounterOpcodes) {
     for (int i = 6; i < 16; ++i) {
         // The counter should be initialized to 0.
         expectCounterItem(server.getStatistics(),
-                          QRCounterItemName[QROpCodeToQRCounterType[i]],
+                          std::string("opcode.") +
+                              QRCounterOpcode[QROpCodeToQRCounterType[i] -
+                                              QR_OPCODE_QUERY].name,
                           expected);
 
         // For each possible opcode, create a request message and send it
@@ -1232,7 +1239,9 @@ TEST_F(AuthSrvTest, queryCounterOpcodes) {
 
         // Confirm the counter.
         expectCounterItem(server.getStatistics(),
-                          QRCounterItemName[QROpCodeToQRCounterType[i]],
+                          std::string("opcode.") +
+                              QRCounterOpcode[QROpCodeToQRCounterType[i] -
+                                              QR_OPCODE_QUERY].name,
                           expected);
     }
 }

+ 0 - 100
src/bin/auth/tests/statistics_unittest.cc

@@ -103,106 +103,6 @@ TEST_F(CountersTest, incrementNormalQuery) {
     checkCountersAllZeroExcept(counters.getStatistics(), expect_nonzero);
 }
 
-TEST_F(CountersTest, getStatistics) {
-    std::map<std::string, ConstElementPtr> stats_map =
-        counters.getStatistics()->mapValue();
-    for (std::map<std::string, ConstElementPtr>::const_iterator
-            i = stats_map.begin(), e = stats_map.end();
-            i != e;
-            ++i)
-    {
-        // item type check
-        EXPECT_NO_THROW(i->second->intValue())
-            << "Item " << i->first << " is not IntElement";
-    }
-}
-
-TEST_F(AuthCountersTest, getStatisticsWithOpcodeCounters) {
-    // Increment some of the opcode counters.  Then they should appear in the
-    // submitted data; others shouldn't
-    const int opcode_results[16] = { 1, 2, 3, 0, 4, 5, 0, 0,
-                                     0, 0, 0, 0, 0, 0, 0, 0 };
-    updateOpcodeCounters(counters, opcode_results);
-    ConstElementPtr statistics_data = counters.getStatistics();
-    opcodeDataCheck(statistics_data, opcode_results);
-}
-
-TEST_F(AuthCountersTest, getStatisticsWithAllOpcodeCounters) {
-    // Increment all opcode counters.  Then they should appear in the
-    // submitted data.
-    const int opcode_results[16] = { 1, 1, 1, 1, 1, 1, 1, 1,
-                                     1, 1, 1, 1, 1, 1, 1, 1 };
-    updateOpcodeCounters(counters, opcode_results);
-    ConstElementPtr statistics_data = counters.getStatistics();
-    opcodeDataCheck(statistics_data, opcode_results);
-}
-
-TEST_F(AuthCountersTest, getStatisticsWithRcodeCounters) {
-    // Increment some of the rcode counters.  Then they should appear in the
-    // submitted data; others shouldn't
-    const int rcode_results[17] = { 1, 2, 3, 4, 5, 6, 7, 8, 9,
-                                    10, 0, 0, 0, 0, 0, 0, 11 };
-    updateRcodeCounters(counters, rcode_results);
-    ConstElementPtr statistics_data = counters.getStatistics();
-    rcodeDataCheck(statistics_data, rcode_results);
-}
-
-TEST_F(AuthCountersTest, getStatisticsWithAllRcodeCounters) {
-    // Increment all rcode counters.  Then they should appear in the
-    // submitted data.
-    const int rcode_results[17] = { 1, 1, 1, 1, 1, 1, 1, 1, 1,
-                                     1, 1, 1, 1, 1, 1, 1, 1 };
-    updateOpcodeCounters(counters, rcode_results);
-    ConstElementPtr statistics_data = counters.getStatistics();
-    opcodeDataCheck(statistics_data, rcode_results);
-}
-
-TEST_F(AuthCountersTest, getStatisticsWithValidator) {
-
-    //a validator for the unittest
-    AuthCounters::validator_type validator;
-    ConstElementPtr el;
-
-    // Get statistics data with correct statistics validator.
-    validator = boost::bind(
-        &AuthCountersTest::MockModuleSpec::validateStatistics,
-        &module_spec_, _1, true);
-
-    EXPECT_TRUE(validator(el));
-
-    // register validator to AuthCounters
-    counters.registerStatisticsValidator(validator);
-
-    // Counters should be initialized to 0.
-    EXPECT_EQ(0, counters.getCounter(AuthCounters::SERVER_UDP_QUERY));
-    EXPECT_EQ(0, counters.getCounter(AuthCounters::SERVER_TCP_QUERY));
-
-    // UDP query counter is set to 2.
-    counters.inc(AuthCounters::SERVER_UDP_QUERY);
-    counters.inc(AuthCounters::SERVER_UDP_QUERY);
-    // TCP query counter is set to 1.
-    counters.inc(AuthCounters::SERVER_TCP_QUERY);
-
-    // checks the value returned by getStatistics
-    ConstElementPtr statistics_data = counters.getStatistics();
-
-    // UDP query counter is 2 and TCP query counter is 1.
-    EXPECT_EQ(2, statistics_data->get("queries.udp")->intValue());
-    EXPECT_EQ(1, statistics_data->get("queries.tcp")->intValue());
-
-    // Get statistics data with incorrect statistics validator.
-    validator = boost::bind(
-        &AuthCountersTest::MockModuleSpec::validateStatistics,
-        &module_spec_, _1, false);
-
-    EXPECT_FALSE(validator(el));
-
-    counters.registerStatisticsValidator(validator);
-
-    // checks the value returned by getStatistics
-    EXPECT_FALSE(counters.getStatistics());
-}
-
 int
 countTreeElements(const struct CounterTypeTree* tree) {
     int count = 0;