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

[731-Kea_statistics_enhancements] new statistics commands

This commit is contained in:
Franciszek Gorski 2019-07-17 19:13:26 +02:00 committed by Razvan Becheriu
parent cdf12c6612
commit 7e90410c33
4 changed files with 106 additions and 0 deletions

View File

@ -864,6 +864,19 @@ ControlledDhcpv4Srv::ControlledDhcpv4Srv(uint16_t server_port /*= DHCP4_SERVER_P
CommandMgr::instance().registerCommand("statistic-remove-all", CommandMgr::instance().registerCommand("statistic-remove-all",
boost::bind(&StatsMgr::statisticRemoveAllHandler, _1, _2)); 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() { void ControlledDhcpv4Srv::shutdown() {
@ -903,8 +916,13 @@ ControlledDhcpv4Srv::~ControlledDhcpv4Srv() {
CommandMgr::instance().deregisterCommand("statistic-remove-all"); CommandMgr::instance().deregisterCommand("statistic-remove-all");
CommandMgr::instance().deregisterCommand("statistic-reset"); CommandMgr::instance().deregisterCommand("statistic-reset");
CommandMgr::instance().deregisterCommand("statistic-reset-all"); 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"); CommandMgr::instance().deregisterCommand("version-get");
} catch (...) { } catch (...) {
// Don't want to throw exceptions from the destructor. The server // Don't want to throw exceptions from the destructor. The server
// is shutting down anyway. // is shutting down anyway.

View File

@ -491,6 +491,10 @@ TEST_F(CtrlChannelDhcpv4SrvTest, commandsRegistration) {
EXPECT_TRUE(command_list.find("\"statistic-remove-all\"") != string::npos); 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\"") != string::npos);
EXPECT_TRUE(command_list.find("\"statistic-reset-all\"") != 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); EXPECT_TRUE(command_list.find("\"version-get\"") != string::npos);
// Ok, and now delete the server. It should deregister its commands. // Ok, and now delete the server. It should deregister its commands.
@ -709,6 +713,34 @@ TEST_F(CtrlChannelDhcpv4SrvTest, controlChannelStats) {
" \"arguments\": {}}", response); " \"arguments\": {}}", response);
EXPECT_EQ("{ \"result\": 0, \"text\": \"All statistics removed.\" }", EXPECT_EQ("{ \"result\": 0, \"text\": \"All statistics removed.\" }",
response); 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 // 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-remove-all");
checkListCommands(rsp, "statistic-reset"); checkListCommands(rsp, "statistic-reset");
checkListCommands(rsp, "statistic-reset-all"); 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"); checkListCommands(rsp, "version-get");
} }

View File

@ -887,6 +887,18 @@ ControlledDhcpv6Srv::ControlledDhcpv6Srv(uint16_t server_port,
CommandMgr::instance().registerCommand("statistic-remove-all", CommandMgr::instance().registerCommand("statistic-remove-all",
boost::bind(&StatsMgr::statisticRemoveAllHandler, _1, _2)); 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() { void ControlledDhcpv6Srv::shutdown() {
@ -926,6 +938,10 @@ ControlledDhcpv6Srv::~ControlledDhcpv6Srv() {
CommandMgr::instance().deregisterCommand("statistic-remove-all"); CommandMgr::instance().deregisterCommand("statistic-remove-all");
CommandMgr::instance().deregisterCommand("statistic-reset"); CommandMgr::instance().deregisterCommand("statistic-reset");
CommandMgr::instance().deregisterCommand("statistic-reset-all"); 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"); CommandMgr::instance().deregisterCommand("version-get");
} catch (...) { } catch (...) {

View File

@ -798,6 +798,10 @@ TEST_F(CtrlDhcpv6SrvTest, commandsRegistration) {
EXPECT_TRUE(command_list.find("\"statistic-remove-all\"") != string::npos); 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\"") != string::npos);
EXPECT_TRUE(command_list.find("\"statistic-reset-all\"") != 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); EXPECT_TRUE(command_list.find("\"version-get\"") != string::npos);
// Ok, and now delete the server. It should deregister its commands. // Ok, and now delete the server. It should deregister its commands.
@ -1023,6 +1027,34 @@ TEST_F(CtrlChannelDhcpv6SrvTest, controlChannelStats) {
" \"arguments\": {}}", response); " \"arguments\": {}}", response);
EXPECT_EQ("{ \"result\": 0, \"text\": \"All statistics removed.\" }", EXPECT_EQ("{ \"result\": 0, \"text\": \"All statistics removed.\" }",
response); 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 // 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-remove-all");
checkListCommands(rsp, "statistic-reset"); checkListCommands(rsp, "statistic-reset");
checkListCommands(rsp, "statistic-reset-all"); 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. // Tests if the server returns its configuration using config-get.