2
0
mirror of https://gitlab.isc.org/isc-projects/kea synced 2025-08-30 13:37:55 +00:00

[755-Kea-DHCP-servers-observations-should-be-reset] implement required changes to dhcp4 and dhcp6 servers

This commit is contained in:
Franciszek Gorski
2019-09-05 09:35:19 +02:00
committed by Marcin Siodelski
parent 61cda1b5e1
commit 3a92d22727
7 changed files with 66 additions and 76 deletions

View File

@@ -5510,6 +5510,10 @@ following statistics-related commands:
- statistic-get-all - statistic-get-all
- statistic-reset-all - statistic-reset-all
- statistic-remove-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`. as described in :ref:`command-stats`.

View File

@@ -5524,6 +5524,10 @@ following statistics-related commands:
- statistic-get-all - statistic-get-all
- statistic-reset-all - statistic-reset-all
- statistic-remove-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`. as described in :ref:`command-stats`.

View File

@@ -52,15 +52,16 @@ for a list of statistics-oriented commands.
Statistics Lifecycle Statistics Lifecycle
==================== ====================
It is useful to understand how the Statistics Manager module works. When It is useful to understand how the Statistics Manager module works.
the server starts operation, the manager is empty and contains no Since Kea 1.7.0 when the server starts operation, the manager contains
statistics. If the ``statistic-get-all`` command is executed at that point, an empty list is all statistics related to runned type of DHCP server, initialized with
returned. Once the server performs an operation that causes a statistic default value. If the ``statistic-get-all`` command is executed at that point,
to change, the related statistic will be created. In general, once a a list with these statistics is returned. Once the server performs an operation
statistic is recorded even once, it is kept in the manager until that causes a statistic to change, the related statistic will be created or updated.
explicitly removed, by ``statistic-remove`` or ``statistic-remove-all`` In general, once a statistic is recorded even once, it is kept in the manager
being called, or when the server is shut down. Per-subnet statistics are until explicitly removed, by ``statistic-remove`` or ``statistic-remove-all``
explicitly removed when reconfiguration takes place. 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 Statistics are considered runtime properties, so they are not retained
after server restart. after server restart.
@@ -84,14 +85,16 @@ Commands for Manipulating Statistics
There are several commands defined that can be used for accessing There are several commands defined that can be used for accessing
(-get), resetting to zero or a neutral value (-reset), or removing a (-get), resetting to zero or a neutral value (-reset), or removing a
statistic completely (-remove). The difference between reset and remove statistic completely (-remove). We can change the statistics time based
is somewhat subtle. The reset command sets the value of the statistic to limit (-sample-age-set) and size based limit (-sample-count-set).
zero or a neutral value, so after this operation, the statistic will The difference between reset and remove is somewhat subtle.
have a value of 0 (integer), 0.0 (float), 0h0m0s0us (duration), or "" The reset command sets the value of the statistic to zero or a neutral value,
(string). When requested, a statistic with the values mentioned will be so after this operation, the statistic will have a value of 0 (integer),
returned. ``Remove`` removes a statistic completely, so the statistic 0.0 (float), 0h0m0s0us (duration), or "" (string).
will no longer be reported. Please note that the server code may add When requested, a statistic with the values mentioned will be returned.
it back if there is a reason to record it. ``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:: .. note::

View File

@@ -554,8 +554,6 @@ TEST_F(CtrlChannelDhcpv4SrvTest, controlChannelStats) {
// preparing the schema which check if all statistics are set to zero // preparing the schema which check if all statistics are set to zero
std::string stats_get_all = "{ \"arguments\": { " 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") "\"pkt4-ack-received\": [ [ 0, \"" + isc::util::ptimeToText(StatsMgr::instance().getObservation("pkt4-ack-received")
->getInteger().second) + "\" ] ], " ->getInteger().second) + "\" ] ], "
"\"pkt4-ack-sent\": [ [ 0, \"" + isc::util::ptimeToText(StatsMgr::instance().getObservation("pkt4-ack-sent") "\"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") "\"pkt4-sent\": [ [ 0, \"" + isc::util::ptimeToText(StatsMgr::instance().getObservation("pkt4-sent")
->getInteger().second) + "\" ] ], " ->getInteger().second) + "\" ] ], "
"\"pkt4-unknown-received\": [ [ 0, \"" + isc::util::ptimeToText(StatsMgr::instance().getObservation("pkt4-unknown-received") "\"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) + "\" ] ] }, " ->getInteger().second) + "\" ] ] }, "
"\"result\": 0 }"; "\"result\": 0 }";

View File

@@ -172,6 +172,28 @@ createStatusCode(const Pkt6& pkt, const Option6IA& ia, const uint16_t status_cod
return (option_status); 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 }; // anonymous namespace
namespace isc { 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()); LOG_ERROR(dhcp6_logger, DHCP6_SRV_CONSTRUCT_ERROR).arg(e.what());
return; return;
} }
// Initializing all observations with zero value // Initializing all observations with default value
isc::stats::StatsMgr::instance().setValue("pkt6-received", setPacketStatisticsDefaults();
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));
// All done, so can proceed // All done, so can proceed
shutdown_ = false; 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() { Dhcpv6Srv::~Dhcpv6Srv() {
discardPackets(); discardPackets();
try { try {

View File

@@ -89,6 +89,9 @@ public:
/// @brief Destructor. Used during DHCPv6 service shutdown. /// @brief Destructor. Used during DHCPv6 service shutdown.
virtual ~Dhcpv6Srv(); 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. /// @brief Checks if the server is running in unit test mode.
/// ///
/// @return true if the server is running in unit test mode, /// @return true if the server is running in unit test mode,

View File

@@ -1136,8 +1136,6 @@ TEST_F(CtrlChannelDhcpv6SrvTest, controlChannelStats) {
// preparing the schema which check if all statistics are set to zero // preparing the schema which check if all statistics are set to zero
std::string stats_get_all = "{ \"arguments\": { " 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") "\"pkt6-advertise-received\": [ [ 0, \"" + isc::util::ptimeToText(StatsMgr::instance().getObservation("pkt6-advertise-received")
->getInteger().second) + "\" ] ], " ->getInteger().second) + "\" ] ], "
"\"pkt6-advertise-sent\": [ [ 0, \"" + isc::util::ptimeToText(StatsMgr::instance().getObservation("pkt6-advertise-sent") "\"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") "\"pkt6-solicit-received\": [ [ 0, \"" + isc::util::ptimeToText(StatsMgr::instance().getObservation("pkt6-solicit-received")
->getInteger().second) + "\" ] ], " ->getInteger().second) + "\" ] ], "
"\"pkt6-unknown-received\": [ [ 0, \"" + isc::util::ptimeToText(StatsMgr::instance().getObservation("pkt6-unknown-received") "\"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) + "\" ] ] }, " ->getInteger().second) + "\" ] ] }, "
"\"result\": 0 }"; "\"result\": 0 }";