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:
committed by
Marcin Siodelski
parent
61cda1b5e1
commit
3a92d22727
@@ -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`.
|
||||
|
||||
|
@@ -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`.
|
||||
|
||||
|
@@ -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::
|
||||
|
||||
|
@@ -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 }";
|
||||
|
||||
|
@@ -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));
|
||||
// Initializing all observations with default value
|
||||
setPacketStatisticsDefaults();
|
||||
|
||||
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
|
||||
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 {
|
||||
|
@@ -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,
|
||||
|
@@ -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 }";
|
||||
|
||||
|
Reference in New Issue
Block a user