]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[755-Kea-DHCP-servers-observations-should-be-reset] implement required changes to...
authorFranciszek Gorski <fagorski9@gmail.com>
Thu, 5 Sep 2019 07:35:19 +0000 (09:35 +0200)
committerMarcin Siodelski <marcin@isc.org>
Fri, 6 Sep 2019 09:34:54 +0000 (11:34 +0200)
doc/sphinx/arm/dhcp4-srv.rst
doc/sphinx/arm/dhcp6-srv.rst
doc/sphinx/arm/stats.rst
src/bin/dhcp4/tests/ctrl_dhcp4_srv_unittest.cc
src/bin/dhcp6/dhcp6_srv.cc
src/bin/dhcp6/dhcp6_srv.h
src/bin/dhcp6/tests/ctrl_dhcp6_srv_unittest.cc

index b44f74cc458ad20bc0803001154c53ab8f6984dd..024687d5be5d8a35eae1f6b2bb20dea34fa27690 100644 (file)
@@ -5510,6 +5510,10 @@ following statistics-related commands:
 -  statistic-get-all
 -  statistic-reset-all
 -  statistic-remove-all
+-  statistic-sample-age-set
+-  statistic-sample-age-set-all
+-  statistic-sample-count-set
+-  statistic-sample-count-set-all
 
 as described in :ref:`command-stats`.
 
index 5a4046212f596190b9c6d78c2be1dc437f8e4ea4..55a70d7528d2ffa47ff57406d62c77e44ff5533b 100644 (file)
@@ -5524,6 +5524,10 @@ following statistics-related commands:
 -  statistic-get-all
 -  statistic-reset-all
 -  statistic-remove-all
+-  statistic-sample-age-set
+-  statistic-sample-age-set-all
+-  statistic-sample-count-set
+-  statistic-sample-count-set-all
 
 as described in :ref:`command-stats`.
 
index 06924512fecf2984827be9d4c94c62face71a757..23404cdc70bd275eefd9065d089842ecfa034f64 100644 (file)
@@ -52,15 +52,16 @@ for a list of statistics-oriented commands.
 Statistics Lifecycle
 ====================
 
-It is useful to understand how the Statistics Manager module works. When
-the server starts operation, the manager is empty and contains no
-statistics. If the ``statistic-get-all`` command is executed at that point, an empty list is
-returned. Once the server performs an operation that causes a statistic
-to change, the related statistic will be created. In general, once a
-statistic is recorded even once, it is kept in the manager until
-explicitly removed, by ``statistic-remove`` or ``statistic-remove-all``
-being called, or when the server is shut down. Per-subnet statistics are
-explicitly removed when reconfiguration takes place.
+It is useful to understand how the Statistics Manager module works.
+Since Kea 1.7.0 when the server starts operation, the manager contains
+all statistics related to runned type of DHCP server, initialized with
+default value. If the ``statistic-get-all`` command is executed at that point,
+a list with these statistics is returned. Once the server performs an operation
+that causes a statistic to change, the related statistic will be created or updated.
+In general, once a statistic is recorded even once, it is kept in the manager
+until explicitly removed, by ``statistic-remove`` or ``statistic-remove-all``
+being called, or when the server is shut down.
+Per-subnet statistics are explicitly removed when reconfiguration takes place.
 
 Statistics are considered runtime properties, so they are not retained
 after server restart.
@@ -84,14 +85,16 @@ Commands for Manipulating Statistics
 
 There are several commands defined that can be used for accessing
 (-get), resetting to zero or a neutral value (-reset), or removing a
-statistic completely (-remove). The difference between reset and remove
-is somewhat subtle. The reset command sets the value of the statistic to
-zero or a neutral value, so after this operation, the statistic will
-have a value of 0 (integer), 0.0 (float), 0h0m0s0us (duration), or ""
-(string). When requested, a statistic with the values mentioned will be
-returned. ``Remove`` removes a statistic completely, so the statistic
-will no longer be reported. Please note that the server code may add
-it back if there is a reason to record it.
+statistic completely (-remove). We can change the statistics time based
+limit (-sample-age-set) and size based limit (-sample-count-set).
+The difference between reset and remove is somewhat subtle.
+The reset command sets the value of the statistic to zero or a neutral value,
+so after this operation, the statistic will have a value of 0 (integer),
+0.0 (float), 0h0m0s0us (duration), or "" (string).
+When requested, a statistic with the values mentioned will be returned.
+``Remove`` removes a statistic completely, so the statistic will no longer
+be reported. Please note that the server code may add it back if there is a reason
+to record it.
 
 .. note::
 
