From: Francis Dupont Date: Sun, 5 Apr 2020 14:17:51 +0000 (+0200) Subject: [#1005] Finished new default sample limits X-Git-Tag: Kea-1.7.7~76 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fe80ce65d15f1236265166556bd64bfa52504327;p=thirdparty%2Fkea.git [#1005] Finished new default sample limits --- diff --git a/ChangeLog b/ChangeLog index 7a38bc8dae..53629a4b92 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,10 @@ -1737. [func] tmark +1738. [func] fdupont + Added new global parameters statistic-default-sample-count and + statistic-default-sample-age to set the default values uses + a sample keeping limits in new statistics. + (Gitlab #1005) + +1737. [func] tmark Added store-extended-info parameter to kea-dhcp4 and kea-dhcp6 which enables the storage of additional information per lease. This has been added in anticipation of supporting LeaseQuery. diff --git a/doc/sphinx/arm/dhcp4-srv.rst b/doc/sphinx/arm/dhcp4-srv.rst index a20e0a347a..de840d0ffa 100644 --- a/doc/sphinx/arm/dhcp4-srv.rst +++ b/doc/sphinx/arm/dhcp4-srv.rst @@ -5310,6 +5310,34 @@ Statistics in the DHCPv4 Server This section describes DHCPv4-specific statistics. For a general overview and usage of statistics, see :ref:`stats`. +Beginning with Kea 1.7.7 the DHCPv4 server provides two global +parameters to control statistics default sample limits: + +- ``statistic-default-sample-count`` - determines the default maximum + number of samples which will be kept. The special value of zero + means to use a default maximum age. + +- ``statistic-default-sample-age`` - determines the default maximum + age in seconds of samples which will be kept. + +.. note:: + + These apply to default values and have no action on existing statistics. + To change sample limits on an existing (or all) statistic use commands + of the dedicated hook described in :ref:`command-statistic-sample-count-set` + and :ref:`command-statistic-sample-age-set-all`. + +For instance to reduce the statistic keeping overhead you can set +the default maximum sample count to 1 so only one sample will be kept by: + +:: + + "Dhcp4": { + "statistic-default-sample-count": 1, + "subnet4": [ ... ], + ... + } + The DHCPv4 server supports the following statistics: .. tabularcolumns:: |p{0.2\linewidth}|p{0.1\linewidth}|p{0.7\linewidth}| diff --git a/doc/sphinx/arm/dhcp6-srv.rst b/doc/sphinx/arm/dhcp6-srv.rst index 6304247515..55e579463e 100644 --- a/doc/sphinx/arm/dhcp6-srv.rst +++ b/doc/sphinx/arm/dhcp6-srv.rst @@ -5186,6 +5186,34 @@ Statistics in the DHCPv6 Server This section describes DHCPv6-specific statistics. For a general overview and usage of statistics, see :ref:`stats`. +Beginning with Kea 1.7.7 the DHCPv6 server provides two global +parameters to control statistics default sample limits: + +- ``statistic-default-sample-count`` - determines the default maximum + number of samples which will be kept. The special value of zero + means to use a default maximum age. + +- ``statistic-default-sample-age`` - determines the default maximum + age in seconds of samples which will be kept. + +.. note:: + + These apply to default values and have no action on existing statistics. + To change sample limits on an existing (or all) statistic use commands + of the dedicated hook described in :ref:`command-statistic-sample-count-set` + and :ref:`command-statistic-sample-age-set-all`. + +For instance to reduce the statistic keeping overhead you can set +the default maximum sample count to 1 so only one sample will be kept by: + +:: + + "Dhcp6": { + "statistic-default-sample-count": 1, + "subnet6": [ ... ], + ... + } + The DHCPv6 server supports the following statistics: .. tabularcolumns:: |p{0.2\linewidth}|p{0.1\linewidth}|p{0.7\linewidth}| diff --git a/doc/sphinx/arm/stats.rst b/doc/sphinx/arm/stats.rst index 7a2f98c289..f86da080cd 100644 --- a/doc/sphinx/arm/stats.rst +++ b/doc/sphinx/arm/stats.rst @@ -90,6 +90,12 @@ There are several commands defined that can be used for accessing statistic completely (-remove). We can change the statistics time based limit (-sample-age-set) and size based limit (-sample-count-set) which control how long or how many samples of the given statistic are retained. + +This only applies for existing statistics: to change the default limits used +when a new statistic is created, for instance during server startup, +the statistic-default-sample-count and statistic-default-sample-age +global configuration parameters must be used. + 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), diff --git a/src/bin/dhcp4/tests/config_parser_unittest.cc b/src/bin/dhcp4/tests/config_parser_unittest.cc index acffb495e8..7114459825 100644 --- a/src/bin/dhcp4/tests/config_parser_unittest.cc +++ b/src/bin/dhcp4/tests/config_parser_unittest.cc @@ -29,6 +29,8 @@ #include #include #include +#include +#include #include #include "marker_file.h" @@ -7142,4 +7144,30 @@ TEST_F(Dhcp4ParserTest, storeExtendedInfoGlobal) { EXPECT_TRUE(subnet2->getStoreExtendedInfo()); } +/// This test checks that the statistic-default-sample-count and age +/// global parameters are committed to the stats manager as expected. +TEST_F(Dhcp4ParserTest, statsDefaultLimits) { + std::string config = "{ " + genIfaceConfig() + "," + + "\"rebind-timer\": 2000, " + "\"renew-timer\": 1000, " + "\"statistic-default-sample-count\": 10, " + "\"statistic-default-sample-age\": 5, " + "\"valid-lifetime\": 4000 }"; + + ConstElementPtr json; + ASSERT_NO_THROW(json = parseDHCP4(config)); + extractConfig(config); + + ConstElementPtr status; + ASSERT_NO_THROW(status = configureDhcp4Server(*srv_, json)); + checkResult(status, 0); + + CfgMgr::instance().commit(); + + stats::StatsMgr& stats_mgr = stats::StatsMgr::instance(); + EXPECT_EQ(10, stats_mgr.getMaxSampleCountDefault()); + EXPECT_EQ("00:00:05", + util::durationToText(stats_mgr.getMaxSampleAgeDefault(), 0)); +} + } diff --git a/src/bin/dhcp4/tests/get_config_unittest.cc b/src/bin/dhcp4/tests/get_config_unittest.cc index f4f27d6ed0..efb91465ce 100644 --- a/src/bin/dhcp4/tests/get_config_unittest.cc +++ b/src/bin/dhcp4/tests/get_config_unittest.cc @@ -2191,6 +2191,18 @@ const char* EXTRACTED_CONFIGS[] = { " }\n" " ],\n" " \"valid-lifetime\": 4000\n" +" }\n", + // CONFIGURATION 72 +"{\n" +" \"interfaces-config\": {\n" +" \"interfaces\": [ \"*\" ],\n" +" \"re-detect\": false\n" +" },\n" +" \"rebind-timer\": 2000,\n" +" \"renew-timer\": 1000,\n" +" \"statistic-default-sample-age\": 5,\n" +" \"statistic-default-sample-count\": 10,\n" +" \"valid-lifetime\": 4000\n" " }\n" }; @@ -2257,6 +2269,8 @@ const char* UNPARSED_CONFIGS[] = { " \"server-hostname\": \"\",\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet4\": [ ],\n" " \"t1-percent\": 0.5,\n" @@ -2323,6 +2337,8 @@ const char* UNPARSED_CONFIGS[] = { " \"server-hostname\": \"\",\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet4\": [\n" " {\n" @@ -2414,6 +2430,8 @@ const char* UNPARSED_CONFIGS[] = { " \"server-hostname\": \"\",\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet4\": [\n" " {\n" @@ -2508,6 +2526,8 @@ const char* UNPARSED_CONFIGS[] = { " \"server-hostname\": \"\",\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet4\": [\n" " {\n" @@ -2603,6 +2623,8 @@ const char* UNPARSED_CONFIGS[] = { " \"server-hostname\": \"\",\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet4\": [\n" " {\n" @@ -2771,6 +2793,8 @@ const char* UNPARSED_CONFIGS[] = { " \"server-hostname\": \"\",\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet4\": [\n" " {\n" @@ -2939,6 +2963,8 @@ const char* UNPARSED_CONFIGS[] = { " \"server-hostname\": \"foo\",\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet4\": [\n" " {\n" @@ -3032,6 +3058,8 @@ const char* UNPARSED_CONFIGS[] = { " \"server-hostname\": \"\",\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet4\": [\n" " {\n" @@ -3128,6 +3156,8 @@ const char* UNPARSED_CONFIGS[] = { " \"server-hostname\": \"nohost\",\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet4\": [\n" " {\n" @@ -3224,6 +3254,8 @@ const char* UNPARSED_CONFIGS[] = { " \"server-hostname\": \"\",\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet4\": [\n" " {\n" @@ -3317,6 +3349,8 @@ const char* UNPARSED_CONFIGS[] = { " \"server-hostname\": \"\",\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet4\": [\n" " {\n" @@ -3410,6 +3444,8 @@ const char* UNPARSED_CONFIGS[] = { " \"server-hostname\": \"\",\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet4\": [\n" " {\n" @@ -3530,6 +3566,8 @@ const char* UNPARSED_CONFIGS[] = { " \"server-hostname\": \"\",\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet4\": [\n" " {\n" @@ -3649,6 +3687,8 @@ const char* UNPARSED_CONFIGS[] = { " \"server-hostname\": \"\",\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet4\": [\n" " {\n" @@ -3769,6 +3809,8 @@ const char* UNPARSED_CONFIGS[] = { " \"server-hostname\": \"\",\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet4\": [\n" " {\n" @@ -3890,6 +3932,8 @@ const char* UNPARSED_CONFIGS[] = { " \"server-hostname\": \"\",\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet4\": [\n" " {\n" @@ -3985,6 +4029,8 @@ const char* UNPARSED_CONFIGS[] = { " \"server-hostname\": \"\",\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet4\": [\n" " {\n" @@ -4111,6 +4157,8 @@ const char* UNPARSED_CONFIGS[] = { " \"server-hostname\": \"\",\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet4\": [\n" " {\n" @@ -4212,6 +4260,8 @@ const char* UNPARSED_CONFIGS[] = { " \"server-hostname\": \"\",\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet4\": [ ],\n" " \"t1-percent\": 0.5,\n" @@ -4287,6 +4337,8 @@ const char* UNPARSED_CONFIGS[] = { " \"server-hostname\": \"\",\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet4\": [ ],\n" " \"t1-percent\": 0.5,\n" @@ -4371,6 +4423,8 @@ const char* UNPARSED_CONFIGS[] = { " \"server-hostname\": \"\",\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet4\": [ ],\n" " \"t1-percent\": 0.5,\n" @@ -4446,6 +4500,8 @@ const char* UNPARSED_CONFIGS[] = { " \"server-hostname\": \"\",\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet4\": [ ],\n" " \"t1-percent\": 0.5,\n" @@ -4521,6 +4577,8 @@ const char* UNPARSED_CONFIGS[] = { " \"server-hostname\": \"\",\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet4\": [ ],\n" " \"t1-percent\": 0.5,\n" @@ -4596,6 +4654,8 @@ const char* UNPARSED_CONFIGS[] = { " \"server-hostname\": \"\",\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet4\": [ ],\n" " \"t1-percent\": 0.5,\n" @@ -4671,6 +4731,8 @@ const char* UNPARSED_CONFIGS[] = { " \"server-hostname\": \"\",\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet4\": [ ],\n" " \"t1-percent\": 0.5,\n" @@ -4755,6 +4817,8 @@ const char* UNPARSED_CONFIGS[] = { " \"server-hostname\": \"\",\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet4\": [\n" " {\n" @@ -4848,6 +4912,8 @@ const char* UNPARSED_CONFIGS[] = { " \"server-hostname\": \"\",\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet4\": [\n" " {\n" @@ -4985,6 +5051,8 @@ const char* UNPARSED_CONFIGS[] = { " \"server-hostname\": \"\",\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet4\": [\n" " {\n" @@ -5114,6 +5182,8 @@ const char* UNPARSED_CONFIGS[] = { " \"server-hostname\": \"\",\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet4\": [ ],\n" " \"t1-percent\": 0.5,\n" @@ -5234,6 +5304,8 @@ const char* UNPARSED_CONFIGS[] = { " \"server-hostname\": \"\",\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet4\": [\n" " {\n" @@ -5336,6 +5408,8 @@ const char* UNPARSED_CONFIGS[] = { " \"server-hostname\": \"\",\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet4\": [\n" " {\n" @@ -5446,6 +5520,8 @@ const char* UNPARSED_CONFIGS[] = { " \"server-hostname\": \"\",\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet4\": [\n" " {\n" @@ -5582,6 +5658,8 @@ const char* UNPARSED_CONFIGS[] = { " \"server-hostname\": \"\",\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet4\": [\n" " {\n" @@ -5692,6 +5770,8 @@ const char* UNPARSED_CONFIGS[] = { " \"server-hostname\": \"\",\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet4\": [\n" " {\n" @@ -5824,6 +5904,8 @@ const char* UNPARSED_CONFIGS[] = { " \"server-hostname\": \"\",\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet4\": [\n" " {\n" @@ -5953,6 +6035,8 @@ const char* UNPARSED_CONFIGS[] = { " \"server-hostname\": \"\",\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet4\": [ ],\n" " \"t1-percent\": 0.5,\n" @@ -6064,6 +6148,8 @@ const char* UNPARSED_CONFIGS[] = { " \"server-hostname\": \"\",\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet4\": [\n" " {\n" @@ -6172,6 +6258,8 @@ const char* UNPARSED_CONFIGS[] = { " \"server-hostname\": \"\",\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet4\": [\n" " {\n" @@ -6284,6 +6372,8 @@ const char* UNPARSED_CONFIGS[] = { " \"server-hostname\": \"\",\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet4\": [\n" " {\n" @@ -6377,6 +6467,8 @@ const char* UNPARSED_CONFIGS[] = { " \"server-hostname\": \"\",\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet4\": [ ],\n" " \"t1-percent\": 0.5,\n" @@ -6444,6 +6536,8 @@ const char* UNPARSED_CONFIGS[] = { " \"server-hostname\": \"\",\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet4\": [ ],\n" " \"t1-percent\": 0.5,\n" @@ -6511,6 +6605,8 @@ const char* UNPARSED_CONFIGS[] = { " \"server-hostname\": \"\",\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet4\": [\n" " {\n" @@ -6604,6 +6700,8 @@ const char* UNPARSED_CONFIGS[] = { " \"server-hostname\": \"\",\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet4\": [\n" " {\n" @@ -6697,6 +6795,8 @@ const char* UNPARSED_CONFIGS[] = { " \"server-hostname\": \"\",\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet4\": [\n" " {\n" @@ -6790,6 +6890,8 @@ const char* UNPARSED_CONFIGS[] = { " \"server-hostname\": \"\",\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet4\": [\n" " {\n" @@ -6883,6 +6985,8 @@ const char* UNPARSED_CONFIGS[] = { " \"server-hostname\": \"\",\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet4\": [\n" " {\n" @@ -6976,6 +7080,8 @@ const char* UNPARSED_CONFIGS[] = { " \"server-hostname\": \"\",\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet4\": [\n" " {\n" @@ -7147,6 +7253,8 @@ const char* UNPARSED_CONFIGS[] = { " \"server-hostname\": \"\",\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet4\": [\n" " {\n" @@ -7255,6 +7363,8 @@ const char* UNPARSED_CONFIGS[] = { " \"server-hostname\": \"\",\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet4\": [\n" " {\n" @@ -7511,6 +7621,8 @@ const char* UNPARSED_CONFIGS[] = { " \"server-hostname\": \"\",\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet4\": [\n" " {\n" @@ -7624,6 +7736,8 @@ const char* UNPARSED_CONFIGS[] = { " \"server-hostname\": \"\",\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet4\": [\n" " {\n" @@ -7795,6 +7909,8 @@ const char* UNPARSED_CONFIGS[] = { " \"server-hostname\": \"\",\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet4\": [\n" " {\n" @@ -7912,6 +8028,8 @@ const char* UNPARSED_CONFIGS[] = { " \"server-hostname\": \"\",\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet4\": [ ],\n" " \"t1-percent\": 0.5,\n" @@ -7977,6 +8095,8 @@ const char* UNPARSED_CONFIGS[] = { " \"server-hostname\": \"\",\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet4\": [ ],\n" " \"t1-percent\": 0.5,\n" @@ -8042,6 +8162,8 @@ const char* UNPARSED_CONFIGS[] = { " \"server-hostname\": \"\",\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet4\": [ ],\n" " \"t1-percent\": 0.5,\n" @@ -8107,6 +8229,8 @@ const char* UNPARSED_CONFIGS[] = { " \"server-hostname\": \"\",\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet4\": [ ],\n" " \"t1-percent\": 0.5,\n" @@ -8174,6 +8298,8 @@ const char* UNPARSED_CONFIGS[] = { " \"server-hostname\": \"\",\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet4\": [\n" " {\n" @@ -8267,6 +8393,8 @@ const char* UNPARSED_CONFIGS[] = { " \"server-hostname\": \"\",\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet4\": [\n" " {\n" @@ -8360,6 +8488,8 @@ const char* UNPARSED_CONFIGS[] = { " \"server-hostname\": \"\",\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet4\": [\n" " {\n" @@ -8453,6 +8583,8 @@ const char* UNPARSED_CONFIGS[] = { " \"server-hostname\": \"\",\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet4\": [\n" " {\n" @@ -8546,6 +8678,8 @@ const char* UNPARSED_CONFIGS[] = { " \"server-hostname\": \"\",\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet4\": [\n" " {\n" @@ -8665,6 +8799,8 @@ const char* UNPARSED_CONFIGS[] = { " \"server-hostname\": \"\",\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet4\": [\n" " {\n" @@ -8758,6 +8894,8 @@ const char* UNPARSED_CONFIGS[] = { " \"server-hostname\": \"\",\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet4\": [\n" " {\n" @@ -8851,6 +8989,8 @@ const char* UNPARSED_CONFIGS[] = { " \"server-hostname\": \"\",\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet4\": [\n" " {\n" @@ -8945,6 +9085,8 @@ const char* UNPARSED_CONFIGS[] = { " \"server-hostname\": \"\",\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet4\": [\n" " {\n" @@ -9043,6 +9185,8 @@ const char* UNPARSED_CONFIGS[] = { " \"server-hostname\": \"\",\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet4\": [\n" " {\n" @@ -9155,6 +9299,8 @@ const char* UNPARSED_CONFIGS[] = { " \"server-hostname\": \"\",\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet4\": [ ],\n" " \"t1-percent\": 0.5,\n" @@ -9343,6 +9489,8 @@ const char* UNPARSED_CONFIGS[] = { " \"valid-lifetime\": 7200\n" " }\n" " ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet4\": [ ],\n" " \"t1-percent\": 0.5,\n" @@ -9465,6 +9613,8 @@ const char* UNPARSED_CONFIGS[] = { " \"server-hostname\": \"\",\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet4\": [\n" " {\n" @@ -9642,6 +9792,8 @@ const char* UNPARSED_CONFIGS[] = { " \"valid-lifetime\": 4000\n" " }\n" " ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet4\": [\n" " {\n" @@ -9733,6 +9885,8 @@ const char* UNPARSED_CONFIGS[] = { " \"server-hostname\": \"\",\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet4\": [\n" " {\n" @@ -9851,6 +10005,8 @@ const char* UNPARSED_CONFIGS[] = { " \"server-hostname\": \"\",\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": true,\n" " \"subnet4\": [\n" " {\n" @@ -9907,6 +10063,75 @@ const char* UNPARSED_CONFIGS[] = { " \"t1-percent\": 0.5,\n" " \"t2-percent\": 0.875,\n" " \"valid-lifetime\": 4000\n" +" }\n", + // CONFIGURATION 72 +"{\n" +" \"authoritative\": false,\n" +" \"boot-file-name\": \"\",\n" +" \"calculate-tee-times\": false,\n" +" \"ddns-generated-prefix\": \"myhost\",\n" +" \"ddns-override-client-update\": false,\n" +" \"ddns-override-no-update\": false,\n" +" \"ddns-qualifying-suffix\": \"\",\n" +" \"ddns-replace-client-name\": \"never\",\n" +" \"ddns-send-updates\": true,\n" +" \"decline-probation-period\": 86400,\n" +" \"dhcp-ddns\": {\n" +" \"enable-updates\": false,\n" +" \"max-queue-size\": 1024,\n" +" \"ncr-format\": \"JSON\",\n" +" \"ncr-protocol\": \"UDP\",\n" +" \"sender-ip\": \"0.0.0.0\",\n" +" \"sender-port\": 0,\n" +" \"server-ip\": \"127.0.0.1\",\n" +" \"server-port\": 53001\n" +" },\n" +" \"dhcp-queue-control\": {\n" +" \"capacity\": 500,\n" +" \"enable-queue\": false,\n" +" \"queue-type\": \"kea-ring4\"\n" +" },\n" +" \"dhcp4o6-port\": 0,\n" +" \"echo-client-id\": true,\n" +" \"expired-leases-processing\": {\n" +" \"flush-reclaimed-timer-wait-time\": 25,\n" +" \"hold-reclaimed-time\": 3600,\n" +" \"max-reclaim-leases\": 100,\n" +" \"max-reclaim-time\": 250,\n" +" \"reclaim-timer-wait-time\": 10,\n" +" \"unwarned-reclaim-cycles\": 5\n" +" },\n" +" \"hooks-libraries\": [ ],\n" +" \"host-reservation-identifiers\": [ \"hw-address\", \"duid\", \"circuit-id\", \"client-id\" ],\n" +" \"hostname-char-replacement\": \"\",\n" +" \"hostname-char-set\": \"[^A-Za-z0-9.-]\",\n" +" \"interfaces-config\": {\n" +" \"interfaces\": [ \"*\" ],\n" +" \"re-detect\": false\n" +" },\n" +" \"lease-database\": {\n" +" \"type\": \"memfile\"\n" +" },\n" +" \"match-client-id\": true,\n" +" \"next-server\": \"0.0.0.0\",\n" +" \"option-data\": [ ],\n" +" \"option-def\": [ ],\n" +" \"rebind-timer\": 2000,\n" +" \"renew-timer\": 1000,\n" +" \"reservation-mode\": \"all\",\n" +" \"sanity-checks\": {\n" +" \"lease-checks\": \"warn\"\n" +" },\n" +" \"server-hostname\": \"\",\n" +" \"server-tag\": \"\",\n" +" \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 5,\n" +" \"statistic-default-sample-count\": 10,\n" +" \"store-extended-info\": false,\n" +" \"subnet4\": [ ],\n" +" \"t1-percent\": 0.5,\n" +" \"t2-percent\": 0.875,\n" +" \"valid-lifetime\": 4000\n" " }\n" }; diff --git a/src/bin/dhcp6/tests/config_parser_unittest.cc b/src/bin/dhcp6/tests/config_parser_unittest.cc index 578974cfa7..a3cd8b5ca2 100644 --- a/src/bin/dhcp6/tests/config_parser_unittest.cc +++ b/src/bin/dhcp6/tests/config_parser_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2012-2019 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2012-2020 Internet Systems Consortium, Inc. ("ISC") // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -28,6 +28,8 @@ #include #include #include +#include +#include #include "test_data_files_config.h" #include "test_libraries.h" @@ -7723,6 +7725,32 @@ TEST_F(Dhcp6ParserTest, storeExtendedInfoNoGlobal) { EXPECT_TRUE(subnet->getStoreExtendedInfo()); } +/// This test checks that the statistic-default-sample-count and age +/// global parameters are committed to the stats manager as expected. +TEST_F(Dhcp6ParserTest, statsDefaultLimits) { + std::string config = "{ " + genIfaceConfig() + "," + + "\"preferred-lifetime\": 3000," + "\"rebind-timer\": 2000, " + "\"renew-timer\": 1000, " + "\"statistic-default-sample-count\": 10, " + "\"statistic-default-sample-age\": 5, " + "\"valid-lifetime\": 4000 }"; + ConstElementPtr json; + ASSERT_NO_THROW(json = parseDHCP6(config)); + extractConfig(config); -}; + ConstElementPtr status; + ASSERT_NO_THROW(status = configureDhcp6Server(srv_, json)); + checkResult(status, 0); + + CfgMgr::instance().commit(); + + stats::StatsMgr& stats_mgr = stats::StatsMgr::instance(); + EXPECT_EQ(10, stats_mgr.getMaxSampleCountDefault()); + EXPECT_EQ("00:00:05", + util::durationToText(stats_mgr.getMaxSampleAgeDefault(), 0)); +} + + +} diff --git a/src/bin/dhcp6/tests/get_config_unittest.cc b/src/bin/dhcp6/tests/get_config_unittest.cc index cfe716bee5..844bd9f4a1 100644 --- a/src/bin/dhcp6/tests/get_config_unittest.cc +++ b/src/bin/dhcp6/tests/get_config_unittest.cc @@ -1918,6 +1918,19 @@ const char* EXTRACTED_CONFIGS[] = { " }\n" " ],\n" " \"valid-lifetime\": 4000\n" +" }\n", + // CONFIGURATION 60 +"{\n" +" \"interfaces-config\": {\n" +" \"interfaces\": [ \"*\" ],\n" +" \"re-detect\": false\n" +" },\n" +" \"preferred-lifetime\": 3000,\n" +" \"rebind-timer\": 2000,\n" +" \"renew-timer\": 1000,\n" +" \"statistic-default-sample-age\": 5,\n" +" \"statistic-default-sample-count\": 10,\n" +" \"valid-lifetime\": 4000\n" " }\n" }; @@ -1989,6 +2002,8 @@ const char* UNPARSED_CONFIGS[] = { " },\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet6\": [ ],\n" " \"t1-percent\": 0.5,\n" @@ -2065,6 +2080,8 @@ const char* UNPARSED_CONFIGS[] = { " },\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet6\": [\n" " {\n" @@ -2167,6 +2184,8 @@ const char* UNPARSED_CONFIGS[] = { " },\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet6\": [\n" " {\n" @@ -2340,6 +2359,8 @@ const char* UNPARSED_CONFIGS[] = { " },\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet6\": [\n" " {\n" @@ -2513,6 +2534,8 @@ const char* UNPARSED_CONFIGS[] = { " },\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet6\": [\n" " {\n" @@ -2690,6 +2713,8 @@ const char* UNPARSED_CONFIGS[] = { " },\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet6\": [\n" " {\n" @@ -2792,6 +2817,8 @@ const char* UNPARSED_CONFIGS[] = { " },\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet6\": [\n" " {\n" @@ -2891,6 +2918,8 @@ const char* UNPARSED_CONFIGS[] = { " },\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet6\": [\n" " {\n" @@ -2990,6 +3019,8 @@ const char* UNPARSED_CONFIGS[] = { " },\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet6\": [\n" " {\n" @@ -3121,6 +3152,8 @@ const char* UNPARSED_CONFIGS[] = { " },\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet6\": [\n" " {\n" @@ -3219,6 +3252,8 @@ const char* UNPARSED_CONFIGS[] = { " },\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet6\": [\n" " {\n" @@ -3319,6 +3354,8 @@ const char* UNPARSED_CONFIGS[] = { " },\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet6\": [\n" " {\n" @@ -3421,6 +3458,8 @@ const char* UNPARSED_CONFIGS[] = { " },\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet6\": [\n" " {\n" @@ -3538,6 +3577,8 @@ const char* UNPARSED_CONFIGS[] = { " },\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet6\": [\n" " {\n" @@ -3646,6 +3687,8 @@ const char* UNPARSED_CONFIGS[] = { " },\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet6\": [ ],\n" " \"t1-percent\": 0.5,\n" @@ -3726,6 +3769,8 @@ const char* UNPARSED_CONFIGS[] = { " },\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet6\": [ ],\n" " \"t1-percent\": 0.5,\n" @@ -3815,6 +3860,8 @@ const char* UNPARSED_CONFIGS[] = { " },\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet6\": [ ],\n" " \"t1-percent\": 0.5,\n" @@ -3895,6 +3942,8 @@ const char* UNPARSED_CONFIGS[] = { " },\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet6\": [ ],\n" " \"t1-percent\": 0.5,\n" @@ -3975,6 +4024,8 @@ const char* UNPARSED_CONFIGS[] = { " },\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet6\": [ ],\n" " \"t1-percent\": 0.5,\n" @@ -4064,6 +4115,8 @@ const char* UNPARSED_CONFIGS[] = { " },\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet6\": [\n" " {\n" @@ -4162,6 +4215,8 @@ const char* UNPARSED_CONFIGS[] = { " },\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet6\": [\n" " {\n" @@ -4304,6 +4359,8 @@ const char* UNPARSED_CONFIGS[] = { " },\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet6\": [\n" " {\n" @@ -4438,6 +4495,8 @@ const char* UNPARSED_CONFIGS[] = { " },\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet6\": [ ],\n" " \"t1-percent\": 0.5,\n" @@ -4563,6 +4622,8 @@ const char* UNPARSED_CONFIGS[] = { " },\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet6\": [\n" " {\n" @@ -4661,6 +4722,8 @@ const char* UNPARSED_CONFIGS[] = { " },\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet6\": [\n" " {\n" @@ -4802,6 +4865,8 @@ const char* UNPARSED_CONFIGS[] = { " },\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet6\": [\n" " {\n" @@ -4968,6 +5033,8 @@ const char* UNPARSED_CONFIGS[] = { " },\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet6\": [\n" " {\n" @@ -5085,6 +5152,8 @@ const char* UNPARSED_CONFIGS[] = { " },\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet6\": [\n" " {\n" @@ -5183,6 +5252,8 @@ const char* UNPARSED_CONFIGS[] = { " },\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet6\": [ ],\n" " \"t1-percent\": 0.5,\n" @@ -5255,6 +5326,8 @@ const char* UNPARSED_CONFIGS[] = { " },\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet6\": [ ],\n" " \"t1-percent\": 0.5,\n" @@ -5327,6 +5400,8 @@ const char* UNPARSED_CONFIGS[] = { " },\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet6\": [\n" " {\n" @@ -5425,6 +5500,8 @@ const char* UNPARSED_CONFIGS[] = { " },\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet6\": [\n" " {\n" @@ -5523,6 +5600,8 @@ const char* UNPARSED_CONFIGS[] = { " },\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet6\": [\n" " {\n" @@ -5699,6 +5778,8 @@ const char* UNPARSED_CONFIGS[] = { " },\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet6\": [\n" " {\n" @@ -5812,6 +5893,8 @@ const char* UNPARSED_CONFIGS[] = { " },\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet6\": [\n" " {\n" @@ -5933,6 +6016,8 @@ const char* UNPARSED_CONFIGS[] = { " },\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet6\": [\n" " {\n" @@ -6031,6 +6116,8 @@ const char* UNPARSED_CONFIGS[] = { " },\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet6\": [\n" " {\n" @@ -6129,6 +6216,8 @@ const char* UNPARSED_CONFIGS[] = { " },\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet6\": [\n" " {\n" @@ -6227,6 +6316,8 @@ const char* UNPARSED_CONFIGS[] = { " },\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet6\": [\n" " {\n" @@ -6460,6 +6551,8 @@ const char* UNPARSED_CONFIGS[] = { " },\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet6\": [\n" " {\n" @@ -6571,6 +6664,8 @@ const char* UNPARSED_CONFIGS[] = { " },\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet6\": [ ],\n" " \"t1-percent\": 0.5,\n" @@ -6643,6 +6738,8 @@ const char* UNPARSED_CONFIGS[] = { " },\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet6\": [ ],\n" " \"t1-percent\": 0.5,\n" @@ -6715,6 +6812,8 @@ const char* UNPARSED_CONFIGS[] = { " },\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet6\": [\n" " {\n" @@ -6917,6 +7016,8 @@ const char* UNPARSED_CONFIGS[] = { " },\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet6\": [\n" " {\n" @@ -7041,6 +7142,8 @@ const char* UNPARSED_CONFIGS[] = { " },\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet6\": [ ],\n" " \"t1-percent\": 0.5,\n" @@ -7111,6 +7214,8 @@ const char* UNPARSED_CONFIGS[] = { " },\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet6\": [ ],\n" " \"t1-percent\": 0.5,\n" @@ -7181,6 +7286,8 @@ const char* UNPARSED_CONFIGS[] = { " },\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet6\": [ ],\n" " \"t1-percent\": 0.5,\n" @@ -7251,6 +7358,8 @@ const char* UNPARSED_CONFIGS[] = { " },\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet6\": [ ],\n" " \"t1-percent\": 0.5,\n" @@ -7321,6 +7430,8 @@ const char* UNPARSED_CONFIGS[] = { " },\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet6\": [ ],\n" " \"t1-percent\": 0.5,\n" @@ -7407,6 +7518,8 @@ const char* UNPARSED_CONFIGS[] = { " },\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet6\": [\n" " {\n" @@ -7505,6 +7618,8 @@ const char* UNPARSED_CONFIGS[] = { " },\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet6\": [\n" " {\n" @@ -7603,6 +7718,8 @@ const char* UNPARSED_CONFIGS[] = { " },\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet6\": [\n" " {\n" @@ -7702,6 +7819,8 @@ const char* UNPARSED_CONFIGS[] = { " },\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet6\": [\n" " {\n" @@ -7806,6 +7925,8 @@ const char* UNPARSED_CONFIGS[] = { " },\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet6\": [\n" " {\n" @@ -7910,6 +8031,8 @@ const char* UNPARSED_CONFIGS[] = { " },\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet6\": [\n" " {\n" @@ -8010,6 +8133,8 @@ const char* UNPARSED_CONFIGS[] = { " },\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet6\": [\n" " {\n" @@ -8111,6 +8236,8 @@ const char* UNPARSED_CONFIGS[] = { " },\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet6\": [\n" " {\n" @@ -8231,6 +8358,8 @@ const char* UNPARSED_CONFIGS[] = { " },\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet6\": [ ],\n" " \"t1-percent\": 0.5,\n" @@ -8421,6 +8550,8 @@ const char* UNPARSED_CONFIGS[] = { " \"valid-lifetime\": 7200\n" " }\n" " ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet6\": [ ],\n" " \"t1-percent\": 0.5,\n" @@ -8545,6 +8676,8 @@ const char* UNPARSED_CONFIGS[] = { " },\n" " \"server-tag\": \"\",\n" " \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 0,\n" +" \"statistic-default-sample-count\": 20,\n" " \"store-extended-info\": false,\n" " \"subnet6\": [\n" " {\n" @@ -8616,6 +8749,80 @@ const char* UNPARSED_CONFIGS[] = { " \"t1-percent\": 0.5,\n" " \"t2-percent\": 0.8,\n" " \"valid-lifetime\": 4000\n" +" }\n", + // CONFIGURATION 60 +"{\n" +" \"calculate-tee-times\": true,\n" +" \"ddns-generated-prefix\": \"myhost\",\n" +" \"ddns-override-client-update\": false,\n" +" \"ddns-override-no-update\": false,\n" +" \"ddns-qualifying-suffix\": \"\",\n" +" \"ddns-replace-client-name\": \"never\",\n" +" \"ddns-send-updates\": true,\n" +" \"decline-probation-period\": 86400,\n" +" \"dhcp-ddns\": {\n" +" \"enable-updates\": false,\n" +" \"max-queue-size\": 1024,\n" +" \"ncr-format\": \"JSON\",\n" +" \"ncr-protocol\": \"UDP\",\n" +" \"sender-ip\": \"0.0.0.0\",\n" +" \"sender-port\": 0,\n" +" \"server-ip\": \"127.0.0.1\",\n" +" \"server-port\": 53001\n" +" },\n" +" \"dhcp-queue-control\": {\n" +" \"capacity\": 500,\n" +" \"enable-queue\": false,\n" +" \"queue-type\": \"kea-ring6\"\n" +" },\n" +" \"dhcp4o6-port\": 0,\n" +" \"expired-leases-processing\": {\n" +" \"flush-reclaimed-timer-wait-time\": 25,\n" +" \"hold-reclaimed-time\": 3600,\n" +" \"max-reclaim-leases\": 100,\n" +" \"max-reclaim-time\": 250,\n" +" \"reclaim-timer-wait-time\": 10,\n" +" \"unwarned-reclaim-cycles\": 5\n" +" },\n" +" \"hooks-libraries\": [ ],\n" +" \"host-reservation-identifiers\": [ \"hw-address\", \"duid\" ],\n" +" \"hostname-char-replacement\": \"\",\n" +" \"hostname-char-set\": \"[^A-Za-z0-9.-]\",\n" +" \"interfaces-config\": {\n" +" \"interfaces\": [ \"*\" ],\n" +" \"re-detect\": false\n" +" },\n" +" \"lease-database\": {\n" +" \"type\": \"memfile\"\n" +" },\n" +" \"mac-sources\": [ \"any\" ],\n" +" \"option-data\": [ ],\n" +" \"option-def\": [ ],\n" +" \"preferred-lifetime\": 3000,\n" +" \"rebind-timer\": 2000,\n" +" \"relay-supplied-options\": [ \"65\" ],\n" +" \"renew-timer\": 1000,\n" +" \"reservation-mode\": \"all\",\n" +" \"sanity-checks\": {\n" +" \"lease-checks\": \"warn\"\n" +" },\n" +" \"server-id\": {\n" +" \"enterprise-id\": 0,\n" +" \"htype\": 0,\n" +" \"identifier\": \"\",\n" +" \"persist\": true,\n" +" \"time\": 0,\n" +" \"type\": \"LLT\"\n" +" },\n" +" \"server-tag\": \"\",\n" +" \"shared-networks\": [ ],\n" +" \"statistic-default-sample-age\": 5,\n" +" \"statistic-default-sample-count\": 10,\n" +" \"store-extended-info\": false,\n" +" \"subnet6\": [ ],\n" +" \"t1-percent\": 0.5,\n" +" \"t2-percent\": 0.8,\n" +" \"valid-lifetime\": 4000\n" " }\n" }; diff --git a/src/lib/dhcpsrv/srv_config.cc b/src/lib/dhcpsrv/srv_config.cc index b40c25a3ae..58a97fee9b 100644 --- a/src/lib/dhcpsrv/srv_config.cc +++ b/src/lib/dhcpsrv/srv_config.cc @@ -16,6 +16,7 @@ #include #include #include // Needed for HWADDR_SOURCE_* +#include #include #include @@ -265,6 +266,25 @@ SrvConfig::removeStatistics() { void SrvConfig::updateStatistics() { + // Update default sample limits. + stats::StatsMgr& stats_mgr = stats::StatsMgr::instance(); + ConstElementPtr max_samples = + getConfiguredGlobal("statistic-default-sample-count"); + if (max_samples) { + stats_mgr.setMaxSampleCountDefault(max_samples->intValue()); + } + ConstElementPtr duration = + getConfiguredGlobal("statistic-default-sample-age"); + if (duration) { + int64_t time_duration = duration->intValue(); + int64_t hours = time_duration / 3600; + time_duration -= hours * 3600; + int64_t minutes = time_duration / 60; + time_duration -= minutes * 60; + int64_t seconds = time_duration; + stats_mgr.setMaxSampleAgeDefault(boost::posix_time::time_duration(hours, minutes, seconds, 0)); + } + // Updating subnet statistics involves updating lease statistics, which // is done by the LeaseMgr. Since servers with subnets, must have a // LeaseMgr, we do not bother updating subnet stats for servers without @@ -596,7 +616,7 @@ SrvConfig::toElement() const { DdnsParamsPtr SrvConfig::getDdnsParams(const Subnet4Ptr& subnet) const { - return (DdnsParamsPtr(new DdnsParams(subnet, + return (DdnsParamsPtr(new DdnsParams(subnet, getD2ClientConfig()->getEnableUpdates()))); } diff --git a/src/lib/dhcpsrv/tests/cfgmgr_unittest.cc b/src/lib/dhcpsrv/tests/cfgmgr_unittest.cc index f81931a97a..3cfd5dd450 100644 --- a/src/lib/dhcpsrv/tests/cfgmgr_unittest.cc +++ b/src/lib/dhcpsrv/tests/cfgmgr_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2012-2019 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2012-2020 Internet Systems Consortium, Inc. ("ISC") // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -15,6 +15,7 @@ #include #include #include +#include #include @@ -607,9 +608,18 @@ TEST_F(CfgMgrTest, commitStats4) { subnets = cfg_mgr.getStagingCfg()->getCfgSubnets4(); subnets->add(subnet2); + // Change the stats default limits. + cfg_mgr.getStagingCfg()->addConfiguredGlobal("statistic-default-sample-count", + Element::create(15)); + cfg_mgr.getStagingCfg()->addConfiguredGlobal("statistic-default-sample-age", + Element::create(2)); + // Let's commit it cfg_mgr.commit(); + EXPECT_EQ(15, stats_mgr.getMaxSampleCountDefault()); + EXPECT_EQ("00:00:02", durationToText(stats_mgr.getMaxSampleAgeDefault(), 0)); + EXPECT_FALSE(stats_mgr.getObservation("subnet[123].total-addresses")); EXPECT_FALSE(stats_mgr.getObservation("subnet[123].assigned-addresses")); @@ -653,11 +663,19 @@ TEST_F(CfgMgrTest, mergeIntoCurrentStats4) { subnets = external_cfg->getCfgSubnets4(); subnets->add(subnet2); + external_cfg->addConfiguredGlobal("statistic-default-sample-count", + Element::create(16)); + external_cfg->addConfiguredGlobal("statistic-default-sample-age", + Element::create(3)); + // Let's merge it. cfg_mgr.mergeIntoCurrentCfg(external_cfg->getSequence()); // The stats should have been updated and so we should be able to get - // obeservations for subnet 42. + // observations for subnet 42. + EXPECT_EQ(16, stats_mgr.getMaxSampleCountDefault()); + EXPECT_EQ("00:00:03", durationToText(stats_mgr.getMaxSampleAgeDefault(), 0)); + EXPECT_TRUE(stats_mgr.getObservation("subnet[42].total-addresses")); EXPECT_TRUE(stats_mgr.getObservation("subnet[42].assigned-addresses")); @@ -731,9 +749,18 @@ TEST_F(CfgMgrTest, commitStats6) { subnets = cfg_mgr.getStagingCfg()->getCfgSubnets6(); subnets->add(subnet2); + // Change the stats default limits. + cfg_mgr.getStagingCfg()->addConfiguredGlobal("statistic-default-sample-count", + Element::create(14)); + cfg_mgr.getStagingCfg()->addConfiguredGlobal("statistic-default-sample-age", + Element::create(10)); + // Let's commit it cfg_mgr.commit(); + EXPECT_EQ(14, stats_mgr.getMaxSampleCountDefault()); + EXPECT_EQ("00:00:10", durationToText(stats_mgr.getMaxSampleAgeDefault(), 0)); + EXPECT_FALSE(stats_mgr.getObservation("subnet[123].total-nas")); EXPECT_FALSE(stats_mgr.getObservation("subnet[123].assigned-nas")); @@ -792,9 +819,17 @@ TEST_F(CfgMgrTest, DISABLED_mergeIntoCurrentStats6) { subnets = external_cfg->getCfgSubnets6(); subnets->add(subnet2); + external_cfg->addConfiguredGlobal("statistic-default-sample-count", + Element::create(17)); + external_cfg->addConfiguredGlobal("statistic-default-sample-age", + Element::create(4)); + // Let's merge it. cfg_mgr.mergeIntoCurrentCfg(external_cfg->getSequence()); + EXPECT_EQ(17, stats_mgr.getMaxSampleCountDefault()); + EXPECT_EQ("00:00:04", durationToText(stats_mgr.getMaxSampleAgeDefault(), 0)); + EXPECT_TRUE(stats_mgr.getObservation("subnet[42].total-nas")); EXPECT_TRUE(stats_mgr.getObservation("subnet[42].assigned-nas")); EXPECT_TRUE(stats_mgr.getObservation("subnet[42].total-pds")); diff --git a/src/lib/stats/tests/observation_unittest.cc b/src/lib/stats/tests/observation_unittest.cc index 03e4680d59..32e07bafdf 100644 --- a/src/lib/stats/tests/observation_unittest.cc +++ b/src/lib/stats/tests/observation_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2015-2019 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2015-2020 Internet Systems Consortium, Inc. ("ISC") // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -238,13 +238,13 @@ TEST_F(ObservationTest, getSize) { TEST_F(ObservationTest, setCountLimit) { // Preparing of 21 test's samples for each type of storage int64_t int_samples[22] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, - 14, 15, 16, 17, 18, 19, 20, 21}; + 14, 15, 16, 17, 18, 19, 20, 21}; double float_samples[22] = {0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, - 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0, 19.0, - 20.0, 21.0}; + 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0, 19.0, + 20.0, 21.0}; std::string string_samples[22] = {"a", "b", "c", "d", "e", "f", "g", "h", - "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", - "v"}; + "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", + "v"}; millisec::time_duration duration_samples[22]; for (uint32_t i = 0; i < 22; ++i) { @@ -476,6 +476,8 @@ TEST_F(ObservationTest, getLimits) { EXPECT_EQ(d.getMaxSampleCount().second, 20); } +// limit defaults are tested with StatsMgr. + // Test checks whether timing is reported properly. TEST_F(ObservationTest, timers) { ptime before = microsec_clock::local_time(); diff --git a/src/lib/stats/tests/stats_mgr_unittest.cc b/src/lib/stats/tests/stats_mgr_unittest.cc index 952b1b8c22..091acb78f1 100644 --- a/src/lib/stats/tests/stats_mgr_unittest.cc +++ b/src/lib/stats/tests/stats_mgr_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2015-2019 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2015-2020 Internet Systems Consortium, Inc. ("ISC") // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -215,6 +215,98 @@ TEST_F(StatsMgrTest, setLimitsAll) { EXPECT_EQ(StatsMgr::instance().getObservation("delta")->getMaxSampleAge().first, false); } +// Test checks whether setting default age limit and count limit works +// properly. +TEST_F(StatsMgrTest, setLimitsDefault) { + ASSERT_EQ(StatsMgr::instance().getMaxSampleCountDefault(), 20); + ASSERT_EQ(StatsMgr::instance().getMaxSampleAgeDefault(), time_duration(0, 0, 0, 0)); + + // Set a couple of statistics + StatsMgr::instance().setValue("alpha", static_cast(1234)); + StatsMgr::instance().setValue("beta", 12.34); + StatsMgr::instance().setValue("gamma", time_duration(1, 2, 3, 4)); + StatsMgr::instance().setValue("delta", "Lorem ipsum"); + + // check what default applied + EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleCount().first, true); + EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleCount().second, 20); + EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleAge().first, false); + EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleAge().second, time_duration(0, 0, 0, 0)); + EXPECT_EQ(StatsMgr::instance().getObservation("beta")->getMaxSampleCount().first, true); + EXPECT_EQ(StatsMgr::instance().getObservation("beta")->getMaxSampleCount().second, 20); + EXPECT_EQ(StatsMgr::instance().getObservation("beta")->getMaxSampleAge().first, false); + EXPECT_EQ(StatsMgr::instance().getObservation("beta")->getMaxSampleAge().second, time_duration(0, 0, 0, 0)); + EXPECT_EQ(StatsMgr::instance().getObservation("gamma")->getMaxSampleCount().first, true); + EXPECT_EQ(StatsMgr::instance().getObservation("gamma")->getMaxSampleCount().second, 20); + EXPECT_EQ(StatsMgr::instance().getObservation("gamma")->getMaxSampleAge().first, false); + EXPECT_EQ(StatsMgr::instance().getObservation("gamma")->getMaxSampleAge().second, time_duration(0, 0, 0, 0)); + EXPECT_EQ(StatsMgr::instance().getObservation("delta")->getMaxSampleCount().first, true); + EXPECT_EQ(StatsMgr::instance().getObservation("delta")->getMaxSampleCount().second, 20); + EXPECT_EQ(StatsMgr::instance().getObservation("delta")->getMaxSampleAge().first, false); + EXPECT_EQ(StatsMgr::instance().getObservation("delta")->getMaxSampleAge().second, time_duration(0, 0, 0, 0)); + + // Retry with another default count limits. + EXPECT_NO_THROW(StatsMgr::instance().setMaxSampleCountDefault(10)); + EXPECT_NO_THROW(StatsMgr::instance().setMaxSampleAgeDefault(time_duration(0, 0, 5, 0))); + ASSERT_EQ(StatsMgr::instance().getMaxSampleCountDefault(), 10); + ASSERT_EQ(StatsMgr::instance().getMaxSampleAgeDefault(), time_duration(0, 0, 5, 0)); + + EXPECT_NO_THROW(StatsMgr::instance().removeAll()); + + StatsMgr::instance().setValue("alpha", static_cast(1234)); + StatsMgr::instance().setValue("beta", 12.34); + StatsMgr::instance().setValue("gamma", time_duration(1, 2, 3, 4)); + StatsMgr::instance().setValue("delta", "Lorem ipsum"); + + EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleCount().first, true); + EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleCount().second, 10); + EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleAge().first, false); + EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleAge().second, time_duration(0, 0, 5, 0)); + EXPECT_EQ(StatsMgr::instance().getObservation("beta")->getMaxSampleCount().first, true); + EXPECT_EQ(StatsMgr::instance().getObservation("beta")->getMaxSampleCount().second, 10); + EXPECT_EQ(StatsMgr::instance().getObservation("beta")->getMaxSampleAge().first, false); + EXPECT_EQ(StatsMgr::instance().getObservation("beta")->getMaxSampleAge().second, time_duration(0, 0, 5, 0)); + EXPECT_EQ(StatsMgr::instance().getObservation("gamma")->getMaxSampleCount().first, true); + EXPECT_EQ(StatsMgr::instance().getObservation("gamma")->getMaxSampleCount().second, 10); + EXPECT_EQ(StatsMgr::instance().getObservation("gamma")->getMaxSampleAge().first, false); + EXPECT_EQ(StatsMgr::instance().getObservation("gamma")->getMaxSampleAge().second, time_duration(0, 0, 5, 0)); + EXPECT_EQ(StatsMgr::instance().getObservation("delta")->getMaxSampleCount().first, true); + EXPECT_EQ(StatsMgr::instance().getObservation("delta")->getMaxSampleCount().second, 10); + EXPECT_EQ(StatsMgr::instance().getObservation("delta")->getMaxSampleAge().first, false); + EXPECT_EQ(StatsMgr::instance().getObservation("delta")->getMaxSampleAge().second, time_duration(0, 0, 5, 0)); + + // Retry with count limit disable. + EXPECT_NO_THROW(StatsMgr::instance().setMaxSampleCountDefault(0)); + ASSERT_EQ(StatsMgr::instance().getMaxSampleCountDefault(), 0); + + EXPECT_NO_THROW(StatsMgr::instance().removeAll()); + + StatsMgr::instance().setValue("alpha", static_cast(1234)); + StatsMgr::instance().setValue("beta", 12.34); + StatsMgr::instance().setValue("gamma", time_duration(1, 2, 3, 4)); + StatsMgr::instance().setValue("delta", "Lorem ipsum"); + + EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleCount().first, false); + EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleCount().second, 10); + EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleAge().first, true); + EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleAge().second, time_duration(0, 0, 5, 0)); + EXPECT_EQ(StatsMgr::instance().getObservation("beta")->getMaxSampleCount().first, false); + EXPECT_EQ(StatsMgr::instance().getObservation("beta")->getMaxSampleCount().second, 10); + EXPECT_EQ(StatsMgr::instance().getObservation("beta")->getMaxSampleAge().first, true); + EXPECT_EQ(StatsMgr::instance().getObservation("beta")->getMaxSampleAge().second, time_duration(0, 0, 5, 0)); + EXPECT_EQ(StatsMgr::instance().getObservation("gamma")->getMaxSampleCount().first, false); + EXPECT_EQ(StatsMgr::instance().getObservation("gamma")->getMaxSampleCount().second, 10); + EXPECT_EQ(StatsMgr::instance().getObservation("gamma")->getMaxSampleAge().first, true); + EXPECT_EQ(StatsMgr::instance().getObservation("gamma")->getMaxSampleAge().second, time_duration(0, 0, 5, 0)); + EXPECT_EQ(StatsMgr::instance().getObservation("delta")->getMaxSampleCount().first, false); + EXPECT_EQ(StatsMgr::instance().getObservation("delta")->getMaxSampleCount().second, 10); + EXPECT_EQ(StatsMgr::instance().getObservation("delta")->getMaxSampleAge().first, true); + EXPECT_EQ(StatsMgr::instance().getObservation("delta")->getMaxSampleAge().second, time_duration(0, 0, 5, 0)); + + EXPECT_NO_THROW(StatsMgr::instance().setMaxSampleCountDefault(20)); + EXPECT_NO_THROW(StatsMgr::instance().setMaxSampleAgeDefault(time_duration(0, 0, 0, 0))); +} + // This test checks whether a single (get("foo")) and all (getAll()) // statistics are reported properly. TEST_F(StatsMgrTest, getGetAll) {