]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#2040] Added D2Stats::init
authorFrancis Dupont <fdupont@isc.org>
Sun, 5 Sep 2021 07:04:01 +0000 (09:04 +0200)
committerFrancis Dupont <fdupont@isc.org>
Tue, 14 Sep 2021 13:20:27 +0000 (15:20 +0200)
src/bin/d2/d2_process.cc
src/bin/d2/tests/dns_client_unittests.cc
src/bin/d2/tests/stats_test_utils.cc
src/lib/d2srv/d2_stats.cc
src/lib/d2srv/d2_stats.h

index ebd3865e79009b02bcb17fa3cc5ceafc32b31657..a4a738be240c93708e62ee95908d599a65fb37b2 100644 (file)
@@ -16,7 +16,6 @@
 #include <d2srv/d2_tsig_key.h>
 #include <hooks/hooks.h>
 #include <hooks/hooks_manager.h>
-#include <stats/stats_mgr.h>
 
 using namespace isc::hooks;
 using namespace isc::process;
@@ -66,16 +65,8 @@ D2Process::D2Process(const char* name, const asiolink::IOServicePtr& io_service)
     D2CfgMgrPtr tmp = getD2CfgMgr();
     update_mgr_.reset(new D2UpdateMgr(queue_mgr_, tmp, getIoService()));
 
-    // Instantiate stats manager.
-    // Initialize statistics.
-    isc::stats::StatsMgr& stats_mgr = isc::stats::StatsMgr::instance();
-    stats_mgr.setMaxSampleCountDefault(0);
-    for (const auto& name : D2Stats::ncr) {
-        stats_mgr.setValue(name, static_cast<int64_t>(0));
-    }
-    for (const auto& name : D2Stats::update) {
-        stats_mgr.setValue(name, static_cast<int64_t>(0));
-    }
+    // Initialize stats manager.
+    D2Stats::init();
 };
 
 void
index a2915cb0f4e0eecbbb4342ad034515f70f1fa026..33369935ab0904ddca73e031b9c21efa4090c0ed 100644 (file)
@@ -486,9 +486,6 @@ TEST_F(DNSClientTest, invalidTimeout) {
 
 // Verifies that TSIG can be used to sign requests and verify responses.
 TEST_F(DNSClientTest, runTSIGTest) {
-    ConstElementPtr stats_all = StatsMgr::instance().getAll();
-    ASSERT_TRUE(stats_all);
-    EXPECT_TRUE(stats_all->empty());
     std::string secret ("key number one");
     D2TsigKeyPtr key_one;
     ASSERT_NO_THROW(key_one.reset(new
@@ -510,12 +507,6 @@ TEST_F(DNSClientTest, runTSIGTest) {
                                               secret.c_str(), secret.size())));
     checkStats("two.com.", stats_key);
     D2TsigKeyPtr nokey;
-    StatsMgr::instance().setValue("update-sent", 0LL);
-    StatsMgr::instance().setValue("update-signed", 0LL);
-    StatsMgr::instance().setValue("update-unsigned", 0LL);
-    StatsMgr::instance().setValue("update-success", 0LL);
-    StatsMgr::instance().setValue("update-timeout", 0LL);
-    StatsMgr::instance().setValue("update-error", 0LL);
 
     // Should be able to send and receive with no keys.
     // Neither client nor server will attempt to sign or verify.
@@ -535,7 +526,6 @@ TEST_F(DNSClientTest, runTSIGTest) {
     runTSIGTest(nokey, key_two);
 
     // Check statistics.
-    stats_all = StatsMgr::instance().getAll();
     StatMap stats_one = {
         { "update-sent", 3},
         { "update-success", 1},
index 905a765a221c974a6663bd3f07d5d08b3ac9f196..7c8f6df6e328a997fe59e9ab35337ce3f1249628 100644 (file)
@@ -5,6 +5,7 @@
 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
 #include <config.h>
 
+#include <d2srv/d2_stats.h>
 #include <stats_test_utils.h>
 
 using namespace isc::data;
@@ -17,6 +18,7 @@ namespace test {
 
 D2StatTest::D2StatTest() {
     StatsMgr::instance().removeAll();
+    D2Stats::init();
 }
 
 D2StatTest::~D2StatTest() {
index 5c94f4304ffa8e363900676458d3d0e5e16f93b5..3d3d3b6ff19c2c49e06887a52a13069b94e368ac 100644 (file)
@@ -9,8 +9,10 @@
 #include <config.h>
 
 #include <d2srv/d2_stats.h>
+#include <stats/stats_mgr.h>
 
 using namespace std;
+using namespace isc::stats;
 
 namespace isc {
 namespace d2 {
@@ -40,5 +42,17 @@ D2Stats::key = {
     "update-error"
 };
 
+void
+D2Stats::init() {
+    StatsMgr& stats_mgr = isc::stats::StatsMgr::instance();
+    stats_mgr.setMaxSampleCountDefault(0);
+    for (const auto& name : D2Stats::ncr) {
+        stats_mgr.setValue(name, static_cast<int64_t>(0));
+    }
+    for (const auto& name : D2Stats::update) {
+        stats_mgr.setValue(name, static_cast<int64_t>(0));
+    }
+};
+
 } // namespace d2
 } // namespace isc
index be40415e50de11fbbdede698009be97717020af3..4bfd1da7ab191c97ad3cccdfa90d3883d7cc64fb 100644 (file)
@@ -40,6 +40,11 @@ public:
     /// - update-timeout
     /// - update-error
     static std::set<std::string> key;
+
+    /// @brief Initialize D2 statistics.
+    ///
+    /// @note: Add default samples if needed.
+    static void init();
 };
 
 } // namespace d2