index f06f62cf27f7ed81547af10db2f0df110ec2a1de..e6598b20adb3c81e710dd577c6d63d45faf5b237 100644 (file)
@@ -554,8 +554,6 @@ TEST_F(CtrlChannelDhcpv4SrvTest, controlChannelStats) {
 
     // preparing the schema which check if all statistics are set to zero
     std::string stats_get_all = "{ \"arguments\": { "
-         "\"declined-addresses\": [ [ 0, \"" + isc::util::ptimeToText(StatsMgr::instance().getObservation("declined-addresses")
-                                    ->getInteger().second) + "\" ] ], "
          "\"pkt4-ack-received\": [ [ 0, \"" + isc::util::ptimeToText(StatsMgr::instance().getObservation("pkt4-ack-received")
                                     ->getInteger().second) + "\" ] ], "
          "\"pkt4-ack-sent\": [ [ 0, \"" + isc::util::ptimeToText(StatsMgr::instance().getObservation("pkt4-ack-sent")
@@ -587,10 +585,6 @@ TEST_F(CtrlChannelDhcpv4SrvTest, controlChannelStats) {
          "\"pkt4-sent\": [ [ 0, \"" + isc::util::ptimeToText(StatsMgr::instance().getObservation("pkt4-sent")
                                     ->getInteger().second) + "\" ] ], "
          "\"pkt4-unknown-received\": [ [ 0, \"" + isc::util::ptimeToText(StatsMgr::instance().getObservation("pkt4-unknown-received")
-                                    ->getInteger().second) + "\" ] ], "
-         "\"reclaimed-declined-addresses\": [ [ 0, \"" + isc::util::ptimeToText(StatsMgr::instance().getObservation("reclaimed-declined-addresses")
-                                    ->getInteger().second) + "\" ] ], "
-         "\"reclaimed-leases\": [ [ 0, \"" + isc::util::ptimeToText(StatsMgr::instance().getObservation("reclaimed-leases")
                                     ->getInteger().second) + "\" ] ] }, "
          "\"result\": 0 }";
 
index a82a0e634e8bd3a74d01f68a709133138406a5bd..3da15808e754b7a863c7f2f8657c10597f706161 100644 (file)
@@ -172,6 +172,28 @@ createStatusCode(const Pkt6& pkt, const Option6IA& ia, const uint16_t status_cod
     return (option_status);
 }
 
+    /// Set of all statistics observed in DHCPv6 server
+    std::set<std::string> dhcp6_statistics = {
+        "pkt6-received",
+        "pkt6-solicit-received",
+        "pkt6-advertise-received",
+        "pkt6-request-received",
+        "pkt6-reply-received",
+        "pkt6-renew-received",
+        "pkt6-rebind-received",
+        "pkt6-decline-received",
+        "pkt6-release-received",
+        "pkt6-infrequest-received",
+        "pkt6-dhcpv4-query-received",
+        "pkt6-dhcpv4-response-received",
+        "pkt6-unknown-received",
+        "pkt6-sent",
+        "pkt6-advertise-sent",
+        "pkt6-reply-sent",
+        "pkt6-dhcpv4-response-sent",
+        "pkt6-parse-failed",
+        "pkt6-receive-drop"
+    };
 }; // anonymous namespace
 
 namespace isc {
@@ -216,58 +238,24 @@ Dhcpv6Srv::Dhcpv6Srv(uint16_t server_port, uint16_t client_port)
         LOG_ERROR(dhcp6_logger, DHCP6_SRV_CONSTRUCT_ERROR).arg(e.what());
         return;
     }
-    // Initializing all observations with zero value
-    isc::stats::StatsMgr::instance().setValue("pkt6-received",
-                                              static_cast<int64_t>(0));
-    isc::stats::StatsMgr::instance().setValue("pkt6-solicit-received",
-                                              static_cast<int64_t>(0));
-    isc::stats::StatsMgr::instance().setValue("pkt6-advertise-received",
-                                              static_cast<int64_t>(0));
-    isc::stats::StatsMgr::instance().setValue("pkt6-request-received",
-                                              static_cast<int64_t>(0));
-    isc::stats::StatsMgr::instance().setValue("pkt6-reply-received",
-                                              static_cast<int64_t>(0));
-    isc::stats::StatsMgr::instance().setValue("pkt6-renew-received",
-                                              static_cast<int64_t>(0));
-    isc::stats::StatsMgr::instance().setValue("pkt6-rebind-received",
-                                              static_cast<int64_t>(0));
-    isc::stats::StatsMgr::instance().setValue("pkt6-release-received",
-                                              static_cast<int64_t>(0));
-    isc::stats::StatsMgr::instance().setValue("pkt6-decline-received",
-                                              static_cast<int64_t>(0));
-    isc::stats::StatsMgr::instance().setValue("pkt6-infrequest-received",
-                                              static_cast<int64_t>(0));
-    isc::stats::StatsMgr::instance().setValue("pkt6-dhcpv4-query-received",
-                                              static_cast<int64_t>(0));
-    isc::stats::StatsMgr::instance().setValue("pkt6-dhcpv4-response-received",
-                                              static_cast<int64_t>(0));
-    isc::stats::StatsMgr::instance().setValue("pkt6-unknown-received",
-                                              static_cast<int64_t>(0));
-
-    isc::stats::StatsMgr::instance().setValue("pkt6-sent",
-                                              static_cast<int64_t>(0));
-    isc::stats::StatsMgr::instance().setValue("pkt6-advertise-sent",
-                                              static_cast<int64_t>(0));
-    isc::stats::StatsMgr::instance().setValue("pkt6-reply-sent",
-                                              static_cast<int64_t>(0));
-    isc::stats::StatsMgr::instance().setValue("pkt6-dhcpv4-response-sent",
-                                              static_cast<int64_t>(0));
-
-    isc::stats::StatsMgr::instance().setValue("pkt6-parse-failed",
-                                              static_cast<int64_t>(0));
-    isc::stats::StatsMgr::instance().setValue("pkt6-receive-drop",
-                                              static_cast<int64_t>(0));
-
-    isc::stats::StatsMgr::instance().setValue("reclaimed-leases",
-                                              static_cast<int64_t>(0));
-    isc::stats::StatsMgr::instance().setValue("declined-addresses",
-                                              static_cast<int64_t>(0));
-    isc::stats::StatsMgr::instance().setValue("reclaimed-declined-addresses",
-                                              static_cast<int64_t>(0));
+    // Initializing all observations with default value
+    setPacketStatisticsDefaults();
+
     // All done, so can proceed
     shutdown_ = false;
 }
 
+void Dhcpv6Srv::setPacketStatisticsDefaults() {
+    std::set<std::string>::iterator it;
+    isc::stats::StatsMgr& stats_mgr = isc::stats::StatsMgr::instance();
+
+    // Iterate over set of observed statistics
+    for (it = dhcp6_statistics.begin(); it != dhcp6_statistics.end(); ++it) {
+        // Initialize them with default value 0
+        stats_mgr.setValue((*it), static_cast<int64_t>(0));
+    }
+}
+
 Dhcpv6Srv::~Dhcpv6Srv() {
     discardPackets();
     try {
index e421832d03ea236ed50d121992e8d3ea4cb22875..3e44bd0113453a02a3fa3aa376843c19f49070de 100644 (file)
@@ -89,6 +89,9 @@ public:
     /// @brief Destructor. Used during DHCPv6 service shutdown.
     virtual ~Dhcpv6Srv();
 
+    /// @brief This function set to defaults all statistics starting with pkt6-.
+    void setPacketStatisticsDefaults();
+
     /// @brief Checks if the server is running in unit test mode.
     ///
     /// @return true if the server is running in unit test mode,
index 8cdb0a4f62799c2859d00975f8259c65389deaeb..9fff87a2bc8da6b49097549b9021cc7fc8c2d6fa 100644 (file)
@@ -1136,8 +1136,6 @@ TEST_F(CtrlChannelDhcpv6SrvTest, controlChannelStats) {
 
     // preparing the schema which check if all statistics are set to zero
     std::string stats_get_all = "{ \"arguments\": { "
-         "\"declined-addresses\": [ [ 0, \"" + isc::util::ptimeToText(StatsMgr::instance().getObservation("declined-addresses")
-                                    ->getInteger().second) + "\" ] ], "
          "\"pkt6-advertise-received\": [ [ 0, \"" + isc::util::ptimeToText(StatsMgr::instance().getObservation("pkt6-advertise-received")
                                     ->getInteger().second) + "\" ] ], "
          "\"pkt6-advertise-sent\": [ [ 0, \"" + isc::util::ptimeToText(StatsMgr::instance().getObservation("pkt6-advertise-sent")
@@ -1175,10 +1173,6 @@ TEST_F(CtrlChannelDhcpv6SrvTest, controlChannelStats) {
          "\"pkt6-solicit-received\": [ [ 0, \"" + isc::util::ptimeToText(StatsMgr::instance().getObservation("pkt6-solicit-received")
                                     ->getInteger().second) + "\" ] ], "
          "\"pkt6-unknown-received\": [ [ 0, \"" + isc::util::ptimeToText(StatsMgr::instance().getObservation("pkt6-unknown-received")
-                                    ->getInteger().second) + "\" ] ], "
-         "\"reclaimed-declined-addresses\": [ [ 0, \"" + isc::util::ptimeToText(StatsMgr::instance().getObservation("reclaimed-declined-addresses")
-                                    ->getInteger().second) + "\" ] ], "
-         "\"reclaimed-leases\": [ [ 0, \"" + isc::util::ptimeToText(StatsMgr::instance().getObservation("reclaimed-leases")
                                     ->getInteger().second) + "\" ] ] }, "
          "\"result\": 0 }";