From: Franciszek Gorski Date: Thu, 5 Sep 2019 07:35:19 +0000 (+0200) Subject: [755-Kea-DHCP-servers-observations-should-be-reset] implement required changes to... X-Git-Tag: Kea-1.7.0~29 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3a92d227275d014404c477fa1624c2bc0b03be56;p=thirdparty%2Fkea.git [755-Kea-DHCP-servers-observations-should-be-reset] implement required changes to dhcp4 and dhcp6 servers --- diff --git a/doc/sphinx/arm/dhcp4-srv.rst b/doc/sphinx/arm/dhcp4-srv.rst index b44f74cc45..024687d5be 100644 --- a/doc/sphinx/arm/dhcp4-srv.rst +++ b/doc/sphinx/arm/dhcp4-srv.rst @@ -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`. diff --git a/doc/sphinx/arm/dhcp6-srv.rst b/doc/sphinx/arm/dhcp6-srv.rst index 5a4046212f..55a70d7528 100644 --- a/doc/sphinx/arm/dhcp6-srv.rst +++ b/doc/sphinx/arm/dhcp6-srv.rst @@ -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`. diff --git a/doc/sphinx/arm/stats.rst b/doc/sphinx/arm/stats.rst index 06924512fe..23404cdc70 100644 --- a/doc/sphinx/arm/stats.rst +++ b/doc/sphinx/arm/stats.rst @@ -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:: diff --git a/src/bin/dhcp4/tests/ctrl_dhcp4_srv_unittest.cc b/src/bin/dhcp4/tests/ctrl_dhcp4_srv_unittest.cc index f06f62cf27..e6598b20ad 100644 --- a/src/bin/dhcp4/tests/ctrl_dhcp4_srv_unittest.cc +++ b/src/bin/dhcp4/tests/ctrl_dhcp4_srv_unittest.cc @@ -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 }"; diff --git a/src/bin/dhcp6/dhcp6_srv.cc b/src/bin/dhcp6/dhcp6_srv.cc index a82a0e634e..3da15808e7 100644 --- a/src/bin/dhcp6/dhcp6_srv.cc +++ b/src/bin/dhcp6/dhcp6_srv.cc @@ -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 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(0)); - isc::stats::StatsMgr::instance().setValue("pkt6-solicit-received", - static_cast(0)); - isc::stats::StatsMgr::instance().setValue("pkt6-advertise-received", - static_cast(0)); - isc::stats::StatsMgr::instance().setValue("pkt6-request-received", - static_cast(0)); - isc::stats::StatsMgr::instance().setValue("pkt6-reply-received", - static_cast(0)); - isc::stats::StatsMgr::instance().setValue("pkt6-renew-received", - static_cast(0)); - isc::stats::StatsMgr::instance().setValue("pkt6-rebind-received", - static_cast(0)); - isc::stats::StatsMgr::instance().setValue("pkt6-release-received", - static_cast(0)); - isc::stats::StatsMgr::instance().setValue("pkt6-decline-received", - static_cast(0)); - isc::stats::StatsMgr::instance().setValue("pkt6-infrequest-received", - static_cast(0)); - isc::stats::StatsMgr::instance().setValue("pkt6-dhcpv4-query-received", - static_cast(0)); - isc::stats::StatsMgr::instance().setValue("pkt6-dhcpv4-response-received", - static_cast(0)); - isc::stats::StatsMgr::instance().setValue("pkt6-unknown-received", - static_cast(0)); - - isc::stats::StatsMgr::instance().setValue("pkt6-sent", - static_cast(0)); - isc::stats::StatsMgr::instance().setValue("pkt6-advertise-sent", - static_cast(0)); - isc::stats::StatsMgr::instance().setValue("pkt6-reply-sent", - static_cast(0)); - isc::stats::StatsMgr::instance().setValue("pkt6-dhcpv4-response-sent", - static_cast(0)); - - isc::stats::StatsMgr::instance().setValue("pkt6-parse-failed", - static_cast(0)); - isc::stats::StatsMgr::instance().setValue("pkt6-receive-drop", - static_cast(0)); - - isc::stats::StatsMgr::instance().setValue("reclaimed-leases", - static_cast(0)); - isc::stats::StatsMgr::instance().setValue("declined-addresses", - static_cast(0)); - isc::stats::StatsMgr::instance().setValue("reclaimed-declined-addresses", - static_cast(0)); + // Initializing all observations with default value + setPacketStatisticsDefaults(); + // All done, so can proceed shutdown_ = false; } +void Dhcpv6Srv::setPacketStatisticsDefaults() { + std::set::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(0)); + } +} + Dhcpv6Srv::~Dhcpv6Srv() { discardPackets(); try { diff --git a/src/bin/dhcp6/dhcp6_srv.h b/src/bin/dhcp6/dhcp6_srv.h index e421832d03..3e44bd0113 100644 --- a/src/bin/dhcp6/dhcp6_srv.h +++ b/src/bin/dhcp6/dhcp6_srv.h @@ -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, diff --git a/src/bin/dhcp6/tests/ctrl_dhcp6_srv_unittest.cc b/src/bin/dhcp6/tests/ctrl_dhcp6_srv_unittest.cc index 8cdb0a4f62..9fff87a2bc 100644 --- a/src/bin/dhcp6/tests/ctrl_dhcp6_srv_unittest.cc +++ b/src/bin/dhcp6/tests/ctrl_dhcp6_srv_unittest.cc @@ -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 }";