From: Franciszek Gorski Date: Wed, 17 Jul 2019 17:13:26 +0000 (+0200) Subject: [731-Kea_statistics_enhancements] new statistics commands X-Git-Tag: Kea-1.6.1~10^2~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7e90410c33f93e428e1d5fd9825ef8c70a128282;p=thirdparty%2Fkea.git [731-Kea_statistics_enhancements] new statistics commands --- diff --git a/src/bin/dhcp4/ctrl_dhcp4_srv.cc b/src/bin/dhcp4/ctrl_dhcp4_srv.cc index b74f149f7d..a6af5b3146 100644 --- a/src/bin/dhcp4/ctrl_dhcp4_srv.cc +++ b/src/bin/dhcp4/ctrl_dhcp4_srv.cc @@ -864,6 +864,19 @@ ControlledDhcpv4Srv::ControlledDhcpv4Srv(uint16_t server_port /*= DHCP4_SERVER_P CommandMgr::instance().registerCommand("statistic-remove-all", boost::bind(&StatsMgr::statisticRemoveAllHandler, _1, _2)); + CommandMgr::instance().registerCommand("statistic-set-max-sample-age", + boost::bind(&StatsMgr::statisticSetMaxSampleAgeHandler, _1, _2)); + + CommandMgr::instance().registerCommand("statistic-set-max-sample-count", + boost::bind(&StatsMgr::statisticSetMaxSampleCountHandler, _1, _2)); + + CommandMgr::instance().registerCommand("statistic-set-max-sample-age-all", + boost::bind(&StatsMgr::statisticSetMaxSampleAgeAllHandler, _1, _2)); + + CommandMgr::instance().registerCommand("statistic-set-max-sample-count-all", + boost::bind(&StatsMgr::statisticSetMaxSampleCountAllHandler, _1, _2)); + + } void ControlledDhcpv4Srv::shutdown() { @@ -903,8 +916,13 @@ ControlledDhcpv4Srv::~ControlledDhcpv4Srv() { CommandMgr::instance().deregisterCommand("statistic-remove-all"); CommandMgr::instance().deregisterCommand("statistic-reset"); CommandMgr::instance().deregisterCommand("statistic-reset-all"); + CommandMgr::instance().deregisterCommand("statistic-set-max-sample-age"); + CommandMgr::instance().deregisterCommand("statistic-set-max-sample-count"); + CommandMgr::instance().deregisterCommand("statistic-set-max-sample-age-all"); + CommandMgr::instance().deregisterCommand("statistic-set-max-sample-count-all"); CommandMgr::instance().deregisterCommand("version-get"); + } catch (...) { // Don't want to throw exceptions from the destructor. The server // is shutting down anyway. diff --git a/src/bin/dhcp4/tests/ctrl_dhcp4_srv_unittest.cc b/src/bin/dhcp4/tests/ctrl_dhcp4_srv_unittest.cc index 9a0cc3ee63..9aed6c6147 100644 --- a/src/bin/dhcp4/tests/ctrl_dhcp4_srv_unittest.cc +++ b/src/bin/dhcp4/tests/ctrl_dhcp4_srv_unittest.cc @@ -491,6 +491,10 @@ TEST_F(CtrlChannelDhcpv4SrvTest, commandsRegistration) { EXPECT_TRUE(command_list.find("\"statistic-remove-all\"") != string::npos); EXPECT_TRUE(command_list.find("\"statistic-reset\"") != string::npos); EXPECT_TRUE(command_list.find("\"statistic-reset-all\"") != string::npos); + EXPECT_TRUE(command_list.find("\"statistic-set-max-sample-age\"") != string::npos); + EXPECT_TRUE(command_list.find("\"statistic-set-max-sample-age-all\"") != string::npos); + EXPECT_TRUE(command_list.find("\"statistic-set-max-sample-count\"") != string::npos); + EXPECT_TRUE(command_list.find("\"statistic-set-max-sample-count-all\"") != string::npos); EXPECT_TRUE(command_list.find("\"version-get\"") != string::npos); // Ok, and now delete the server. It should deregister its commands. @@ -709,6 +713,34 @@ TEST_F(CtrlChannelDhcpv4SrvTest, controlChannelStats) { " \"arguments\": {}}", response); EXPECT_EQ("{ \"result\": 0, \"text\": \"All statistics removed.\" }", response); + + // Check statistic-set-max-sample-age + sendUnixCommand("{ \"command\" : \"statistic-set-max-sample-age\", " + " \"arguments\": {" + " \"name\":\"bogus\", \"duration\": 1245 }}", response); + EXPECT_EQ("{ \"result\": 1, \"text\": \"No 'bogus' statistic found\" }", + response); + + // Check statistic-set-max-sample-age-all + sendUnixCommand("{ \"command\" : \"statistic-set-max-sample-age-all\", " + " \"arguments\": {" + " \"duration\": 1245 }}", response); + EXPECT_EQ("{ \"result\": 0, \"text\": \"All statistics duration limit are set.\" }", + response); + + // Check statistic-set-max-sample-count + sendUnixCommand("{ \"command\" : \"statistic-set-max-sample-count\", " + " \"arguments\": {" + " \"name\":\"bogus\", \"max-samples\": 100 }}", response); + EXPECT_EQ("{ \"result\": 1, \"text\": \"No 'bogus' statistic found\" }", + response); + + // Check statistic-set-max-sample-count-all + sendUnixCommand("{ \"command\" : \"statistic-set-max-sample-count-all\", " + " \"arguments\": {" + " \"max-samples\": 100 }}", response); + EXPECT_EQ("{ \"result\": 0, \"text\": \"All statistics count limit are set.\" }", + response); } // Check that the "config-set" command will replace current configuration @@ -883,6 +915,10 @@ TEST_F(CtrlChannelDhcpv4SrvTest, listCommands) { checkListCommands(rsp, "statistic-remove-all"); checkListCommands(rsp, "statistic-reset"); checkListCommands(rsp, "statistic-reset-all"); + checkListCommands(rsp, "statistic-set-max-sample-age"); + checkListCommands(rsp, "statistic-set-max-sample-age-all"); + checkListCommands(rsp, "statistic-set-max-sample-count"); + checkListCommands(rsp, "statistic-set-max-sample-count-all"); checkListCommands(rsp, "version-get"); } diff --git a/src/bin/dhcp6/ctrl_dhcp6_srv.cc b/src/bin/dhcp6/ctrl_dhcp6_srv.cc index aba2e9b091..6d4a74b3d1 100644 --- a/src/bin/dhcp6/ctrl_dhcp6_srv.cc +++ b/src/bin/dhcp6/ctrl_dhcp6_srv.cc @@ -887,6 +887,18 @@ ControlledDhcpv6Srv::ControlledDhcpv6Srv(uint16_t server_port, CommandMgr::instance().registerCommand("statistic-remove-all", boost::bind(&StatsMgr::statisticRemoveAllHandler, _1, _2)); + + CommandMgr::instance().registerCommand("statistic-set-max-sample-age", + boost::bind(&StatsMgr::statisticSetMaxSampleAgeHandler, _1, _2)); + + CommandMgr::instance().registerCommand("statistic-set-max-sample-count", + boost::bind(&StatsMgr::statisticSetMaxSampleCountHandler, _1, _2)); + + CommandMgr::instance().registerCommand("statistic-set-max-sample-age-all", + boost::bind(&StatsMgr::statisticSetMaxSampleAgeAllHandler, _1, _2)); + + CommandMgr::instance().registerCommand("statistic-set-max-sample-count-all", + boost::bind(&StatsMgr::statisticSetMaxSampleCountAllHandler, _1, _2)); } void ControlledDhcpv6Srv::shutdown() { @@ -926,6 +938,10 @@ ControlledDhcpv6Srv::~ControlledDhcpv6Srv() { CommandMgr::instance().deregisterCommand("statistic-remove-all"); CommandMgr::instance().deregisterCommand("statistic-reset"); CommandMgr::instance().deregisterCommand("statistic-reset-all"); + CommandMgr::instance().deregisterCommand("statistic-set-max-sample-age"); + CommandMgr::instance().deregisterCommand("statistic-set-max-sample-count"); + CommandMgr::instance().deregisterCommand("statistic-set-max-sample-age-all"); + CommandMgr::instance().deregisterCommand("statistic-set-max-sample-count-all"); CommandMgr::instance().deregisterCommand("version-get"); } catch (...) { diff --git a/src/bin/dhcp6/tests/ctrl_dhcp6_srv_unittest.cc b/src/bin/dhcp6/tests/ctrl_dhcp6_srv_unittest.cc index d0dfb536e8..733ca4e8f1 100644 --- a/src/bin/dhcp6/tests/ctrl_dhcp6_srv_unittest.cc +++ b/src/bin/dhcp6/tests/ctrl_dhcp6_srv_unittest.cc @@ -798,6 +798,10 @@ TEST_F(CtrlDhcpv6SrvTest, commandsRegistration) { EXPECT_TRUE(command_list.find("\"statistic-remove-all\"") != string::npos); EXPECT_TRUE(command_list.find("\"statistic-reset\"") != string::npos); EXPECT_TRUE(command_list.find("\"statistic-reset-all\"") != string::npos); + EXPECT_TRUE(command_list.find("\"statistic-set-max-sample-age\"") != string::npos); + EXPECT_TRUE(command_list.find("\"statistic-set-max-sample-age-all\"") != string::npos); + EXPECT_TRUE(command_list.find("\"statistic-set-max-sample-count\"") != string::npos); + EXPECT_TRUE(command_list.find("\"statistic-set-max-sample-count-all\"") != string::npos); EXPECT_TRUE(command_list.find("\"version-get\"") != string::npos); // Ok, and now delete the server. It should deregister its commands. @@ -1023,6 +1027,34 @@ TEST_F(CtrlChannelDhcpv6SrvTest, controlChannelStats) { " \"arguments\": {}}", response); EXPECT_EQ("{ \"result\": 0, \"text\": \"All statistics removed.\" }", response); + + // Check statistic-set-max-sample-age + sendUnixCommand("{ \"command\" : \"statistic-set-max-sample-age\", " + " \"arguments\": {" + " \"name\":\"bogus\", \"duration\": 1245 }}", response); + EXPECT_EQ("{ \"result\": 1, \"text\": \"No 'bogus' statistic found\" }", + response); + + // Check statistic-set-max-sample-age-all + sendUnixCommand("{ \"command\" : \"statistic-set-max-sample-age-all\", " + " \"arguments\": {" + " \"duration\": 1245 }}", response); + EXPECT_EQ("{ \"result\": 0, \"text\": \"All statistics duration limit are set.\" }", + response); + + // Check statistic-set-max-sample-count + sendUnixCommand("{ \"command\" : \"statistic-set-max-sample-count\", " + " \"arguments\": {" + " \"name\":\"bogus\", \"max-samples\": 100 }}", response); + EXPECT_EQ("{ \"result\": 1, \"text\": \"No 'bogus' statistic found\" }", + response); + + // Check statistic-set-max-sample-count-all + sendUnixCommand("{ \"command\" : \"statistic-set-max-sample-count-all\", " + " \"arguments\": {" + " \"max-samples\": 100 }}", response); + EXPECT_EQ("{ \"result\": 0, \"text\": \"All statistics count limit are set.\" }", + response); } // Tests that the server properly responds to shtudown command sent @@ -1054,6 +1086,10 @@ TEST_F(CtrlChannelDhcpv6SrvTest, commandsList) { checkListCommands(rsp, "statistic-remove-all"); checkListCommands(rsp, "statistic-reset"); checkListCommands(rsp, "statistic-reset-all"); + checkListCommands(rsp, "statistic-set-max-sample-age"); + checkListCommands(rsp, "statistic-set-max-sample-age-all"); + checkListCommands(rsp, "statistic-set-max-sample-count"); + checkListCommands(rsp, "statistic-set-max-sample-count-all"); } // Tests if the server returns its configuration using config-get.