From: Razvan Becheriu Date: Tue, 11 Aug 2020 07:55:58 +0000 (+0300) Subject: [#1305] add thread and queue info to get-status command X-Git-Tag: Kea-1.8.0~37 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dc4e001199c29ff6c8330bbdd38adb5ac63ab221;p=thirdparty%2Fkea.git [#1305] add thread and queue info to get-status command --- diff --git a/src/bin/dhcp4/ctrl_dhcp4_srv.cc b/src/bin/dhcp4/ctrl_dhcp4_srv.cc index 9b1deefeaf..f6a06b8a89 100644 --- a/src/bin/dhcp4/ctrl_dhcp4_srv.cc +++ b/src/bin/dhcp4/ctrl_dhcp4_srv.cc @@ -660,7 +660,12 @@ ControlledDhcpv4Srv::commandStatusGetHandler(const string&, status->set("reload", Element::create(reload.total_seconds())); } - // todo: number of service threads. + if (MultiThreadingMgr::instance().getMode()) { + status->set("thread-pool-size", Element::create( + long(MultiThreadingMgr::instance().getThreadPoolSize()))); + status->set("packet-queue-size", Element::create( + long(MultiThreadingMgr::instance().getPacketQueueSize()))); + } return (createAnswer(0, status)); } diff --git a/src/bin/dhcp4/tests/ctrl_dhcp4_srv_unittest.cc b/src/bin/dhcp4/tests/ctrl_dhcp4_srv_unittest.cc index 9ebb1ab23b..22efe381e0 100644 --- a/src/bin/dhcp4/tests/ctrl_dhcp4_srv_unittest.cc +++ b/src/bin/dhcp4/tests/ctrl_dhcp4_srv_unittest.cc @@ -1119,6 +1119,47 @@ TEST_F(CtrlChannelDhcpv4SrvTest, statusGet) { ASSERT_TRUE(found_reload); EXPECT_LE(found_reload->intValue(), 5); EXPECT_GE(found_reload->intValue(), 0); + + MultiThreadingMgr::instance().setMode(true); + MultiThreadingMgr::instance().setThreadPoolSize(4); + MultiThreadingMgr::instance().setPacketQueueSize(64); + sendUnixCommand("{ \"command\": \"status-get\" }", response_txt); + ASSERT_NO_THROW(response = Element::fromJSON(response_txt)); + ASSERT_TRUE(response); + ASSERT_EQ(Element::map, response->getType()); + EXPECT_EQ(2, response->size()); + result = response->get("result"); + ASSERT_TRUE(result); + ASSERT_EQ(Element::integer, result->getType()); + EXPECT_EQ(0, result->intValue()); + arguments = response->get("arguments"); + ASSERT_EQ(Element::map, arguments->getType()); + + // The returned pid should be the pid of our process. + found_pid = arguments->get("pid"); + ASSERT_TRUE(found_pid); + EXPECT_EQ(static_cast(getpid()), found_pid->intValue()); + + // It is hard to check the actual uptime (and reload) as it is based + // on current time. Let's just make sure it is within a reasonable + // range. + found_uptime = arguments->get("uptime"); + ASSERT_TRUE(found_uptime); + EXPECT_LE(found_uptime->intValue(), 5); + EXPECT_GE(found_uptime->intValue(), 0); + + found_reload = arguments->get("reload"); + ASSERT_TRUE(found_reload); + EXPECT_LE(found_reload->intValue(), 5); + EXPECT_GE(found_reload->intValue(), 0); + + auto found_thread_count = arguments->get("thread-pool-size"); + ASSERT_TRUE(found_thread_count); + EXPECT_EQ(found_thread_count->intValue(), 4); + + auto found_queue_size = arguments->get("packet-queue-size"); + ASSERT_TRUE(found_queue_size); + EXPECT_EQ(found_queue_size->intValue(), 64); } // This test verifies that the DHCP server handles config-backend-pull command diff --git a/src/bin/dhcp6/ctrl_dhcp6_srv.cc b/src/bin/dhcp6/ctrl_dhcp6_srv.cc index 1b73cb83b3..7a316363dd 100644 --- a/src/bin/dhcp6/ctrl_dhcp6_srv.cc +++ b/src/bin/dhcp6/ctrl_dhcp6_srv.cc @@ -663,7 +663,12 @@ ControlledDhcpv6Srv::commandStatusGetHandler(const string&, status->set("reload", Element::create(reload.total_seconds())); } - // todo: number of service threads. + if (MultiThreadingMgr::instance().getMode()) { + status->set("thread-pool-size", Element::create( + long(MultiThreadingMgr::instance().getThreadPoolSize()))); + status->set("packet-queue-size", Element::create( + long(MultiThreadingMgr::instance().getPacketQueueSize()))); + } return (createAnswer(0, status)); } diff --git a/src/bin/dhcp6/tests/ctrl_dhcp6_srv_unittest.cc b/src/bin/dhcp6/tests/ctrl_dhcp6_srv_unittest.cc index c0ac48da0f..ac6ea65c7c 100644 --- a/src/bin/dhcp6/tests/ctrl_dhcp6_srv_unittest.cc +++ b/src/bin/dhcp6/tests/ctrl_dhcp6_srv_unittest.cc @@ -1009,6 +1009,47 @@ TEST_F(CtrlChannelDhcpv6SrvTest, statusGet) { ASSERT_TRUE(found_reload); EXPECT_LE(found_reload->intValue(), 5); EXPECT_GE(found_reload->intValue(), 0); + + MultiThreadingMgr::instance().setMode(true); + MultiThreadingMgr::instance().setThreadPoolSize(4); + MultiThreadingMgr::instance().setPacketQueueSize(64); + sendUnixCommand("{ \"command\": \"status-get\" }", response_txt); + ASSERT_NO_THROW(response = Element::fromJSON(response_txt)); + ASSERT_TRUE(response); + ASSERT_EQ(Element::map, response->getType()); + EXPECT_EQ(2, response->size()); + result = response->get("result"); + ASSERT_TRUE(result); + ASSERT_EQ(Element::integer, result->getType()); + EXPECT_EQ(0, result->intValue()); + arguments = response->get("arguments"); + ASSERT_EQ(Element::map, arguments->getType()); + + // The returned pid should be the pid of our process. + found_pid = arguments->get("pid"); + ASSERT_TRUE(found_pid); + EXPECT_EQ(static_cast(getpid()), found_pid->intValue()); + + // It is hard to check the actual uptime (and reload) as it is based + // on current time. Let's just make sure it is within a reasonable + // range. + found_uptime = arguments->get("uptime"); + ASSERT_TRUE(found_uptime); + EXPECT_LE(found_uptime->intValue(), 5); + EXPECT_GE(found_uptime->intValue(), 0); + + found_reload = arguments->get("reload"); + ASSERT_TRUE(found_reload); + EXPECT_LE(found_reload->intValue(), 5); + EXPECT_GE(found_reload->intValue(), 0); + + auto found_thread_count = arguments->get("thread-pool-size"); + ASSERT_TRUE(found_thread_count); + EXPECT_EQ(found_thread_count->intValue(), 4); + + auto found_queue_size = arguments->get("packet-queue-size"); + ASSERT_TRUE(found_queue_size); + EXPECT_EQ(found_queue_size->intValue(), 64); } // This test verifies that the DHCP server handles server-tag-get command