From cdf12c66122fee9875e0f31cf987cce4ebc0268d Mon Sep 17 00:00:00 2001 From: Franciszek Gorski Date: Mon, 15 Jul 2019 12:19:12 +0200 Subject: [PATCH 01/12] new statistics commands --- src/lib/stats/observation.cc | 20 +- src/lib/stats/observation.h | 10 + src/lib/stats/stats_mgr.cc | 135 ++++++++++ src/lib/stats/stats_mgr.h | 130 +++++++++- src/lib/stats/tests/observation_unittest.cc | 29 +++ src/lib/stats/tests/stats_mgr_unittest.cc | 257 +++++++++++++++++++- 6 files changed, 573 insertions(+), 8 deletions(-) diff --git a/src/lib/stats/observation.cc b/src/lib/stats/observation.cc index b790e8eb5b..33661ffa9d 100644 --- a/src/lib/stats/observation.cc +++ b/src/lib/stats/observation.cc @@ -150,6 +150,14 @@ size_t Observation::getSize() const { return (size); } +std::pair Observation::getMaxSampleAge() const { + return (max_sample_age_); +} + +std::pair Observation::getMaxSampleCount() const { + return (max_sample_count_); +} + template size_t Observation::getSizeInternal(StorageType& storage, Type exp_type) const { if (type_ != exp_type) { @@ -178,8 +186,8 @@ void Observation::setValueInternal(SampleType value, StorageType& storage, storage.push_front(make_pair(value, microsec_clock::local_time())); if (max_sample_count_.first) { - // if max_sample_count is set to true - // and size of storage is equal to max_sample_count + // if max_sample_count_ is set to true + // and size of storage is equal to max_sample_count_ if (storage.size() > max_sample_count_.second) { storage.pop_back(); // removing the last element } @@ -273,10 +281,10 @@ void Observation::setMaxSampleAgeInternal(StorageType& storage, << typeToText(exp_type) << ", but the actual type is " << typeToText(type_)); } - // setting new value of max_sample_age + // setting new value of max_sample_age_ max_sample_age_.first = true; max_sample_age_.second = duration; - // deactivating the max_sample_count limit + // deactivating the max_sample_count_ limit max_sample_count_.first = false; StatsDuration range_of_storage = @@ -298,10 +306,10 @@ void Observation::setMaxSampleCountInternal(StorageType& storage, << typeToText(exp_type) << ", but the actual type is " << typeToText(type_)); } - // setting new value of max_sample_count + // setting new value of max_sample_count_ max_sample_count_.first = true; max_sample_count_.second = max_samples; - // deactivating the max_sample_age limit + // deactivating the max_sample_age_ limit max_sample_age_.first = false; while (storage.size() > max_samples) { diff --git a/src/lib/stats/observation.h b/src/lib/stats/observation.h index 23fd7ef23e..28cf9a8bdc 100644 --- a/src/lib/stats/observation.h +++ b/src/lib/stats/observation.h @@ -194,6 +194,16 @@ class Observation { /// @return size of storage size_t getSize() const; + /// @brief Returns both value of max_sample_age_ of statistic. + /// + /// @return max_sample_age_. + std::pair getMaxSampleAge() const; + + /// @brief Returns both value of max_sample_count_ of statistic. + /// + /// @return max_sample_count_. + std::pair getMaxSampleCount() const; + /// @brief Resets statistic. /// /// Sets statistic to a neutral (0, 0.0 or "") value and diff --git a/src/lib/stats/stats_mgr.cc b/src/lib/stats/stats_mgr.cc index eb2500ce34..444b5e49b8 100644 --- a/src/lib/stats/stats_mgr.cc +++ b/src/lib/stats/stats_mgr.cc @@ -101,6 +101,26 @@ bool StatsMgr::setMaxSampleCount(const std::string& name, } } +void StatsMgr::setMaxSampleAgeAll(const StatsDuration& duration) { + // Let's iterate over all stored statistics... + for (std::map::iterator s = global_->stats_.begin(); + s != global_->stats_.end(); ++s) { + + // ... and set duration limit for each statistic. + s->second->setMaxSampleAge(duration); + } +} + +void StatsMgr::setMaxSampleCountAll(uint32_t max_samples) { + // Let's iterate over all stored statistics... + for (std::map::iterator s = global_->stats_.begin(); + s != global_->stats_.end(); ++s) { + + // ... and set count limit for each statistic. + s->second->setMaxSampleCount(max_samples); + } +} + bool StatsMgr::reset(const std::string& name) { ObservationPtr obs = getObservation(name); if (obs) { @@ -164,6 +184,46 @@ size_t StatsMgr::count() const { return (global_->stats_.size()); } +isc::data::ConstElementPtr +StatsMgr::statisticSetMaxSampleAgeHandler(const std::string& /*name*/, + const isc::data::ConstElementPtr& params) { + std::string name, error; + StatsDuration duration; + if (!getStatName(params, name, error)) { + return (createAnswer(CONTROL_RESULT_ERROR, error)); + } + if (!getStatDuration(params, duration, error)) { + return (createAnswer(CONTROL_RESULT_ERROR, error)); + } + if (instance().setMaxSampleAge(name, duration)) { + return (createAnswer(CONTROL_RESULT_SUCCESS, + "Statistic '" + name + "' duration limit is set.")); + } else { + return (createAnswer(CONTROL_RESULT_ERROR, + "No '" + name + "' statistic found")); + } +} + +isc::data::ConstElementPtr +StatsMgr::statisticSetMaxSampleCountHandler(const std::string& /*name*/, + const isc::data::ConstElementPtr& params) { + std::string name, error; + uint32_t max_samples; + if (!getStatName(params, name, error)) { + return (createAnswer(CONTROL_RESULT_ERROR, error)); + } + if (!getStatMaxSamples(params, max_samples, error)) { + return (createAnswer(CONTROL_RESULT_ERROR, error)); + } + if (instance().setMaxSampleCount(name, max_samples)) { + return (createAnswer(CONTROL_RESULT_SUCCESS, + "Statistic '" + name + "' count limit is set.")); + } else { + return (createAnswer(CONTROL_RESULT_ERROR, + "No '" + name + "' statistic found")); + } +} + isc::data::ConstElementPtr StatsMgr::statisticGetHandler(const std::string& /*name*/, const isc::data::ConstElementPtr& params) { @@ -232,6 +292,32 @@ StatsMgr::statisticResetAllHandler(const std::string& /*name*/, "All statistics reset to neutral values.")); } +isc::data::ConstElementPtr +StatsMgr::statisticSetMaxSampleAgeAllHandler(const std::string& /*name*/, + const isc::data::ConstElementPtr& params) { + std::string error; + StatsDuration duration; + if (!getStatDuration(params, duration, error)) { + return (createAnswer(CONTROL_RESULT_ERROR, error)); + } + instance().setMaxSampleAgeAll(duration); + return (createAnswer(CONTROL_RESULT_SUCCESS, + "All statistics duration limit are set.")); +} + +isc::data::ConstElementPtr +StatsMgr::statisticSetMaxSampleCountAllHandler(const std::string& /*name*/, + const isc::data::ConstElementPtr& params) { + std::string error; + uint32_t max_samples; + if (!getStatMaxSamples(params, max_samples, error)) { + return (createAnswer(CONTROL_RESULT_ERROR, error)); + } + instance().setMaxSampleCountAll(max_samples); + return (createAnswer(CONTROL_RESULT_SUCCESS, + "All statistics count limit are set.")); +} + bool StatsMgr::getStatName(const isc::data::ConstElementPtr& params, std::string& name, @@ -254,5 +340,54 @@ StatsMgr::getStatName(const isc::data::ConstElementPtr& params, return (true); } +bool +StatsMgr::getStatDuration(const isc::data::ConstElementPtr& params, + StatsDuration& duration, + std::string& reason) { + if (!params) { + reason = "Missing mandatory 'duration' parameter."; + return (false); + } + ConstElementPtr stat_duration = params->get("duration"); + if (!stat_duration) { + reason = "Missing mandatory 'duration' parameter."; + return (false); + } + + int64_t dur = stat_duration->intValue(); + + int64_t hours = dur/3600; + dur = dur - hours*3600; + + int64_t minutes = dur/60; + dur = dur - minutes*60; + + int64_t seconds = dur; + duration = boost::posix_time::time_duration(hours,minutes,seconds,0); + return (true); +} + +bool +StatsMgr::getStatMaxSamples(const isc::data::ConstElementPtr& params, + uint32_t& max_samples, + std::string& reason) { + if (!params) { + reason = "Missing mandatory 'max-samples' parameter."; + return (false); + } + ConstElementPtr stat_max_samples = params->get("max-samples"); + if (!stat_max_samples) { + reason = "Missing mandatory 'max-samples' parameter."; + return (false); + } + if (stat_max_samples->getType() != Element::integer) { + reason = "'max-samples' parameter expected to be an integer."; + return (false); + } + + max_samples = stat_max_samples->intValue(); + return (true); +} + }; }; diff --git a/src/lib/stats/stats_mgr.h b/src/lib/stats/stats_mgr.h index 085ab3cb5b..3ba00ad072 100644 --- a/src/lib/stats/stats_mgr.h +++ b/src/lib/stats/stats_mgr.h @@ -160,6 +160,12 @@ class StatsMgr : public boost::noncopyable { /// setMaxSampleCount("incoming-packets", 100); bool setMaxSampleCount(const std::string& name, uint32_t max_samples); + /// @brief Set duration limit for all collected statistics. + void setMaxSampleAgeAll(const StatsDuration& duration); + + /// @brief Set count limit for all collected statistics. + void setMaxSampleCountAll(uint32_t max_samples); + /// @} /// @defgroup consumer_methods Methods are used by data consumers. @@ -191,7 +197,7 @@ class StatsMgr : public boost::noncopyable { /// @brief Returns size of specified statistic. /// /// @param name name of the statistic which size should be return. - /// @return size of specified statistic. + /// @return size of specified statistic, 0 means lack of given statistic. size_t getSize(const std::string& name) const; /// @brief Returns number of available statistics. @@ -300,6 +306,50 @@ class StatsMgr : public boost::noncopyable { statisticRemoveHandler(const std::string& name, const isc::data::ConstElementPtr& params); + /// @brief Handles statistic-set-max-sample-age command + /// + /// This method handles statistic-set-max-sample-age command, + /// which set max_sample_age_ limit of a given statistic + /// and leaves max_sample_count_ disabled. + /// It expects two parameters stored in params map: + /// name: name-of-the-statistic + /// duration: time limit expressed as a number of seconds + /// + /// Example params structure: + /// { + /// "name": "packets-received", + /// "duration": 1245 + /// } + /// + /// @param name name of the command (ignored, should be "statistic-set-max-sample-age") + /// @param params structure containing a map that contains "name" and "duration" + /// @return answer containing information about successfully setup limit of statistic + static isc::data::ConstElementPtr + statisticSetMaxSampleAgeHandler(const std::string& name, + const isc::data::ConstElementPtr& params); + + /// @brief Handles statistic-set-max-sample-count command + /// + /// This method handles statistic-set-max-sample-count command, + /// which set max_sample_count_ limit of a given statistic + /// and leaves max_sample_age_ disabled. + /// It expects two parameters stored in params map: + /// name: name-of-the-statistic + /// max-samples: value of max_sample_count_ + /// + /// Example params structure: + /// { + /// "name": "packets-received", + /// "max-samples": 15 + /// } + /// + /// @param name name of the command (ignored, should be "statistic-set-max-sample-count") + /// @param params structure containing a map that contains "name" and "max-samples" + /// @return answer containing information about successfully setup limit of statistic + static isc::data::ConstElementPtr + statisticSetMaxSampleCountHandler(const std::string& name, + const isc::data::ConstElementPtr& params); + /// @brief Handles statistic-get-all command /// /// This method handles statistic-get-all command, which returns values @@ -336,6 +386,45 @@ class StatsMgr : public boost::noncopyable { statisticRemoveAllHandler(const std::string& name, const isc::data::ConstElementPtr& params); + /// @brief Handles statistic-set-max-sample-age-all command + /// + /// This method handles statistic-set-max-sample-age-all command, + /// which set max_sample_age_ limit to all statistics. + /// It expects one parameter stored in params map: + /// duration: limit expressed as a number of seconds + /// + /// Example params structure: + /// { + /// "duration": 1245 + /// } + /// + /// @param name name of the command (ignored, should be "statistic-set-max-sample-age-all") + /// @param params structure containing a map that contains "duration" + /// @return answer confirming success of this operation + static isc::data::ConstElementPtr + statisticSetMaxSampleAgeAllHandler(const std::string& name, + const isc::data::ConstElementPtr& params); + + /// @brief Handles statistic-set-max-sample-count command + /// + /// This method handles statistic-set-max-sample-count command, + /// which set max_sample_count_ limit of a given statistic + /// and leaves max_sample_age_ disabled. + /// It expects one parameter stored in params map: + /// max-samples: value of max_sample_count_ + /// + /// Example params structure: + /// { + /// "max-samples": 15 + /// } + /// + /// @param name name of the command (ignored, should be "statistic-set-max-sample-count") + /// @param params structure containing a map that contains "max-samples" + /// @return answer confirming success of this operation + static isc::data::ConstElementPtr + statisticSetMaxSampleCountAllHandler(const std::string& name, + const isc::data::ConstElementPtr& params); + /// @} private: @@ -433,6 +522,45 @@ private: std::string& name, std::string& reason); + /// @brief Utility method that attempts to extract duration limit for + /// a given statistic + /// + /// This method attempts to extract duration limit for a given statistic + /// from the params structure. + /// It is expected to be a map that contains four 'duration' elements: 'hours', + /// 'minutes', 'seconds' and 'milliseconds' + /// all are of type int. If present as expected, statistic duration + /// limit is set and true is returned. + /// If any of these four parameters is missing or is of incorrect type, + /// the reason is specified in reason parameter and false is returned. + /// + /// @param params parameters structure received in command + /// @param duration [out] duration limit for the statistic (if no error detected) + /// @param reason [out] failure reason (if error is detected) + /// @return true (if everything is ok), false otherwise + static bool getStatDuration(const isc::data::ConstElementPtr& params, + StatsDuration& duration, + std::string& reason); + + /// @brief Utility method that attempts to extract count limit for + /// a given statistic + /// + /// This method attempts to extract count limit for a given statistic + /// from the params structure. + /// It is expected to be a map that contains 'max_samples' element, + /// that is of type int. If present as expected, statistic count + /// limit (max_samples) is set and true is returned. + /// If missing or is of incorrect type, the reason is specified in reason + /// parameter and false is returned. + /// + /// @param params parameters structure received in command + /// @param max_samples [out] count limit for the statistic (if no error detected) + /// @param reason [out] failure reason (if error is detected) + /// @return true (if everything is ok), false otherwise + static bool getStatMaxSamples(const isc::data::ConstElementPtr& params, + uint32_t& max_samples, + std::string& reason); + // This is a global context. All statistics will initially be stored here. StatContextPtr global_; }; diff --git a/src/lib/stats/tests/observation_unittest.cc b/src/lib/stats/tests/observation_unittest.cc index 2cab680da8..e12d406626 100644 --- a/src/lib/stats/tests/observation_unittest.cc +++ b/src/lib/stats/tests/observation_unittest.cc @@ -430,6 +430,35 @@ TEST_F(ObservationTest, setAgeLimit) { } } +// Test checks whether we can get max_sample_age_ and max_sample_count_ +// properly. +TEST_F(ObservationTest, getLimits) { + // First checks whether getting default values works properly + EXPECT_EQ(a.getMaxSampleAge().first, false); + EXPECT_EQ(b.getMaxSampleAge().first, false); + EXPECT_EQ(c.getMaxSampleAge().first, false); + EXPECT_EQ(d.getMaxSampleAge().first, false); + + EXPECT_EQ(a.getMaxSampleCount().first, true); + EXPECT_EQ(b.getMaxSampleCount().first, true); + EXPECT_EQ(c.getMaxSampleCount().first, true); + EXPECT_EQ(d.getMaxSampleCount().first, true); + + EXPECT_EQ(a.getMaxSampleCount().second, 20); + EXPECT_EQ(b.getMaxSampleCount().second, 20); + EXPECT_EQ(c.getMaxSampleCount().second, 20); + EXPECT_EQ(d.getMaxSampleCount().second, 20); + + // Change limit to max_sample_age_ + a.setMaxSampleAge(millisec::time_duration(0, 4, 5, 3)); + EXPECT_EQ(a.getMaxSampleAge().first, true); + EXPECT_EQ(a.getMaxSampleAge().second, millisec::time_duration(0, 4, 5, 3)); + + EXPECT_EQ(a.getMaxSampleCount().first, false); + EXPECT_EQ(a.getMaxSampleCount().second, 20); + +} + // 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 c61636f70b..7c9ab0b5cd 100644 --- a/src/lib/stats/tests/stats_mgr_unittest.cc +++ b/src/lib/stats/tests/stats_mgr_unittest.cc @@ -136,7 +136,7 @@ TEST_F(StatsMgrTest, getSize) { EXPECT_EQ(StatsMgr::instance().getSize("delta"), 1); } -// Test checks whether setting age limit and count limit works properly +// Test checks whether setting age limit and count limit works properly. TEST_F(StatsMgrTest, setLimits) { // Initializing of an integer type observation StatsMgr::instance().setValue("foo", static_cast(1)); @@ -161,6 +161,66 @@ TEST_F(StatsMgrTest, setLimits) { EXPECT_EQ(StatsMgr::instance().getSize("foo"), 100); } +// Test checks whether setting age limit and count limit to existing +// statistics works properly. +TEST_F(StatsMgrTest, setLimitsAll) { + // 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"); + + //First, check the setting of time limit to existing statistics + EXPECT_NO_THROW(StatsMgr::instance().setMaxSampleAgeAll(time_duration(0, 0, 1, 0))); + // Now check if time limit was set properly + EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleAge().first, true); + EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleAge().second, + time_duration(0, 0, 1, 0)); + // and whether count limit is disabled + EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleCount().first, false); + + EXPECT_EQ(StatsMgr::instance().getObservation("beta")->getMaxSampleAge().first, true); + EXPECT_EQ(StatsMgr::instance().getObservation("beta")->getMaxSampleAge().second, + time_duration(0, 0, 1, 0)); + + EXPECT_EQ(StatsMgr::instance().getObservation("beta")->getMaxSampleCount().first, false); + + EXPECT_EQ(StatsMgr::instance().getObservation("gamma")->getMaxSampleAge().first, true); + EXPECT_EQ(StatsMgr::instance().getObservation("gamma")->getMaxSampleAge().second, + time_duration(0, 0, 1, 0)); + + EXPECT_EQ(StatsMgr::instance().getObservation("gamma")->getMaxSampleCount().first, false); + + EXPECT_EQ(StatsMgr::instance().getObservation("delta")->getMaxSampleAge().first, true); + EXPECT_EQ(StatsMgr::instance().getObservation("delta")->getMaxSampleAge().second, + time_duration(0, 0, 1, 0)); + + EXPECT_EQ(StatsMgr::instance().getObservation("delta")->getMaxSampleCount().first, false); + + //then, check the setting of count limit to existing statistics + EXPECT_NO_THROW(StatsMgr::instance().setMaxSampleCountAll(1200)); + // Now check if count limit was set properly + EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleCount().first, true); + EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleCount().second, 1200); + // and whether count limit is disabled + EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleAge().first, false); + + EXPECT_EQ(StatsMgr::instance().getObservation("beta")->getMaxSampleCount().first, true); + EXPECT_EQ(StatsMgr::instance().getObservation("beta")->getMaxSampleCount().second, 1200); + + EXPECT_EQ(StatsMgr::instance().getObservation("beta")->getMaxSampleAge().first, false); + + EXPECT_EQ(StatsMgr::instance().getObservation("gamma")->getMaxSampleCount().first, true); + EXPECT_EQ(StatsMgr::instance().getObservation("gamma")->getMaxSampleCount().second, 1200); + + EXPECT_EQ(StatsMgr::instance().getObservation("gamma")->getMaxSampleAge().first, false); + + EXPECT_EQ(StatsMgr::instance().getObservation("delta")->getMaxSampleCount().first, true); + EXPECT_EQ(StatsMgr::instance().getObservation("delta")->getMaxSampleCount().second, 1200); + + EXPECT_EQ(StatsMgr::instance().getObservation("delta")->getMaxSampleAge().first, false); +} + // This test checks whether a single (get("foo")) and all (getAll()) // statistics are reported properly. TEST_F(StatsMgrTest, getGetAll) { @@ -718,4 +778,199 @@ TEST_F(StatsMgrTest, commandRemoveAll) { EXPECT_EQ(0, StatsMgr::instance().count()); } +// This test checks whether statistic-set-max-sample-age command really set +// max_sample_age_ limit correctly. +TEST_F(StatsMgrTest, commandSetMaxSampleAge) { + StatsMgr::instance().setValue("alpha", static_cast(1234)); + + ElementPtr params = Element::createMap(); + params->set("name", Element::create("alpha")); + params->set("duration", Element::create(1245)); // time_duration(0, 20, 45, 0) + + ConstElementPtr rsp = + StatsMgr::instance().statisticSetMaxSampleAgeHandler("statistic-set-max-sample-age", params); + int status_code; + ASSERT_NO_THROW(parseAnswer(status_code, rsp)); + EXPECT_EQ(CONTROL_RESULT_SUCCESS, status_code); + + // Now check if time limit was set properly + EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleAge().first, true); + EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleAge().second, + time_duration(0, 20, 45, 0)); + // and whether count limit is disabled + EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleCount().first, false); +} + +// Test checks if statistic-set-max-sample-age is able to handle: +// - a request without parameters +// - a request without duration parameter +// - a request with missing statistic name +// - a request for non-existing statistic. +TEST_F(StatsMgrTest, commandSetMaxSampleAgeNegative) { + + // Case 1: a request without parameters + ConstElementPtr rsp = + StatsMgr::instance().statisticSetMaxSampleAgeHandler("statistic-set-max-sample-age", ElementPtr()); + int status_code; + ASSERT_NO_THROW(parseAnswer(status_code, rsp)); + EXPECT_EQ(status_code, CONTROL_RESULT_ERROR); + + // Case 2: a request without duration parameter + ElementPtr params = Element::createMap(); + params->set("name", Element::create("alpha")); + rsp = StatsMgr::instance().statisticSetMaxSampleAgeHandler("statistic-set-max-sample-age", params); + ASSERT_NO_THROW(parseAnswer(status_code, rsp)); + EXPECT_EQ(status_code, CONTROL_RESULT_ERROR); + + // Case 3: a request with missing statistic name + params = Element::createMap(); + params->set("duration", Element::create(100)); + rsp = StatsMgr::instance().statisticSetMaxSampleAgeHandler("statistic-set-max-sample-age", params); + ASSERT_NO_THROW(parseAnswer(status_code, rsp)); + EXPECT_EQ(status_code, CONTROL_RESULT_ERROR); + + // Case 4: a request for non-existing statistic + params->set("name", Element::create("alpha")); + rsp = StatsMgr::instance().statisticSetMaxSampleAgeHandler("statistic-set-max-sample-age", params); + EXPECT_EQ("{ \"result\": 1, \"text\": \"No 'alpha' statistic found\" }", + rsp->str()); +} + +TEST_F(StatsMgrTest, commandSetMaxSampleAgeAll) { + // 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"); + + ElementPtr params = Element::createMap(); + params->set("duration", Element::create(3765)); // time_duration(1, 2, 45, 0) + + ConstElementPtr rsp = + StatsMgr::instance().statisticSetMaxSampleAgeAllHandler("statistic-set-max-sample-age-all", params); + int status_code; + ASSERT_NO_THROW(parseAnswer(status_code, rsp)); + EXPECT_EQ(CONTROL_RESULT_SUCCESS, status_code); + + // Now check if time limit was set properly + EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleAge().first, true); + EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleAge().second, + time_duration(1, 2, 45, 0)); + // and whether count limit is disabled + EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleCount().first, false); + + EXPECT_EQ(StatsMgr::instance().getObservation("beta")->getMaxSampleAge().first, true); + EXPECT_EQ(StatsMgr::instance().getObservation("beta")->getMaxSampleAge().second, + time_duration(1, 2, 45, 0)); + + EXPECT_EQ(StatsMgr::instance().getObservation("beta")->getMaxSampleCount().first, false); + + EXPECT_EQ(StatsMgr::instance().getObservation("gamma")->getMaxSampleAge().first, true); + EXPECT_EQ(StatsMgr::instance().getObservation("gamma")->getMaxSampleAge().second, + time_duration(1, 2, 45, 0)); + + EXPECT_EQ(StatsMgr::instance().getObservation("gamma")->getMaxSampleCount().first, false); + + EXPECT_EQ(StatsMgr::instance().getObservation("delta")->getMaxSampleAge().first, true); + EXPECT_EQ(StatsMgr::instance().getObservation("delta")->getMaxSampleAge().second, + time_duration(1, 2, 45, 0)); + + EXPECT_EQ(StatsMgr::instance().getObservation("delta")->getMaxSampleCount().first, false); +} + +// This test checks whether statistic-set-max-sample-count command really set +// max_sample_count_ limit correctly. +TEST_F(StatsMgrTest, commandSetMaxSampleCount) { + StatsMgr::instance().setValue("alpha", static_cast(1234)); + + ElementPtr params = Element::createMap(); + params->set("name", Element::create("alpha")); + params->set("max-samples", Element::create(15)); + + ConstElementPtr rsp = + StatsMgr::instance().statisticSetMaxSampleCountHandler("statistic-set-max-sample-count", params); + int status_code; + ASSERT_NO_THROW(parseAnswer(status_code, rsp)); + EXPECT_EQ(CONTROL_RESULT_SUCCESS, status_code); + + // Now check if time limit was set properly + EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleCount().first, true); + EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleCount().second, 15); + + // and whether duration limit is disabled + EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleAge().first, false); +} + +// Test checks if statistic-set-max-sample-age is able to handle: +// - a request without parameters +// - a request without max-samples parameter +// - a request with missing statistic name +// - a request for non-existing statistic. +TEST_F(StatsMgrTest, commandSetMaxSampleCountNegative) { + + // Case 1: a request without parameters + ConstElementPtr rsp = + StatsMgr::instance().statisticSetMaxSampleCountHandler("statistic-set-max-sample-count", ElementPtr()); + int status_code; + ASSERT_NO_THROW(parseAnswer(status_code, rsp)); + EXPECT_EQ(status_code, CONTROL_RESULT_ERROR); + + // Case 2: a request without max-samples parameter + ElementPtr params = Element::createMap(); + params->set("name", Element::create("alpha")); + rsp = StatsMgr::instance().statisticSetMaxSampleCountHandler("statistic-set-max-sample-count", params); + ASSERT_NO_THROW(parseAnswer(status_code, rsp)); + EXPECT_EQ(status_code, CONTROL_RESULT_ERROR); + + // Case 3: a request with missing statistic name + params = Element::createMap(); + params->set("max-samples", Element::create(10)); + rsp = StatsMgr::instance().statisticSetMaxSampleCountHandler("statistic-set-max-sample-count", params); + ASSERT_NO_THROW(parseAnswer(status_code, rsp)); + EXPECT_EQ(status_code, CONTROL_RESULT_ERROR); + + // Case 4: a request for non-existing statistic + params->set("name", Element::create("alpha")); + rsp = StatsMgr::instance().statisticSetMaxSampleCountHandler("statistic-set-max-sample-count", params); + EXPECT_EQ("{ \"result\": 1, \"text\": \"No 'alpha' statistic found\" }", + rsp->str()); +} + +TEST_F(StatsMgrTest, commandSetMaxSampleCountAll) { + // 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"); + + ElementPtr params = Element::createMap(); + params->set("max-samples", Element::create(200)); + + ConstElementPtr rsp = + StatsMgr::instance().statisticSetMaxSampleCountAllHandler("statistic-set-max-sample-count-all", params); + int status_code; + ASSERT_NO_THROW(parseAnswer(status_code, rsp)); + EXPECT_EQ(CONTROL_RESULT_SUCCESS, status_code); + // Now check if count limit was set properly + EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleCount().first, true); + EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleCount().second, 200); + // and whether count limit is disabled + EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleAge().first, false); + + EXPECT_EQ(StatsMgr::instance().getObservation("beta")->getMaxSampleCount().first, true); + EXPECT_EQ(StatsMgr::instance().getObservation("beta")->getMaxSampleCount().second, 200); + + EXPECT_EQ(StatsMgr::instance().getObservation("beta")->getMaxSampleAge().first, false); + + EXPECT_EQ(StatsMgr::instance().getObservation("gamma")->getMaxSampleCount().first, true); + EXPECT_EQ(StatsMgr::instance().getObservation("gamma")->getMaxSampleCount().second, 200); + + EXPECT_EQ(StatsMgr::instance().getObservation("gamma")->getMaxSampleAge().first, false); + + EXPECT_EQ(StatsMgr::instance().getObservation("delta")->getMaxSampleCount().first, true); + EXPECT_EQ(StatsMgr::instance().getObservation("delta")->getMaxSampleCount().second, 200); + + EXPECT_EQ(StatsMgr::instance().getObservation("delta")->getMaxSampleAge().first, false); +} + }; -- GitLab From 7e90410c33f93e428e1d5fd9825ef8c70a128282 Mon Sep 17 00:00:00 2001 From: Franciszek Gorski Date: Wed, 17 Jul 2019 19:13:26 +0200 Subject: [PATCH 02/12] [731-Kea_statistics_enhancements] new statistics commands --- src/bin/dhcp4/ctrl_dhcp4_srv.cc | 18 ++++++++++ .../dhcp4/tests/ctrl_dhcp4_srv_unittest.cc | 36 +++++++++++++++++++ src/bin/dhcp6/ctrl_dhcp6_srv.cc | 16 +++++++++ .../dhcp6/tests/ctrl_dhcp6_srv_unittest.cc | 36 +++++++++++++++++++ 4 files changed, 106 insertions(+) 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. -- GitLab From 88ab289e7033570de10dfeffa94cbec5fb179a44 Mon Sep 17 00:00:00 2001 From: Franciszek Gorski Date: Fri, 26 Jul 2019 11:30:48 +0200 Subject: [PATCH 03/12] [731-Kea_statistics_enhancements] --- doc/api/statistic-set-max-sample-age-all.json | 14 ++++++++++++++ doc/api/statistic-set-max-sample-age.json | 15 +++++++++++++++ doc/api/statistic-set-max-sample-count-all.json | 14 ++++++++++++++ doc/api/statistic-set-max-sample-count.json | 15 +++++++++++++++ doc/sphinx/api/cmds-list | 6 +++++- 5 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 doc/api/statistic-set-max-sample-age-all.json create mode 100644 doc/api/statistic-set-max-sample-age.json create mode 100644 doc/api/statistic-set-max-sample-count-all.json create mode 100644 doc/api/statistic-set-max-sample-count.json diff --git a/doc/api/statistic-set-max-sample-age-all.json b/doc/api/statistic-set-max-sample-age-all.json new file mode 100644 index 0000000000..6a4513d172 --- /dev/null +++ b/doc/api/statistic-set-max-sample-age-all.json @@ -0,0 +1,14 @@ +{ + "name": "statistic-set-max-sample-age-all", + "brief": "The statistic-set-max-sample-age-all command sets time based limit for all statistics. It takes a single integer parameter called duration.", + "description": "See ", + "support": [ "kea-dhcp4", "kea-dhcp6" ], + "avail": "1.6.0", + "cmd-syntax": "{ + \"command\": \"statistic-set-max-sample-age-all\", + \"arguments\": { + \"duration\": 1245 + } +}", + "cmd-comment": "The server will respond with message about successfully setted limits for all statistics, with a result set to 0 indicating success and an empty parameters field." +} diff --git a/doc/api/statistic-set-max-sample-age.json b/doc/api/statistic-set-max-sample-age.json new file mode 100644 index 0000000000..eb8418e94e --- /dev/null +++ b/doc/api/statistic-set-max-sample-age.json @@ -0,0 +1,15 @@ +{ + "name": "statistic-set-max-sample-age", + "brief": "The statistic-set-max-sample-age command sets time based limit for single statistic. It takes two parameters: a string called name and an integer value called duration.", + "description": "See ", + "support": [ "kea-dhcp4", "kea-dhcp6" ], + "avail": "1.6.0", + "cmd-syntax": "{ + \"command\": \"statistic-set-max-sample-age\", + \"arguments\": { + \"name\": \"pkt4-received\", + \"duration\": 1245 + } +}", + "cmd-comment": "The server will respond with message about successfully setted limit for the given statistic, with a result set to 0 indicating success and an empty parameters field." +} diff --git a/doc/api/statistic-set-max-sample-count-all.json b/doc/api/statistic-set-max-sample-count-all.json new file mode 100644 index 0000000000..3b62140e02 --- /dev/null +++ b/doc/api/statistic-set-max-sample-count-all.json @@ -0,0 +1,14 @@ +{ + "name": "statistic-set-max-sample-count-all", + "brief": "The statistic-set-max-sample-count-all command sets size based limit for all statistics. It takes a single integer parameter called max-samples.", + "description": "See ", + "support": [ "kea-dhcp4", "kea-dhcp6" ], + "avail": "1.6.0", + "cmd-syntax": "{ + \"command\": \"statistic-set-max-sample-count-all\", + \"arguments\": { + \"max-samples\": 100 + } +}", + "cmd-comment": "The server will respond with message about successfully setted limits for all statistics, with a result set to 0 indicating success and an empty parameters field." +} diff --git a/doc/api/statistic-set-max-sample-count.json b/doc/api/statistic-set-max-sample-count.json new file mode 100644 index 0000000000..d0ddefbece --- /dev/null +++ b/doc/api/statistic-set-max-sample-count.json @@ -0,0 +1,15 @@ +{ + "name": "statistic-set-max-sample-count", + "brief": "The statistic-set-max-sample-count command sets size based limit for single statistic. It takes two parameters: a string called name and an integer value called max-samples.", + "description": "See ", + "support": [ "kea-dhcp4", "kea-dhcp6" ], + "avail": "1.6.0", + "cmd-syntax": "{ + \"command\": \"statistic-set-max-sample-count\", + \"arguments\": { + \"name\": \"pkt4-received\", + \"max-samples\": 100 + } +}", + "cmd-comment": "The server will respond with message about successfully setted limit for the given statistic, with a result set to 0 indicating success and an empty parameters field." +} diff --git a/doc/sphinx/api/cmds-list b/doc/sphinx/api/cmds-list index 0289e4d431..aa8c08ad5f 100644 --- a/doc/sphinx/api/cmds-list +++ b/doc/sphinx/api/cmds-list @@ -37,7 +37,7 @@ lease6-get-all lease6-update lease6-wipe leases-reclaim -libreload +libreloadAle trzeba list-commands network4-add network4-del @@ -117,6 +117,10 @@ statistic-remove statistic-remove-all statistic-reset statistic-reset-all +statistic-set-max-sample-age +statistic-set-max-sample-age-all +statistic-set-max-sample-count +statistic-set-max-sample-count-all subnet4-add subnet4-del subnet4-get -- GitLab From c4009b67580d3f2ad36762c492080278cce92283 Mon Sep 17 00:00:00 2001 From: Franciszek Gorski Date: Fri, 26 Jul 2019 13:53:28 +0200 Subject: [PATCH 04/12] [731-Kea_statistics_enhancements] add documentation --- doc/api/statistic-set-max-sample-age-all.json | 2 +- doc/api/statistic-set-max-sample-age.json | 2 +- doc/api/statistic-set-max-sample-count-all.json | 2 +- doc/api/statistic-set-max-sample-count.json | 2 +- doc/sphinx/api/cmds-list | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/doc/api/statistic-set-max-sample-age-all.json b/doc/api/statistic-set-max-sample-age-all.json index 6a4513d172..93cec1d967 100644 --- a/doc/api/statistic-set-max-sample-age-all.json +++ b/doc/api/statistic-set-max-sample-age-all.json @@ -10,5 +10,5 @@ \"duration\": 1245 } }", - "cmd-comment": "The server will respond with message about successfully setted limits for all statistics, with a result set to 0 indicating success and an empty parameters field." + "cmd-comment": "The server will respond with message about successfully setted limits for all statistics, with a result set to 0 indicating success and an empty parameters field. If an error is encountered, the server will return a status code of 1 (error) and the text field will contain the error description." } diff --git a/doc/api/statistic-set-max-sample-age.json b/doc/api/statistic-set-max-sample-age.json index eb8418e94e..9d9a8d794a 100644 --- a/doc/api/statistic-set-max-sample-age.json +++ b/doc/api/statistic-set-max-sample-age.json @@ -11,5 +11,5 @@ \"duration\": 1245 } }", - "cmd-comment": "The server will respond with message about successfully setted limit for the given statistic, with a result set to 0 indicating success and an empty parameters field." + "cmd-comment": "The server will respond with message about successfully setted limit for the given statistic, with a result set to 0 indicating success and an empty parameters field. If an error is encountered (e.g. requested statistic was not found), the server will return a status code of 1 (error) and the text field will contain the error description." } diff --git a/doc/api/statistic-set-max-sample-count-all.json b/doc/api/statistic-set-max-sample-count-all.json index 3b62140e02..4c71fc072b 100644 --- a/doc/api/statistic-set-max-sample-count-all.json +++ b/doc/api/statistic-set-max-sample-count-all.json @@ -10,5 +10,5 @@ \"max-samples\": 100 } }", - "cmd-comment": "The server will respond with message about successfully setted limits for all statistics, with a result set to 0 indicating success and an empty parameters field." + "cmd-comment": "The server will respond with message about successfully setted limits for all statistics, with a result set to 0 indicating success and an empty parameters field. If an error is encountered, the server will return a status code of 1 (error) and the text field will contain the error description." } diff --git a/doc/api/statistic-set-max-sample-count.json b/doc/api/statistic-set-max-sample-count.json index d0ddefbece..a713180593 100644 --- a/doc/api/statistic-set-max-sample-count.json +++ b/doc/api/statistic-set-max-sample-count.json @@ -11,5 +11,5 @@ \"max-samples\": 100 } }", - "cmd-comment": "The server will respond with message about successfully setted limit for the given statistic, with a result set to 0 indicating success and an empty parameters field." + "cmd-comment": "The server will respond with message about successfully setted limit for the given statistic, with a result set to 0 indicating success and an empty parameters field. If an error is encountered (e.g. requested statistic was not found), the server will return a status code of 1 (error) and the text field will contain the error description." } diff --git a/doc/sphinx/api/cmds-list b/doc/sphinx/api/cmds-list index aa8c08ad5f..b781e6c91b 100644 --- a/doc/sphinx/api/cmds-list +++ b/doc/sphinx/api/cmds-list @@ -37,7 +37,7 @@ lease6-get-all lease6-update lease6-wipe leases-reclaim -libreloadAle trzeba +libreload list-commands network4-add network4-del -- GitLab From 04553822fbc00a6fe0aae5749d3372f5761933e2 Mon Sep 17 00:00:00 2001 From: Franciszek Gorski Date: Fri, 26 Jul 2019 14:24:31 +0200 Subject: [PATCH 05/12] [731-Kea_statistics_enhancements] fixed documentation --- src/lib/stats/observation.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/lib/stats/observation.h b/src/lib/stats/observation.h index 28cf9a8bdc..a07e087725 100644 --- a/src/lib/stats/observation.h +++ b/src/lib/stats/observation.h @@ -66,8 +66,7 @@ typedef std::pair StringSample; /// @ref getDuration, @ref getString (appropriate type must be used) or /// @ref getJSON, which is generic and can be used for all types. /// -/// @todo: Eventually it will be possible to retain multiple samples for the same -/// observation, but that is outside of scope for 0.9.2. +/// Since Kea 1.6 multiple samples are stored for the same observation. class Observation { public: -- GitLab From 798f70f6181fed979a58a7bddded1c7e4f4fd20f Mon Sep 17 00:00:00 2001 From: Franciszek Gorski Date: Fri, 2 Aug 2019 09:48:37 +0200 Subject: [PATCH 06/12] [731-Kea_statistics_enhancements] rewrite stats documentation to sphinx --- .../api/statistic-set-max-sample-age-all.json | 0 .../api/statistic-set-max-sample-age.json | 0 .../statistic-set-max-sample-count-all.json | 0 .../api/statistic-set-max-sample-count.json | 0 doc/sphinx/arm/stats.rst | 128 ++++++++++++++++++ 5 files changed, 128 insertions(+) rename doc/{ => sphinx}/api/statistic-set-max-sample-age-all.json (100%) rename doc/{ => sphinx}/api/statistic-set-max-sample-age.json (100%) rename doc/{ => sphinx}/api/statistic-set-max-sample-count-all.json (100%) rename doc/{ => sphinx}/api/statistic-set-max-sample-count.json (100%) diff --git a/doc/api/statistic-set-max-sample-age-all.json b/doc/sphinx/api/statistic-set-max-sample-age-all.json similarity index 100% rename from doc/api/statistic-set-max-sample-age-all.json rename to doc/sphinx/api/statistic-set-max-sample-age-all.json diff --git a/doc/api/statistic-set-max-sample-age.json b/doc/sphinx/api/statistic-set-max-sample-age.json similarity index 100% rename from doc/api/statistic-set-max-sample-age.json rename to doc/sphinx/api/statistic-set-max-sample-age.json diff --git a/doc/api/statistic-set-max-sample-count-all.json b/doc/sphinx/api/statistic-set-max-sample-count-all.json similarity index 100% rename from doc/api/statistic-set-max-sample-count-all.json rename to doc/sphinx/api/statistic-set-max-sample-count-all.json diff --git a/doc/api/statistic-set-max-sample-count.json b/doc/sphinx/api/statistic-set-max-sample-count.json similarity index 100% rename from doc/api/statistic-set-max-sample-count.json rename to doc/sphinx/api/statistic-set-max-sample-count.json diff --git a/doc/sphinx/arm/stats.rst b/doc/sphinx/arm/stats.rst index 139504774f..80495903bc 100644 --- a/doc/sphinx/arm/stats.rst +++ b/doc/sphinx/arm/stats.rst @@ -233,3 +233,131 @@ If the removal of all statistics is successful, the server responds with a status of 0, indicating success, and an empty parameters field. If an error is encountered, the server returns a status code of 1 (error) and the text field contains the error description. + +.. _command-statistic-set-max-sample-age: + +The statistic-set-max-sample-age Command +---------------------------------------- + +The ``statistic-set-max-sample-age`` command sets time based limit +for collecting samples for given statistic. An example command may look +like this: + +:: + + { + "command": "statistic-set-max-sample-age", + "arguments": { + "name": "pkt4-received", + "duration": 1245 + } + + } + +The server will respond with message about successfully set limit +for the given statistic, with a result set to 0 indicating success +and an empty parameters field. If an error is encountered (e.g. the +requested statistic was not found), the server returns a status code +of 1 (error) and the text field contains the error description. + +.. _command-statistic-set-max-sample-age-all: + +The statistic-set-max-sample-age-all Command +-------------------------------------------- + +The ``statistic-set-max-sample-age-all`` command sets time based limits +for collecting samples for all statistics. An example command may look +like this: + +:: + + { + "command": "statistic-set-max-sample-age-all", + "arguments": { + "duration": 1245 + } + + } + +The server will respond with message about successfully set limit +for all statistics, with a result set to 0 indicating success +and an empty parameters field. If an error is encountered, the server returns +a status code of 1 (error) and the text field contains the error description. + +.. _command-statistic-set-max-sample-count: + +The statistic-set-max-sample-count Command +------------------------------------------ + +The ``statistic-set-max-sample-count`` command sets size based limit +for collecting samples for given statistic. An example command may look +like this: + +:: + + { + "command": "statistic-set-max-sample-count", + "arguments": { + "name": "pkt4-received", + "max-samples": 100 + } + + } + +The server will respond with message about successfully set limit +for the given statistic, with a result set to 0 indicating success +and an empty parameters field. If an error is encountered (e.g. the +requested statistic was not found), the server returns a status code +of 1 (error) and the text field contains the error description. + +.. _command-statistic-set-max-sample-count-all: + +The statistic-set-max-sample-count-all Command +---------------------------------------------- + +The ``statistic-set-max-sample-count-all`` command sets size based limits +for collecting samples for all statistics. An example command may look +like this: + +:: + + { + "command": "statistic-set-max-sample-count-all", + "arguments": { + "max-samples": 100 + } + + } + +The server will respond with message about successfully set limit +for all statistics, with a result set to 0 indicating success +and an empty parameters field. If an error is encountered, the server returns +a status code of 1 (error) and the text field contains the error description. + +.. _time-series: + +Time series +==================== + +Previously, by default, each statistic holded only a single data point. When Kea +attempted to record a new value, the existing previous value was +overwritten. That approach has the benefit of taking up little memory and +it covers most cases reasonably well. However, there may be cases where +you need to have many data points for some process. For example, some +processes, such as received packet size, packet processing time or number +of database queries needed to process a packet, are not cumulative and it +would be useful to keep many data points, perhaps to do some form of +statistical analysis afterwards. + + +Since Kea 1.6, by default, each statistic holds 20 data points. Setting such +limit prevent unlimited memory consumption growth. +There are two ways to define the limts: time based (e.g. keep samples from +the last 5 minutes) and size based. It's possible to change the size based +limit by using one of two commands: ``statistic-set-max-sample-count``, +to set size limit for single statistic and ``statistic-set-max-sample-count-all`` +for setting size based limits for all statistics. To set time based +limit for single statistic use ``statistic-set-max-sample-age``, +and ``statistic-set-max-sample-age-all`` to set time based limits for all statistics. +For given statistic only one type of limit can be active. It means that +storage is limited only by time based limit or size based, never by both of them. -- GitLab From 402fdc78ba9bf5da9a2b93926f7c5a313af3ac15 Mon Sep 17 00:00:00 2001 From: Razvan Becheriu Date: Mon, 5 Aug 2019 13:34:45 +0300 Subject: [PATCH 07/12] review changes --- .../api/statistic-set-max-sample-age-all.json | 2 +- .../api/statistic-set-max-sample-age.json | 2 +- .../statistic-set-max-sample-count-all.json | 2 +- .../api/statistic-set-max-sample-count.json | 2 +- doc/sphinx/arm/stats.rst | 17 +++--- src/bin/dhcp4/ctrl_dhcp4_srv.cc | 3 - src/bin/dhcp6/ctrl_dhcp6_srv.cc | 2 +- .../dhcp6/tests/ctrl_dhcp6_srv_unittest.cc | 2 +- src/lib/stats/observation.h | 4 +- src/lib/stats/stats_mgr.cc | 22 +++---- src/lib/stats/stats_mgr.h | 30 +++++----- src/lib/stats/tests/observation_unittest.cc | 23 ++++++- src/lib/stats/tests/stats_mgr_unittest.cc | 60 +++++++------------ 13 files changed, 83 insertions(+), 88 deletions(-) diff --git a/doc/sphinx/api/statistic-set-max-sample-age-all.json b/doc/sphinx/api/statistic-set-max-sample-age-all.json index 93cec1d967..5394aba218 100644 --- a/doc/sphinx/api/statistic-set-max-sample-age-all.json +++ b/doc/sphinx/api/statistic-set-max-sample-age-all.json @@ -10,5 +10,5 @@ \"duration\": 1245 } }", - "cmd-comment": "The server will respond with message about successfully setted limits for all statistics, with a result set to 0 indicating success and an empty parameters field. If an error is encountered, the server will return a status code of 1 (error) and the text field will contain the error description." + "cmd-comment": "The server will respond with message about successfully set limits for all statistics, with a result set to 0 indicating success and an empty parameters field. If an error is encountered, the server will return a status code of 1 (error) and the text field will contain the error description." } diff --git a/doc/sphinx/api/statistic-set-max-sample-age.json b/doc/sphinx/api/statistic-set-max-sample-age.json index 9d9a8d794a..20b53ffb81 100644 --- a/doc/sphinx/api/statistic-set-max-sample-age.json +++ b/doc/sphinx/api/statistic-set-max-sample-age.json @@ -11,5 +11,5 @@ \"duration\": 1245 } }", - "cmd-comment": "The server will respond with message about successfully setted limit for the given statistic, with a result set to 0 indicating success and an empty parameters field. If an error is encountered (e.g. requested statistic was not found), the server will return a status code of 1 (error) and the text field will contain the error description." + "cmd-comment": "The server will respond with message about successfully set limit for the given statistic, with a result set to 0 indicating success and an empty parameters field. If an error is encountered (e.g. requested statistic was not found), the server will return a status code of 1 (error) and the text field will contain the error description." } diff --git a/doc/sphinx/api/statistic-set-max-sample-count-all.json b/doc/sphinx/api/statistic-set-max-sample-count-all.json index 4c71fc072b..0c8df9e130 100644 --- a/doc/sphinx/api/statistic-set-max-sample-count-all.json +++ b/doc/sphinx/api/statistic-set-max-sample-count-all.json @@ -10,5 +10,5 @@ \"max-samples\": 100 } }", - "cmd-comment": "The server will respond with message about successfully setted limits for all statistics, with a result set to 0 indicating success and an empty parameters field. If an error is encountered, the server will return a status code of 1 (error) and the text field will contain the error description." + "cmd-comment": "The server will respond with message about successfully set limits for all statistics, with a result set to 0 indicating success and an empty parameters field. If an error is encountered, the server will return a status code of 1 (error) and the text field will contain the error description." } diff --git a/doc/sphinx/api/statistic-set-max-sample-count.json b/doc/sphinx/api/statistic-set-max-sample-count.json index a713180593..3bffccacab 100644 --- a/doc/sphinx/api/statistic-set-max-sample-count.json +++ b/doc/sphinx/api/statistic-set-max-sample-count.json @@ -11,5 +11,5 @@ \"max-samples\": 100 } }", - "cmd-comment": "The server will respond with message about successfully setted limit for the given statistic, with a result set to 0 indicating success and an empty parameters field. If an error is encountered (e.g. requested statistic was not found), the server will return a status code of 1 (error) and the text field will contain the error description." + "cmd-comment": "The server will respond with message about successfully set limit for the given statistic, with a result set to 0 indicating success and an empty parameters field. If an error is encountered (e.g. requested statistic was not found), the server will return a status code of 1 (error) and the text field will contain the error description." } diff --git a/doc/sphinx/arm/stats.rst b/doc/sphinx/arm/stats.rst index 80495903bc..ac53fd15cb 100644 --- a/doc/sphinx/arm/stats.rst +++ b/doc/sphinx/arm/stats.rst @@ -339,15 +339,14 @@ a status code of 1 (error) and the text field contains the error description. Time series ==================== -Previously, by default, each statistic holded only a single data point. When Kea -attempted to record a new value, the existing previous value was -overwritten. That approach has the benefit of taking up little memory and -it covers most cases reasonably well. However, there may be cases where -you need to have many data points for some process. For example, some -processes, such as received packet size, packet processing time or number -of database queries needed to process a packet, are not cumulative and it -would be useful to keep many data points, perhaps to do some form of -statistical analysis afterwards. +Previously, by default, each statistic held only a single data point. When Kea +attempted to record a new value, the existing previous value was overwritten. +That approach has the benefit of taking up little memory and it covers most +cases reasonably well. However, there may be cases where you need to have many +data points for some process. For example, some processes, such as received +packet size, packet processing time or number of database queries needed to +process a packet, are not cumulative and it would be useful to keep many data +points, perhaps to do some form of statistical analysis afterwards. Since Kea 1.6, by default, each statistic holds 20 data points. Setting such diff --git a/src/bin/dhcp4/ctrl_dhcp4_srv.cc b/src/bin/dhcp4/ctrl_dhcp4_srv.cc index a6af5b3146..8c2589b108 100644 --- a/src/bin/dhcp4/ctrl_dhcp4_srv.cc +++ b/src/bin/dhcp4/ctrl_dhcp4_srv.cc @@ -875,8 +875,6 @@ ControlledDhcpv4Srv::ControlledDhcpv4Srv(uint16_t server_port /*= DHCP4_SERVER_P CommandMgr::instance().registerCommand("statistic-set-max-sample-count-all", boost::bind(&StatsMgr::statisticSetMaxSampleCountAllHandler, _1, _2)); - - } void ControlledDhcpv4Srv::shutdown() { @@ -922,7 +920,6 @@ ControlledDhcpv4Srv::~ControlledDhcpv4Srv() { 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/dhcp6/ctrl_dhcp6_srv.cc b/src/bin/dhcp6/ctrl_dhcp6_srv.cc index 6d4a74b3d1..3552f7eedf 100644 --- a/src/bin/dhcp6/ctrl_dhcp6_srv.cc +++ b/src/bin/dhcp6/ctrl_dhcp6_srv.cc @@ -941,7 +941,7 @@ ControlledDhcpv6Srv::~ControlledDhcpv6Srv() { 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("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 733ca4e8f1..77f2640bfa 100644 --- a/src/bin/dhcp6/tests/ctrl_dhcp6_srv_unittest.cc +++ b/src/bin/dhcp6/tests/ctrl_dhcp6_srv_unittest.cc @@ -1089,7 +1089,7 @@ TEST_F(CtrlChannelDhcpv6SrvTest, commandsList) { 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, "statistic-set-max-sample-count-all"); } // Tests if the server returns its configuration using config-get. diff --git a/src/lib/stats/observation.h b/src/lib/stats/observation.h index a07e087725..d979500554 100644 --- a/src/lib/stats/observation.h +++ b/src/lib/stats/observation.h @@ -193,12 +193,12 @@ class Observation { /// @return size of storage size_t getSize() const; - /// @brief Returns both value of max_sample_age_ of statistic. + /// @brief Returns both values of max_sample_age_ of statistic. /// /// @return max_sample_age_. std::pair getMaxSampleAge() const; - /// @brief Returns both value of max_sample_count_ of statistic. + /// @brief Returns both values of max_sample_count_ of statistic. /// /// @return max_sample_count_. std::pair getMaxSampleCount() const; diff --git a/src/lib/stats/stats_mgr.cc b/src/lib/stats/stats_mgr.cc index 444b5e49b8..70a6edb29c 100644 --- a/src/lib/stats/stats_mgr.cc +++ b/src/lib/stats/stats_mgr.cc @@ -195,7 +195,7 @@ StatsMgr::statisticSetMaxSampleAgeHandler(const std::string& /*name*/, if (!getStatDuration(params, duration, error)) { return (createAnswer(CONTROL_RESULT_ERROR, error)); } - if (instance().setMaxSampleAge(name, duration)) { + if (setMaxSampleAge(name, duration)) { return (createAnswer(CONTROL_RESULT_SUCCESS, "Statistic '" + name + "' duration limit is set.")); } else { @@ -215,7 +215,7 @@ StatsMgr::statisticSetMaxSampleCountHandler(const std::string& /*name*/, if (!getStatMaxSamples(params, max_samples, error)) { return (createAnswer(CONTROL_RESULT_ERROR, error)); } - if (instance().setMaxSampleCount(name, max_samples)) { + if (setMaxSampleCount(name, max_samples)) { return (createAnswer(CONTROL_RESULT_SUCCESS, "Statistic '" + name + "' count limit is set.")); } else { @@ -300,7 +300,7 @@ StatsMgr::statisticSetMaxSampleAgeAllHandler(const std::string& /*name*/, if (!getStatDuration(params, duration, error)) { return (createAnswer(CONTROL_RESULT_ERROR, error)); } - instance().setMaxSampleAgeAll(duration); + setMaxSampleAgeAll(duration); return (createAnswer(CONTROL_RESULT_SUCCESS, "All statistics duration limit are set.")); } @@ -313,7 +313,7 @@ StatsMgr::statisticSetMaxSampleCountAllHandler(const std::string& /*name*/, if (!getStatMaxSamples(params, max_samples, error)) { return (createAnswer(CONTROL_RESULT_ERROR, error)); } - instance().setMaxSampleCountAll(max_samples); + setMaxSampleCountAll(max_samples); return (createAnswer(CONTROL_RESULT_SUCCESS, "All statistics count limit are set.")); } @@ -354,16 +354,16 @@ StatsMgr::getStatDuration(const isc::data::ConstElementPtr& params, return (false); } - int64_t dur = stat_duration->intValue(); + int64_t time_duration = stat_duration->intValue(); - int64_t hours = dur/3600; - dur = dur - hours*3600; + int64_t hours = time_duration / 3600; + time_duration -= hours * 3600; - int64_t minutes = dur/60; - dur = dur - minutes*60; + int64_t minutes = time_duration / 60; + time_duration -= minutes * 60; - int64_t seconds = dur; - duration = boost::posix_time::time_duration(hours,minutes,seconds,0); + int64_t seconds = time_duration; + duration = boost::posix_time::time_duration(hours, minutes, seconds, 0); return (true); } diff --git a/src/lib/stats/stats_mgr.h b/src/lib/stats/stats_mgr.h index 3ba00ad072..11dc2d5abf 100644 --- a/src/lib/stats/stats_mgr.h +++ b/src/lib/stats/stats_mgr.h @@ -149,7 +149,7 @@ class StatsMgr : public boost::noncopyable { /// /// Specifies that statistic name should be stored not as single value, but /// rather as a set of values. In this form, at most max_samples will be kept. - /// When adding max_samples+1 sample, the oldest sample will be discarded. + /// When adding max_samples + 1 sample, the oldest sample will be discarded. /// /// /// @param name name of the observation @@ -256,7 +256,7 @@ class StatsMgr : public boost::noncopyable { /// /// This method handles statistic-get command, which returns value /// of a given statistic). It expects one parameter stored in params map: - /// name: name-of-the-statistic + /// name: name of the statistic /// /// Example params structure: /// { @@ -274,7 +274,7 @@ class StatsMgr : public boost::noncopyable { /// /// This method handles statistic-reset command, which resets value /// of a given statistic. It expects one parameter stored in params map: - /// name: name-of-the-statistic + /// name: name of the statistic /// /// Example params structure: /// { @@ -292,7 +292,7 @@ class StatsMgr : public boost::noncopyable { /// /// This method handles statistic-reset command, which removes a given /// statistic completely. It expects one parameter stored in params map: - /// name: name-of-the-statistic + /// name: name of the statistic /// /// Example params structure: /// { @@ -312,7 +312,7 @@ class StatsMgr : public boost::noncopyable { /// which set max_sample_age_ limit of a given statistic /// and leaves max_sample_count_ disabled. /// It expects two parameters stored in params map: - /// name: name-of-the-statistic + /// name: name of the statistic /// duration: time limit expressed as a number of seconds /// /// Example params structure: @@ -334,8 +334,8 @@ class StatsMgr : public boost::noncopyable { /// which set max_sample_count_ limit of a given statistic /// and leaves max_sample_age_ disabled. /// It expects two parameters stored in params map: - /// name: name-of-the-statistic - /// max-samples: value of max_sample_count_ + /// name: name of the statistic + /// max-samples: count limit /// /// Example params structure: /// { @@ -348,7 +348,7 @@ class StatsMgr : public boost::noncopyable { /// @return answer containing information about successfully setup limit of statistic static isc::data::ConstElementPtr statisticSetMaxSampleCountHandler(const std::string& name, - const isc::data::ConstElementPtr& params); + const isc::data::ConstElementPtr& params); /// @brief Handles statistic-get-all command /// @@ -403,27 +403,27 @@ class StatsMgr : public boost::noncopyable { /// @return answer confirming success of this operation static isc::data::ConstElementPtr statisticSetMaxSampleAgeAllHandler(const std::string& name, - const isc::data::ConstElementPtr& params); + const isc::data::ConstElementPtr& params); - /// @brief Handles statistic-set-max-sample-count command + /// @brief Handles statistic-set-max-sample-count-all command /// - /// This method handles statistic-set-max-sample-count command, + /// This method handles statistic-set-max-sample-count-all command, /// which set max_sample_count_ limit of a given statistic /// and leaves max_sample_age_ disabled. /// It expects one parameter stored in params map: - /// max-samples: value of max_sample_count_ + /// max-samples: count limit /// /// Example params structure: /// { /// "max-samples": 15 /// } /// - /// @param name name of the command (ignored, should be "statistic-set-max-sample-count") + /// @param name name of the command (ignored, should be "statistic-set-max-sample-count-all") /// @param params structure containing a map that contains "max-samples" /// @return answer confirming success of this operation static isc::data::ConstElementPtr statisticSetMaxSampleCountAllHandler(const std::string& name, - const isc::data::ConstElementPtr& params); + const isc::data::ConstElementPtr& params); /// @} @@ -547,7 +547,7 @@ private: /// /// This method attempts to extract count limit for a given statistic /// from the params structure. - /// It is expected to be a map that contains 'max_samples' element, + /// It is expected to be a map that contains 'max-samples' element, /// that is of type int. If present as expected, statistic count /// limit (max_samples) is set and true is returned. /// If missing or is of incorrect type, the reason is specified in reason diff --git a/src/lib/stats/tests/observation_unittest.cc b/src/lib/stats/tests/observation_unittest.cc index e12d406626..f2e066ac3f 100644 --- a/src/lib/stats/tests/observation_unittest.cc +++ b/src/lib/stats/tests/observation_unittest.cc @@ -449,14 +449,31 @@ TEST_F(ObservationTest, getLimits) { EXPECT_EQ(c.getMaxSampleCount().second, 20); EXPECT_EQ(d.getMaxSampleCount().second, 20); - // Change limit to max_sample_age_ - a.setMaxSampleAge(millisec::time_duration(0, 4, 5, 3)); + // change limit to time duration + ASSERT_NOT_THROW(a.setMaxSampleAge(millisec::time_duration(0, 4, 5, 3))); + ASSERT_NOT_THROW(b.setMaxSampleAge(millisec::time_duration(0, 4, 5, 3))); + ASSERT_NOT_THROW(c.setMaxSampleAge(millisec::time_duration(0, 4, 5, 3))); + ASSERT_NOT_THROW(d.setMaxSampleAge(millisec::time_duration(0, 4, 5, 3))); + EXPECT_EQ(a.getMaxSampleAge().first, true); + EXPECT_EQ(b.getMaxSampleAge().first, true); + EXPECT_EQ(c.getMaxSampleAge().first, true); + EXPECT_EQ(d.getMaxSampleAge().first, true); + EXPECT_EQ(a.getMaxSampleAge().second, millisec::time_duration(0, 4, 5, 3)); + EXPECT_EQ(b.getMaxSampleAge().second, millisec::time_duration(0, 4, 5, 3)); + EXPECT_EQ(c.getMaxSampleAge().second, millisec::time_duration(0, 4, 5, 3)); + EXPECT_EQ(d.getMaxSampleAge().second, millisec::time_duration(0, 4, 5, 3)); EXPECT_EQ(a.getMaxSampleCount().first, false); - EXPECT_EQ(a.getMaxSampleCount().second, 20); + EXPECT_EQ(b.getMaxSampleCount().first, false); + EXPECT_EQ(c.getMaxSampleCount().first, false); + EXPECT_EQ(d.getMaxSampleCount().first, false); + EXPECT_EQ(a.getMaxSampleCount().second, 20); + EXPECT_EQ(b.getMaxSampleCount().second, 20); + EXPECT_EQ(c.getMaxSampleCount().second, 20); + EXPECT_EQ(d.getMaxSampleCount().second, 20); } // Test checks whether timing is reported properly. diff --git a/src/lib/stats/tests/stats_mgr_unittest.cc b/src/lib/stats/tests/stats_mgr_unittest.cc index 7c9ab0b5cd..b662e5fb4f 100644 --- a/src/lib/stats/tests/stats_mgr_unittest.cc +++ b/src/lib/stats/tests/stats_mgr_unittest.cc @@ -170,54 +170,48 @@ TEST_F(StatsMgrTest, setLimitsAll) { StatsMgr::instance().setValue("gamma", time_duration(1, 2, 3, 4)); StatsMgr::instance().setValue("delta", "Lorem ipsum"); - //First, check the setting of time limit to existing statistics + // check the setting of time limit to existing statistics EXPECT_NO_THROW(StatsMgr::instance().setMaxSampleAgeAll(time_duration(0, 0, 1, 0))); - // Now check if time limit was set properly + + // check if time limit was set properly and whether count limit is disabled EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleAge().first, true); EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleAge().second, - time_duration(0, 0, 1, 0)); - // and whether count limit is disabled + time_duration(0, 0, 1, 0)); EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleCount().first, false); EXPECT_EQ(StatsMgr::instance().getObservation("beta")->getMaxSampleAge().first, true); EXPECT_EQ(StatsMgr::instance().getObservation("beta")->getMaxSampleAge().second, - time_duration(0, 0, 1, 0)); - + time_duration(0, 0, 1, 0)); EXPECT_EQ(StatsMgr::instance().getObservation("beta")->getMaxSampleCount().first, false); EXPECT_EQ(StatsMgr::instance().getObservation("gamma")->getMaxSampleAge().first, true); EXPECT_EQ(StatsMgr::instance().getObservation("gamma")->getMaxSampleAge().second, - time_duration(0, 0, 1, 0)); - + time_duration(0, 0, 1, 0)); EXPECT_EQ(StatsMgr::instance().getObservation("gamma")->getMaxSampleCount().first, false); EXPECT_EQ(StatsMgr::instance().getObservation("delta")->getMaxSampleAge().first, true); EXPECT_EQ(StatsMgr::instance().getObservation("delta")->getMaxSampleAge().second, - time_duration(0, 0, 1, 0)); - + time_duration(0, 0, 1, 0)); EXPECT_EQ(StatsMgr::instance().getObservation("delta")->getMaxSampleCount().first, false); - //then, check the setting of count limit to existing statistics + // check the setting of count limit to existing statistics EXPECT_NO_THROW(StatsMgr::instance().setMaxSampleCountAll(1200)); - // Now check if count limit was set properly + + // check if count limit was set properly and whether count limit is disabled EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleCount().first, true); EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleCount().second, 1200); - // and whether count limit is disabled EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleAge().first, false); EXPECT_EQ(StatsMgr::instance().getObservation("beta")->getMaxSampleCount().first, true); EXPECT_EQ(StatsMgr::instance().getObservation("beta")->getMaxSampleCount().second, 1200); - EXPECT_EQ(StatsMgr::instance().getObservation("beta")->getMaxSampleAge().first, false); EXPECT_EQ(StatsMgr::instance().getObservation("gamma")->getMaxSampleCount().first, true); EXPECT_EQ(StatsMgr::instance().getObservation("gamma")->getMaxSampleCount().second, 1200); - EXPECT_EQ(StatsMgr::instance().getObservation("gamma")->getMaxSampleAge().first, false); EXPECT_EQ(StatsMgr::instance().getObservation("delta")->getMaxSampleCount().first, true); EXPECT_EQ(StatsMgr::instance().getObservation("delta")->getMaxSampleCount().second, 1200); - EXPECT_EQ(StatsMgr::instance().getObservation("delta")->getMaxSampleAge().first, false); } @@ -793,11 +787,10 @@ TEST_F(StatsMgrTest, commandSetMaxSampleAge) { ASSERT_NO_THROW(parseAnswer(status_code, rsp)); EXPECT_EQ(CONTROL_RESULT_SUCCESS, status_code); - // Now check if time limit was set properly + // check if time limit was set properly and whether count limit is disabled EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleAge().first, true); EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleAge().second, - time_duration(0, 20, 45, 0)); - // and whether count limit is disabled + time_duration(0, 20, 45, 0)); EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleCount().first, false); } @@ -807,7 +800,6 @@ TEST_F(StatsMgrTest, commandSetMaxSampleAge) { // - a request with missing statistic name // - a request for non-existing statistic. TEST_F(StatsMgrTest, commandSetMaxSampleAgeNegative) { - // Case 1: a request without parameters ConstElementPtr rsp = StatsMgr::instance().statisticSetMaxSampleAgeHandler("statistic-set-max-sample-age", ElementPtr()); @@ -852,29 +844,25 @@ TEST_F(StatsMgrTest, commandSetMaxSampleAgeAll) { ASSERT_NO_THROW(parseAnswer(status_code, rsp)); EXPECT_EQ(CONTROL_RESULT_SUCCESS, status_code); - // Now check if time limit was set properly + // check if time limit was set properly and whether count limit is disabled EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleAge().first, true); EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleAge().second, - time_duration(1, 2, 45, 0)); - // and whether count limit is disabled + time_duration(1, 2, 45, 0)); EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleCount().first, false); EXPECT_EQ(StatsMgr::instance().getObservation("beta")->getMaxSampleAge().first, true); EXPECT_EQ(StatsMgr::instance().getObservation("beta")->getMaxSampleAge().second, - time_duration(1, 2, 45, 0)); - + time_duration(1, 2, 45, 0)); EXPECT_EQ(StatsMgr::instance().getObservation("beta")->getMaxSampleCount().first, false); EXPECT_EQ(StatsMgr::instance().getObservation("gamma")->getMaxSampleAge().first, true); EXPECT_EQ(StatsMgr::instance().getObservation("gamma")->getMaxSampleAge().second, - time_duration(1, 2, 45, 0)); - + time_duration(1, 2, 45, 0)); EXPECT_EQ(StatsMgr::instance().getObservation("gamma")->getMaxSampleCount().first, false); EXPECT_EQ(StatsMgr::instance().getObservation("delta")->getMaxSampleAge().first, true); EXPECT_EQ(StatsMgr::instance().getObservation("delta")->getMaxSampleAge().second, - time_duration(1, 2, 45, 0)); - + time_duration(1, 2, 45, 0)); EXPECT_EQ(StatsMgr::instance().getObservation("delta")->getMaxSampleCount().first, false); } @@ -893,21 +881,18 @@ TEST_F(StatsMgrTest, commandSetMaxSampleCount) { ASSERT_NO_THROW(parseAnswer(status_code, rsp)); EXPECT_EQ(CONTROL_RESULT_SUCCESS, status_code); - // Now check if time limit was set properly + // check if time limit was set properly and whether duration limit is disabled EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleCount().first, true); EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleCount().second, 15); - - // and whether duration limit is disabled EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleAge().first, false); } -// Test checks if statistic-set-max-sample-age is able to handle: +// Test checks if statistic-set-max-sample-count is able to handle: // - a request without parameters // - a request without max-samples parameter // - a request with missing statistic name // - a request for non-existing statistic. TEST_F(StatsMgrTest, commandSetMaxSampleCountNegative) { - // Case 1: a request without parameters ConstElementPtr rsp = StatsMgr::instance().statisticSetMaxSampleCountHandler("statistic-set-max-sample-count", ElementPtr()); @@ -951,25 +936,22 @@ TEST_F(StatsMgrTest, commandSetMaxSampleCountAll) { int status_code; ASSERT_NO_THROW(parseAnswer(status_code, rsp)); EXPECT_EQ(CONTROL_RESULT_SUCCESS, status_code); - // Now check if count limit was set properly + + // check if count limit was set properly and whether count limit is disabled EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleCount().first, true); EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleCount().second, 200); - // and whether count limit is disabled EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleAge().first, false); EXPECT_EQ(StatsMgr::instance().getObservation("beta")->getMaxSampleCount().first, true); EXPECT_EQ(StatsMgr::instance().getObservation("beta")->getMaxSampleCount().second, 200); - EXPECT_EQ(StatsMgr::instance().getObservation("beta")->getMaxSampleAge().first, false); EXPECT_EQ(StatsMgr::instance().getObservation("gamma")->getMaxSampleCount().first, true); EXPECT_EQ(StatsMgr::instance().getObservation("gamma")->getMaxSampleCount().second, 200); - EXPECT_EQ(StatsMgr::instance().getObservation("gamma")->getMaxSampleAge().first, false); EXPECT_EQ(StatsMgr::instance().getObservation("delta")->getMaxSampleCount().first, true); EXPECT_EQ(StatsMgr::instance().getObservation("delta")->getMaxSampleCount().second, 200); - EXPECT_EQ(StatsMgr::instance().getObservation("delta")->getMaxSampleAge().first, false); } -- GitLab From 61fd37285b5008f12995b8cef923577384fbe783 Mon Sep 17 00:00:00 2001 From: Razvan Becheriu Date: Mon, 5 Aug 2019 14:08:50 +0300 Subject: [PATCH 08/12] fixed compilation --- src/lib/stats/stats_mgr.cc | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/lib/stats/stats_mgr.cc b/src/lib/stats/stats_mgr.cc index 70a6edb29c..25ad50086f 100644 --- a/src/lib/stats/stats_mgr.cc +++ b/src/lib/stats/stats_mgr.cc @@ -189,13 +189,13 @@ StatsMgr::statisticSetMaxSampleAgeHandler(const std::string& /*name*/, const isc::data::ConstElementPtr& params) { std::string name, error; StatsDuration duration; - if (!getStatName(params, name, error)) { + if (!StatsMgr::getStatName(params, name, error)) { return (createAnswer(CONTROL_RESULT_ERROR, error)); } - if (!getStatDuration(params, duration, error)) { + if (!StatsMgr::getStatDuration(params, duration, error)) { return (createAnswer(CONTROL_RESULT_ERROR, error)); } - if (setMaxSampleAge(name, duration)) { + if (StatsMgr::instance().setMaxSampleAge(name, duration)) { return (createAnswer(CONTROL_RESULT_SUCCESS, "Statistic '" + name + "' duration limit is set.")); } else { @@ -209,13 +209,13 @@ StatsMgr::statisticSetMaxSampleCountHandler(const std::string& /*name*/, const isc::data::ConstElementPtr& params) { std::string name, error; uint32_t max_samples; - if (!getStatName(params, name, error)) { + if (!StatsMgr::getStatName(params, name, error)) { return (createAnswer(CONTROL_RESULT_ERROR, error)); } - if (!getStatMaxSamples(params, max_samples, error)) { + if (!StatsMgr::getStatMaxSamples(params, max_samples, error)) { return (createAnswer(CONTROL_RESULT_ERROR, error)); } - if (setMaxSampleCount(name, max_samples)) { + if (StatsMgr::instance().setMaxSampleCount(name, max_samples)) { return (createAnswer(CONTROL_RESULT_SUCCESS, "Statistic '" + name + "' count limit is set.")); } else { @@ -228,22 +228,22 @@ isc::data::ConstElementPtr StatsMgr::statisticGetHandler(const std::string& /*name*/, const isc::data::ConstElementPtr& params) { std::string name, error; - if (!getStatName(params, name, error)) { + if (!StatsMgr::getStatName(params, name, error)) { return (createAnswer(CONTROL_RESULT_ERROR, error)); } return (createAnswer(CONTROL_RESULT_SUCCESS, - instance().get(name))); + StatsMgr::instance().get(name))); } isc::data::ConstElementPtr StatsMgr::statisticResetHandler(const std::string& /*name*/, const isc::data::ConstElementPtr& params) { std::string name, error; - if (!getStatName(params, name, error)) { + if (!StatsMgr::getStatName(params, name, error)) { return (createAnswer(CONTROL_RESULT_ERROR, error)); } - if (instance().reset(name)) { + if (StatsMgr::instance().reset(name)) { return (createAnswer(CONTROL_RESULT_SUCCESS, "Statistic '" + name + "' reset.")); } else { @@ -256,10 +256,10 @@ isc::data::ConstElementPtr StatsMgr::statisticRemoveHandler(const std::string& /*name*/, const isc::data::ConstElementPtr& params) { std::string name, error; - if (!getStatName(params, name, error)) { + if (!StatsMgr::getStatName(params, name, error)) { return (createAnswer(CONTROL_RESULT_ERROR, error)); } - if (instance().del(name)) { + if (StatsMgr::instance().del(name)) { return (createAnswer(CONTROL_RESULT_SUCCESS, "Statistic '" + name + "' removed.")); } else { @@ -272,7 +272,7 @@ StatsMgr::statisticRemoveHandler(const std::string& /*name*/, isc::data::ConstElementPtr StatsMgr::statisticRemoveAllHandler(const std::string& /*name*/, const isc::data::ConstElementPtr& /*params*/) { - instance().removeAll(); + StatsMgr::instance().removeAll(); return (createAnswer(CONTROL_RESULT_SUCCESS, "All statistics removed.")); } @@ -280,14 +280,14 @@ StatsMgr::statisticRemoveAllHandler(const std::string& /*name*/, isc::data::ConstElementPtr StatsMgr::statisticGetAllHandler(const std::string& /*name*/, const isc::data::ConstElementPtr& /*params*/) { - ConstElementPtr all_stats = instance().getAll(); + ConstElementPtr all_stats = StatsMgr::instance().getAll(); return (createAnswer(CONTROL_RESULT_SUCCESS, all_stats)); } isc::data::ConstElementPtr StatsMgr::statisticResetAllHandler(const std::string& /*name*/, const isc::data::ConstElementPtr& /*params*/) { - instance().resetAll(); + StatsMgr::instance().resetAll(); return (createAnswer(CONTROL_RESULT_SUCCESS, "All statistics reset to neutral values.")); } @@ -297,10 +297,10 @@ StatsMgr::statisticSetMaxSampleAgeAllHandler(const std::string& /*name*/, const isc::data::ConstElementPtr& params) { std::string error; StatsDuration duration; - if (!getStatDuration(params, duration, error)) { + if (!StatsMgr::getStatDuration(params, duration, error)) { return (createAnswer(CONTROL_RESULT_ERROR, error)); } - setMaxSampleAgeAll(duration); + StatsMgr::instance().setMaxSampleAgeAll(duration); return (createAnswer(CONTROL_RESULT_SUCCESS, "All statistics duration limit are set.")); } @@ -310,10 +310,10 @@ StatsMgr::statisticSetMaxSampleCountAllHandler(const std::string& /*name*/, const isc::data::ConstElementPtr& params) { std::string error; uint32_t max_samples; - if (!getStatMaxSamples(params, max_samples, error)) { + if (!StatsMgr::getStatMaxSamples(params, max_samples, error)) { return (createAnswer(CONTROL_RESULT_ERROR, error)); } - setMaxSampleCountAll(max_samples); + StatsMgr::instance().setMaxSampleCountAll(max_samples); return (createAnswer(CONTROL_RESULT_SUCCESS, "All statistics count limit are set.")); } -- GitLab From 09851a0d39712ab701ac2140bca4c0c6f4f6c704 Mon Sep 17 00:00:00 2001 From: Razvan Becheriu Date: Mon, 5 Aug 2019 14:10:55 +0300 Subject: [PATCH 09/12] fixed compilation --- src/lib/stats/tests/observation_unittest.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lib/stats/tests/observation_unittest.cc b/src/lib/stats/tests/observation_unittest.cc index f2e066ac3f..f241b19da3 100644 --- a/src/lib/stats/tests/observation_unittest.cc +++ b/src/lib/stats/tests/observation_unittest.cc @@ -450,10 +450,10 @@ TEST_F(ObservationTest, getLimits) { EXPECT_EQ(d.getMaxSampleCount().second, 20); // change limit to time duration - ASSERT_NOT_THROW(a.setMaxSampleAge(millisec::time_duration(0, 4, 5, 3))); - ASSERT_NOT_THROW(b.setMaxSampleAge(millisec::time_duration(0, 4, 5, 3))); - ASSERT_NOT_THROW(c.setMaxSampleAge(millisec::time_duration(0, 4, 5, 3))); - ASSERT_NOT_THROW(d.setMaxSampleAge(millisec::time_duration(0, 4, 5, 3))); + ASSERT_NO_THROW(a.setMaxSampleAge(millisec::time_duration(0, 4, 5, 3))); + ASSERT_NO_THROW(b.setMaxSampleAge(millisec::time_duration(0, 4, 5, 3))); + ASSERT_NO_THROW(c.setMaxSampleAge(millisec::time_duration(0, 4, 5, 3))); + ASSERT_NO_THROW(d.setMaxSampleAge(millisec::time_duration(0, 4, 5, 3))); EXPECT_EQ(a.getMaxSampleAge().first, true); EXPECT_EQ(b.getMaxSampleAge().first, true); -- GitLab From 46fd89e83604bab05a84699820d4d6a3e1c51a64 Mon Sep 17 00:00:00 2001 From: Razvan Becheriu Date: Mon, 5 Aug 2019 18:17:48 +0300 Subject: [PATCH 10/12] renamed commands --- doc/sphinx/api/cmds-list | 8 ++-- ...json => statistic-sample-age-set-all.json} | 8 ++-- ...age.json => statistic-sample-age-set.json} | 8 ++-- ...on => statistic-sample-count-set-all.json} | 8 ++-- ...t.json => statistic-sample-count-set.json} | 8 ++-- doc/sphinx/arm/stats.rst | 44 +++++++++---------- src/bin/dhcp4/ctrl_dhcp4_srv.cc | 20 ++++----- .../dhcp4/tests/ctrl_dhcp4_srv_unittest.cc | 32 +++++++------- src/bin/dhcp6/ctrl_dhcp6_srv.cc | 20 ++++----- .../dhcp6/tests/ctrl_dhcp6_srv_unittest.cc | 32 +++++++------- src/lib/stats/stats_mgr.h | 24 +++++----- src/lib/stats/tests/stats_mgr_unittest.cc | 32 +++++++------- 12 files changed, 122 insertions(+), 122 deletions(-) rename doc/sphinx/api/{statistic-set-max-sample-age-all.json => statistic-sample-age-set-all.json} (57%) rename doc/sphinx/api/{statistic-set-max-sample-age.json => statistic-sample-age-set.json} (60%) rename doc/sphinx/api/{statistic-set-max-sample-count-all.json => statistic-sample-count-set-all.json} (56%) rename doc/sphinx/api/{statistic-set-max-sample-count.json => statistic-sample-count-set.json} (59%) diff --git a/doc/sphinx/api/cmds-list b/doc/sphinx/api/cmds-list index b781e6c91b..bcfaf87c37 100644 --- a/doc/sphinx/api/cmds-list +++ b/doc/sphinx/api/cmds-list @@ -117,10 +117,10 @@ statistic-remove statistic-remove-all statistic-reset statistic-reset-all -statistic-set-max-sample-age -statistic-set-max-sample-age-all -statistic-set-max-sample-count -statistic-set-max-sample-count-all +statistic-sample-age-set +statistic-sample-age-set-all +statistic-sample-count-set +statistic-sample-count-set-all subnet4-add subnet4-del subnet4-get diff --git a/doc/sphinx/api/statistic-set-max-sample-age-all.json b/doc/sphinx/api/statistic-sample-age-set-all.json similarity index 57% rename from doc/sphinx/api/statistic-set-max-sample-age-all.json rename to doc/sphinx/api/statistic-sample-age-set-all.json index 5394aba218..09f172b074 100644 --- a/doc/sphinx/api/statistic-set-max-sample-age-all.json +++ b/doc/sphinx/api/statistic-sample-age-set-all.json @@ -1,11 +1,11 @@ { - "name": "statistic-set-max-sample-age-all", - "brief": "The statistic-set-max-sample-age-all command sets time based limit for all statistics. It takes a single integer parameter called duration.", - "description": "See ", + "name": "statistic-sample-age-set-all", + "brief": "The statistic-sample-age-set-all command sets time based limit for all statistics. It takes a single integer parameter called duration.", + "description": "See ", "support": [ "kea-dhcp4", "kea-dhcp6" ], "avail": "1.6.0", "cmd-syntax": "{ - \"command\": \"statistic-set-max-sample-age-all\", + \"command\": \"statistic-sample-age-set-all\", \"arguments\": { \"duration\": 1245 } diff --git a/doc/sphinx/api/statistic-set-max-sample-age.json b/doc/sphinx/api/statistic-sample-age-set.json similarity index 60% rename from doc/sphinx/api/statistic-set-max-sample-age.json rename to doc/sphinx/api/statistic-sample-age-set.json index 20b53ffb81..42d22bdd3c 100644 --- a/doc/sphinx/api/statistic-set-max-sample-age.json +++ b/doc/sphinx/api/statistic-sample-age-set.json @@ -1,11 +1,11 @@ { - "name": "statistic-set-max-sample-age", - "brief": "The statistic-set-max-sample-age command sets time based limit for single statistic. It takes two parameters: a string called name and an integer value called duration.", - "description": "See ", + "name": "statistic-sample-age-set", + "brief": "The statistic-sample-age-set command sets time based limit for single statistic. It takes two parameters: a string called name and an integer value called duration.", + "description": "See ", "support": [ "kea-dhcp4", "kea-dhcp6" ], "avail": "1.6.0", "cmd-syntax": "{ - \"command\": \"statistic-set-max-sample-age\", + \"command\": \"statistic-sample-age-set\", \"arguments\": { \"name\": \"pkt4-received\", \"duration\": 1245 diff --git a/doc/sphinx/api/statistic-set-max-sample-count-all.json b/doc/sphinx/api/statistic-sample-count-set-all.json similarity index 56% rename from doc/sphinx/api/statistic-set-max-sample-count-all.json rename to doc/sphinx/api/statistic-sample-count-set-all.json index 0c8df9e130..ef7ba34809 100644 --- a/doc/sphinx/api/statistic-set-max-sample-count-all.json +++ b/doc/sphinx/api/statistic-sample-count-set-all.json @@ -1,11 +1,11 @@ { - "name": "statistic-set-max-sample-count-all", - "brief": "The statistic-set-max-sample-count-all command sets size based limit for all statistics. It takes a single integer parameter called max-samples.", - "description": "See ", + "name": "statistic-sample-count-set-all", + "brief": "The statistic-sample-count-set-all command sets size based limit for all statistics. It takes a single integer parameter called max-samples.", + "description": "See ", "support": [ "kea-dhcp4", "kea-dhcp6" ], "avail": "1.6.0", "cmd-syntax": "{ - \"command\": \"statistic-set-max-sample-count-all\", + \"command\": \"statistic-sample-count-set-all\", \"arguments\": { \"max-samples\": 100 } diff --git a/doc/sphinx/api/statistic-set-max-sample-count.json b/doc/sphinx/api/statistic-sample-count-set.json similarity index 59% rename from doc/sphinx/api/statistic-set-max-sample-count.json rename to doc/sphinx/api/statistic-sample-count-set.json index 3bffccacab..7f9ad07103 100644 --- a/doc/sphinx/api/statistic-set-max-sample-count.json +++ b/doc/sphinx/api/statistic-sample-count-set.json @@ -1,11 +1,11 @@ { - "name": "statistic-set-max-sample-count", - "brief": "The statistic-set-max-sample-count command sets size based limit for single statistic. It takes two parameters: a string called name and an integer value called max-samples.", - "description": "See ", + "name": "statistic-sample-count-set", + "brief": "The statistic-sample-count-set command sets size based limit for single statistic. It takes two parameters: a string called name and an integer value called max-samples.", + "description": "See ", "support": [ "kea-dhcp4", "kea-dhcp6" ], "avail": "1.6.0", "cmd-syntax": "{ - \"command\": \"statistic-set-max-sample-count\", + \"command\": \"statistic-sample-count-set\", \"arguments\": { \"name\": \"pkt4-received\", \"max-samples\": 100 diff --git a/doc/sphinx/arm/stats.rst b/doc/sphinx/arm/stats.rst index ac53fd15cb..88e5d2d81c 100644 --- a/doc/sphinx/arm/stats.rst +++ b/doc/sphinx/arm/stats.rst @@ -234,19 +234,19 @@ a status of 0, indicating success, and an empty parameters field. If an error is encountered, the server returns a status code of 1 (error) and the text field contains the error description. -.. _command-statistic-set-max-sample-age: +.. _command-statistic-sample-age-set: -The statistic-set-max-sample-age Command +The statistic-sample-age-set Command ---------------------------------------- -The ``statistic-set-max-sample-age`` command sets time based limit +The ``statistic-sample-age-set`` command sets time based limit for collecting samples for given statistic. An example command may look like this: :: { - "command": "statistic-set-max-sample-age", + "command": "statistic-sample-age-set", "arguments": { "name": "pkt4-received", "duration": 1245 @@ -260,19 +260,19 @@ and an empty parameters field. If an error is encountered (e.g. the requested statistic was not found), the server returns a status code of 1 (error) and the text field contains the error description. -.. _command-statistic-set-max-sample-age-all: +.. _command-statistic-sample-age-set-all: -The statistic-set-max-sample-age-all Command +The statistic-sample-age-set-all Command -------------------------------------------- -The ``statistic-set-max-sample-age-all`` command sets time based limits +The ``statistic-sample-age-set-all`` command sets time based limits for collecting samples for all statistics. An example command may look like this: :: { - "command": "statistic-set-max-sample-age-all", + "command": "statistic-sample-age-set-all", "arguments": { "duration": 1245 } @@ -284,19 +284,19 @@ for all statistics, with a result set to 0 indicating success and an empty parameters field. If an error is encountered, the server returns a status code of 1 (error) and the text field contains the error description. -.. _command-statistic-set-max-sample-count: +.. _command-statistic-sample-count-set: -The statistic-set-max-sample-count Command +The statistic-sample-count-set Command ------------------------------------------ -The ``statistic-set-max-sample-count`` command sets size based limit +The ``statistic-sample-count-set`` command sets size based limit for collecting samples for given statistic. An example command may look like this: :: { - "command": "statistic-set-max-sample-count", + "command": "statistic-sample-count-set", "arguments": { "name": "pkt4-received", "max-samples": 100 @@ -310,19 +310,19 @@ and an empty parameters field. If an error is encountered (e.g. the requested statistic was not found), the server returns a status code of 1 (error) and the text field contains the error description. -.. _command-statistic-set-max-sample-count-all: +.. _command-statistic-sample-count-set-all: -The statistic-set-max-sample-count-all Command +The statistic-sample-count-set-all Command ---------------------------------------------- -The ``statistic-set-max-sample-count-all`` command sets size based limits +The ``statistic-sample-count-set-all`` command sets size based limits for collecting samples for all statistics. An example command may look like this: :: { - "command": "statistic-set-max-sample-count-all", + "command": "statistic-sample-count-set-all", "arguments": { "max-samples": 100 } @@ -353,10 +353,10 @@ Since Kea 1.6, by default, each statistic holds 20 data points. Setting such limit prevent unlimited memory consumption growth. There are two ways to define the limts: time based (e.g. keep samples from the last 5 minutes) and size based. It's possible to change the size based -limit by using one of two commands: ``statistic-set-max-sample-count``, -to set size limit for single statistic and ``statistic-set-max-sample-count-all`` +limit by using one of two commands: ``statistic-sample-count-set``, +to set size limit for single statistic and ``statistic-sample-count-set-all`` for setting size based limits for all statistics. To set time based -limit for single statistic use ``statistic-set-max-sample-age``, -and ``statistic-set-max-sample-age-all`` to set time based limits for all statistics. -For given statistic only one type of limit can be active. It means that -storage is limited only by time based limit or size based, never by both of them. +limit for single statistic use ``statistic-sample-age-set``, and +``statistic-sample-age-set-all`` to set time based limits for all statistics. +For given statistic only one type of limit can be active. It means that storage +is limited only by time based limit or size based, never by both of them. diff --git a/src/bin/dhcp4/ctrl_dhcp4_srv.cc b/src/bin/dhcp4/ctrl_dhcp4_srv.cc index 8c2589b108..4987613534 100644 --- a/src/bin/dhcp4/ctrl_dhcp4_srv.cc +++ b/src/bin/dhcp4/ctrl_dhcp4_srv.cc @@ -864,16 +864,16 @@ 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", + CommandMgr::instance().registerCommand("statistic-sample-age-set", 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", + CommandMgr::instance().registerCommand("statistic-sample-age-set-all", boost::bind(&StatsMgr::statisticSetMaxSampleAgeAllHandler, _1, _2)); - CommandMgr::instance().registerCommand("statistic-set-max-sample-count-all", + CommandMgr::instance().registerCommand("statistic-sample-count-set", + boost::bind(&StatsMgr::statisticSetMaxSampleCountHandler, _1, _2)); + + CommandMgr::instance().registerCommand("statistic-sample-count-set-all", boost::bind(&StatsMgr::statisticSetMaxSampleCountAllHandler, _1, _2)); } @@ -914,10 +914,10 @@ 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("statistic-sample-age-set"); + CommandMgr::instance().deregisterCommand("statistic-sample-age-set-all"); + CommandMgr::instance().deregisterCommand("statistic-sample-count-set"); + CommandMgr::instance().deregisterCommand("statistic-sample-count-set-all"); CommandMgr::instance().deregisterCommand("version-get"); } catch (...) { diff --git a/src/bin/dhcp4/tests/ctrl_dhcp4_srv_unittest.cc b/src/bin/dhcp4/tests/ctrl_dhcp4_srv_unittest.cc index 9aed6c6147..14439e52a2 100644 --- a/src/bin/dhcp4/tests/ctrl_dhcp4_srv_unittest.cc +++ b/src/bin/dhcp4/tests/ctrl_dhcp4_srv_unittest.cc @@ -491,10 +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("\"statistic-sample-age-set\"") != string::npos); + EXPECT_TRUE(command_list.find("\"statistic-sample-age-set-all\"") != string::npos); + EXPECT_TRUE(command_list.find("\"statistic-sample-count-set\"") != string::npos); + EXPECT_TRUE(command_list.find("\"statistic-sample-count-set-all\"") != string::npos); EXPECT_TRUE(command_list.find("\"version-get\"") != string::npos); // Ok, and now delete the server. It should deregister its commands. @@ -714,29 +714,29 @@ TEST_F(CtrlChannelDhcpv4SrvTest, controlChannelStats) { EXPECT_EQ("{ \"result\": 0, \"text\": \"All statistics removed.\" }", response); - // Check statistic-set-max-sample-age - sendUnixCommand("{ \"command\" : \"statistic-set-max-sample-age\", " + // Check statistic-sample-age-set + sendUnixCommand("{ \"command\" : \"statistic-sample-age-set\", " " \"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\", " + // Check statistic-sample-age-set-all + sendUnixCommand("{ \"command\" : \"statistic-sample-age-set-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\", " + // Check statistic-sample-count-set + sendUnixCommand("{ \"command\" : \"statistic-sample-count-set\", " " \"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\", " + // Check statistic-sample-count-set-all + sendUnixCommand("{ \"command\" : \"statistic-sample-count-set-all\", " " \"arguments\": {" " \"max-samples\": 100 }}", response); EXPECT_EQ("{ \"result\": 0, \"text\": \"All statistics count limit are set.\" }", @@ -915,10 +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, "statistic-sample-age-set"); + checkListCommands(rsp, "statistic-sample-age-set-all"); + checkListCommands(rsp, "statistic-sample-count-set"); + checkListCommands(rsp, "statistic-sample-count-set-all"); checkListCommands(rsp, "version-get"); } diff --git a/src/bin/dhcp6/ctrl_dhcp6_srv.cc b/src/bin/dhcp6/ctrl_dhcp6_srv.cc index 3552f7eedf..9e5947606c 100644 --- a/src/bin/dhcp6/ctrl_dhcp6_srv.cc +++ b/src/bin/dhcp6/ctrl_dhcp6_srv.cc @@ -888,16 +888,16 @@ 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", + CommandMgr::instance().registerCommand("statistic-sample-age-set", 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", + CommandMgr::instance().registerCommand("statistic-sample-age-set-all", boost::bind(&StatsMgr::statisticSetMaxSampleAgeAllHandler, _1, _2)); - CommandMgr::instance().registerCommand("statistic-set-max-sample-count-all", + CommandMgr::instance().registerCommand("statistic-sample-count-set", + boost::bind(&StatsMgr::statisticSetMaxSampleCountHandler, _1, _2)); + + CommandMgr::instance().registerCommand("statistic-sample-count-set-all", boost::bind(&StatsMgr::statisticSetMaxSampleCountAllHandler, _1, _2)); } @@ -938,10 +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("statistic-sample-age-set"); + CommandMgr::instance().deregisterCommand("statistic-sample-age-set-all"); + CommandMgr::instance().deregisterCommand("statistic-sample-count-set"); + CommandMgr::instance().deregisterCommand("statistic-sample-count-set-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 77f2640bfa..ee821e37a4 100644 --- a/src/bin/dhcp6/tests/ctrl_dhcp6_srv_unittest.cc +++ b/src/bin/dhcp6/tests/ctrl_dhcp6_srv_unittest.cc @@ -798,10 +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("\"statistic-sample-age-set\"") != string::npos); + EXPECT_TRUE(command_list.find("\"statistic-sample-age-set-all\"") != string::npos); + EXPECT_TRUE(command_list.find("\"statistic-sample-count-set\"") != string::npos); + EXPECT_TRUE(command_list.find("\"statistic-sample-count-set-all\"") != string::npos); EXPECT_TRUE(command_list.find("\"version-get\"") != string::npos); // Ok, and now delete the server. It should deregister its commands. @@ -1028,29 +1028,29 @@ TEST_F(CtrlChannelDhcpv6SrvTest, controlChannelStats) { EXPECT_EQ("{ \"result\": 0, \"text\": \"All statistics removed.\" }", response); - // Check statistic-set-max-sample-age - sendUnixCommand("{ \"command\" : \"statistic-set-max-sample-age\", " + // Check statistic-sample-age-set + sendUnixCommand("{ \"command\" : \"statistic-sample-age-set\", " " \"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\", " + // Check statistic-sample-age-set-all + sendUnixCommand("{ \"command\" : \"statistic-sample-age-set-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\", " + // Check statistic-sample-count-set + sendUnixCommand("{ \"command\" : \"statistic-sample-count-set\", " " \"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\", " + // Check statistic-sample-count-set-all + sendUnixCommand("{ \"command\" : \"statistic-sample-count-set-all\", " " \"arguments\": {" " \"max-samples\": 100 }}", response); EXPECT_EQ("{ \"result\": 0, \"text\": \"All statistics count limit are set.\" }", @@ -1086,10 +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"); + checkListCommands(rsp, "statistic-sample-age-set"); + checkListCommands(rsp, "statistic-sample-age-set-all"); + checkListCommands(rsp, "statistic-sample-count-set"); + checkListCommands(rsp, "statistic-sample-count-set-all"); } // Tests if the server returns its configuration using config-get. diff --git a/src/lib/stats/stats_mgr.h b/src/lib/stats/stats_mgr.h index 11dc2d5abf..b4a9664e55 100644 --- a/src/lib/stats/stats_mgr.h +++ b/src/lib/stats/stats_mgr.h @@ -306,9 +306,9 @@ class StatsMgr : public boost::noncopyable { statisticRemoveHandler(const std::string& name, const isc::data::ConstElementPtr& params); - /// @brief Handles statistic-set-max-sample-age command + /// @brief Handles statistic-sample-age-set command /// - /// This method handles statistic-set-max-sample-age command, + /// This method handles statistic-sample-age-set command, /// which set max_sample_age_ limit of a given statistic /// and leaves max_sample_count_ disabled. /// It expects two parameters stored in params map: @@ -321,16 +321,16 @@ class StatsMgr : public boost::noncopyable { /// "duration": 1245 /// } /// - /// @param name name of the command (ignored, should be "statistic-set-max-sample-age") + /// @param name name of the command (ignored, should be "statistic-sample-age-set") /// @param params structure containing a map that contains "name" and "duration" /// @return answer containing information about successfully setup limit of statistic static isc::data::ConstElementPtr statisticSetMaxSampleAgeHandler(const std::string& name, const isc::data::ConstElementPtr& params); - /// @brief Handles statistic-set-max-sample-count command + /// @brief Handles statistic-sample-count-set command /// - /// This method handles statistic-set-max-sample-count command, + /// This method handles statistic-sample-count-set command, /// which set max_sample_count_ limit of a given statistic /// and leaves max_sample_age_ disabled. /// It expects two parameters stored in params map: @@ -343,7 +343,7 @@ class StatsMgr : public boost::noncopyable { /// "max-samples": 15 /// } /// - /// @param name name of the command (ignored, should be "statistic-set-max-sample-count") + /// @param name name of the command (ignored, should be "statistic-sample-count-set") /// @param params structure containing a map that contains "name" and "max-samples" /// @return answer containing information about successfully setup limit of statistic static isc::data::ConstElementPtr @@ -386,9 +386,9 @@ class StatsMgr : public boost::noncopyable { statisticRemoveAllHandler(const std::string& name, const isc::data::ConstElementPtr& params); - /// @brief Handles statistic-set-max-sample-age-all command + /// @brief Handles statistic-sample-age-set-all command /// - /// This method handles statistic-set-max-sample-age-all command, + /// This method handles statistic-sample-age-set-all command, /// which set max_sample_age_ limit to all statistics. /// It expects one parameter stored in params map: /// duration: limit expressed as a number of seconds @@ -398,16 +398,16 @@ class StatsMgr : public boost::noncopyable { /// "duration": 1245 /// } /// - /// @param name name of the command (ignored, should be "statistic-set-max-sample-age-all") + /// @param name name of the command (ignored, should be "statistic-sample-age-set-all") /// @param params structure containing a map that contains "duration" /// @return answer confirming success of this operation static isc::data::ConstElementPtr statisticSetMaxSampleAgeAllHandler(const std::string& name, const isc::data::ConstElementPtr& params); - /// @brief Handles statistic-set-max-sample-count-all command + /// @brief Handles statistic-sample-count-set-all command /// - /// This method handles statistic-set-max-sample-count-all command, + /// This method handles statistic-sample-count-set-all command, /// which set max_sample_count_ limit of a given statistic /// and leaves max_sample_age_ disabled. /// It expects one parameter stored in params map: @@ -418,7 +418,7 @@ class StatsMgr : public boost::noncopyable { /// "max-samples": 15 /// } /// - /// @param name name of the command (ignored, should be "statistic-set-max-sample-count-all") + /// @param name name of the command (ignored, should be "statistic-sample-count-set-all") /// @param params structure containing a map that contains "max-samples" /// @return answer confirming success of this operation static isc::data::ConstElementPtr diff --git a/src/lib/stats/tests/stats_mgr_unittest.cc b/src/lib/stats/tests/stats_mgr_unittest.cc index b662e5fb4f..bf2114f543 100644 --- a/src/lib/stats/tests/stats_mgr_unittest.cc +++ b/src/lib/stats/tests/stats_mgr_unittest.cc @@ -772,7 +772,7 @@ TEST_F(StatsMgrTest, commandRemoveAll) { EXPECT_EQ(0, StatsMgr::instance().count()); } -// This test checks whether statistic-set-max-sample-age command really set +// This test checks whether statistic-sample-age-set command really set // max_sample_age_ limit correctly. TEST_F(StatsMgrTest, commandSetMaxSampleAge) { StatsMgr::instance().setValue("alpha", static_cast(1234)); @@ -782,7 +782,7 @@ TEST_F(StatsMgrTest, commandSetMaxSampleAge) { params->set("duration", Element::create(1245)); // time_duration(0, 20, 45, 0) ConstElementPtr rsp = - StatsMgr::instance().statisticSetMaxSampleAgeHandler("statistic-set-max-sample-age", params); + StatsMgr::instance().statisticSetMaxSampleAgeHandler("statistic-sample-age-set", params); int status_code; ASSERT_NO_THROW(parseAnswer(status_code, rsp)); EXPECT_EQ(CONTROL_RESULT_SUCCESS, status_code); @@ -794,7 +794,7 @@ TEST_F(StatsMgrTest, commandSetMaxSampleAge) { EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleCount().first, false); } -// Test checks if statistic-set-max-sample-age is able to handle: +// Test checks if statistic-sample-age-set is able to handle: // - a request without parameters // - a request without duration parameter // - a request with missing statistic name @@ -802,7 +802,7 @@ TEST_F(StatsMgrTest, commandSetMaxSampleAge) { TEST_F(StatsMgrTest, commandSetMaxSampleAgeNegative) { // Case 1: a request without parameters ConstElementPtr rsp = - StatsMgr::instance().statisticSetMaxSampleAgeHandler("statistic-set-max-sample-age", ElementPtr()); + StatsMgr::instance().statisticSetMaxSampleAgeHandler("statistic-sample-age-set", ElementPtr()); int status_code; ASSERT_NO_THROW(parseAnswer(status_code, rsp)); EXPECT_EQ(status_code, CONTROL_RESULT_ERROR); @@ -810,20 +810,20 @@ TEST_F(StatsMgrTest, commandSetMaxSampleAgeNegative) { // Case 2: a request without duration parameter ElementPtr params = Element::createMap(); params->set("name", Element::create("alpha")); - rsp = StatsMgr::instance().statisticSetMaxSampleAgeHandler("statistic-set-max-sample-age", params); + rsp = StatsMgr::instance().statisticSetMaxSampleAgeHandler("statistic-sample-age-set", params); ASSERT_NO_THROW(parseAnswer(status_code, rsp)); EXPECT_EQ(status_code, CONTROL_RESULT_ERROR); // Case 3: a request with missing statistic name params = Element::createMap(); params->set("duration", Element::create(100)); - rsp = StatsMgr::instance().statisticSetMaxSampleAgeHandler("statistic-set-max-sample-age", params); + rsp = StatsMgr::instance().statisticSetMaxSampleAgeHandler("statistic-sample-age-set", params); ASSERT_NO_THROW(parseAnswer(status_code, rsp)); EXPECT_EQ(status_code, CONTROL_RESULT_ERROR); // Case 4: a request for non-existing statistic params->set("name", Element::create("alpha")); - rsp = StatsMgr::instance().statisticSetMaxSampleAgeHandler("statistic-set-max-sample-age", params); + rsp = StatsMgr::instance().statisticSetMaxSampleAgeHandler("statistic-sample-age-set", params); EXPECT_EQ("{ \"result\": 1, \"text\": \"No 'alpha' statistic found\" }", rsp->str()); } @@ -839,7 +839,7 @@ TEST_F(StatsMgrTest, commandSetMaxSampleAgeAll) { params->set("duration", Element::create(3765)); // time_duration(1, 2, 45, 0) ConstElementPtr rsp = - StatsMgr::instance().statisticSetMaxSampleAgeAllHandler("statistic-set-max-sample-age-all", params); + StatsMgr::instance().statisticSetMaxSampleAgeAllHandler("statistic-sample-age-set-all", params); int status_code; ASSERT_NO_THROW(parseAnswer(status_code, rsp)); EXPECT_EQ(CONTROL_RESULT_SUCCESS, status_code); @@ -866,7 +866,7 @@ TEST_F(StatsMgrTest, commandSetMaxSampleAgeAll) { EXPECT_EQ(StatsMgr::instance().getObservation("delta")->getMaxSampleCount().first, false); } -// This test checks whether statistic-set-max-sample-count command really set +// This test checks whether statistic-sample-count-set command really set // max_sample_count_ limit correctly. TEST_F(StatsMgrTest, commandSetMaxSampleCount) { StatsMgr::instance().setValue("alpha", static_cast(1234)); @@ -876,7 +876,7 @@ TEST_F(StatsMgrTest, commandSetMaxSampleCount) { params->set("max-samples", Element::create(15)); ConstElementPtr rsp = - StatsMgr::instance().statisticSetMaxSampleCountHandler("statistic-set-max-sample-count", params); + StatsMgr::instance().statisticSetMaxSampleCountHandler("statistic-sample-count-set", params); int status_code; ASSERT_NO_THROW(parseAnswer(status_code, rsp)); EXPECT_EQ(CONTROL_RESULT_SUCCESS, status_code); @@ -887,7 +887,7 @@ TEST_F(StatsMgrTest, commandSetMaxSampleCount) { EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleAge().first, false); } -// Test checks if statistic-set-max-sample-count is able to handle: +// Test checks if statistic-sample-count-set is able to handle: // - a request without parameters // - a request without max-samples parameter // - a request with missing statistic name @@ -895,7 +895,7 @@ TEST_F(StatsMgrTest, commandSetMaxSampleCount) { TEST_F(StatsMgrTest, commandSetMaxSampleCountNegative) { // Case 1: a request without parameters ConstElementPtr rsp = - StatsMgr::instance().statisticSetMaxSampleCountHandler("statistic-set-max-sample-count", ElementPtr()); + StatsMgr::instance().statisticSetMaxSampleCountHandler("statistic-sample-count-set", ElementPtr()); int status_code; ASSERT_NO_THROW(parseAnswer(status_code, rsp)); EXPECT_EQ(status_code, CONTROL_RESULT_ERROR); @@ -903,20 +903,20 @@ TEST_F(StatsMgrTest, commandSetMaxSampleCountNegative) { // Case 2: a request without max-samples parameter ElementPtr params = Element::createMap(); params->set("name", Element::create("alpha")); - rsp = StatsMgr::instance().statisticSetMaxSampleCountHandler("statistic-set-max-sample-count", params); + rsp = StatsMgr::instance().statisticSetMaxSampleCountHandler("statistic-sample-count-set", params); ASSERT_NO_THROW(parseAnswer(status_code, rsp)); EXPECT_EQ(status_code, CONTROL_RESULT_ERROR); // Case 3: a request with missing statistic name params = Element::createMap(); params->set("max-samples", Element::create(10)); - rsp = StatsMgr::instance().statisticSetMaxSampleCountHandler("statistic-set-max-sample-count", params); + rsp = StatsMgr::instance().statisticSetMaxSampleCountHandler("statistic-sample-count-set", params); ASSERT_NO_THROW(parseAnswer(status_code, rsp)); EXPECT_EQ(status_code, CONTROL_RESULT_ERROR); // Case 4: a request for non-existing statistic params->set("name", Element::create("alpha")); - rsp = StatsMgr::instance().statisticSetMaxSampleCountHandler("statistic-set-max-sample-count", params); + rsp = StatsMgr::instance().statisticSetMaxSampleCountHandler("statistic-sample-count-set", params); EXPECT_EQ("{ \"result\": 1, \"text\": \"No 'alpha' statistic found\" }", rsp->str()); } @@ -932,7 +932,7 @@ TEST_F(StatsMgrTest, commandSetMaxSampleCountAll) { params->set("max-samples", Element::create(200)); ConstElementPtr rsp = - StatsMgr::instance().statisticSetMaxSampleCountAllHandler("statistic-set-max-sample-count-all", params); + StatsMgr::instance().statisticSetMaxSampleCountAllHandler("statistic-sample-count-set-all", params); int status_code; ASSERT_NO_THROW(parseAnswer(status_code, rsp)); EXPECT_EQ(CONTROL_RESULT_SUCCESS, status_code); -- GitLab From dde1b96b33ed20dbe2c815f1168e62b66635e39f Mon Sep 17 00:00:00 2001 From: Razvan Becheriu Date: Mon, 5 Aug 2019 18:29:32 +0300 Subject: [PATCH 11/12] fixed header --- src/lib/stats/stats_mgr.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/lib/stats/stats_mgr.h b/src/lib/stats/stats_mgr.h index b4a9664e55..450d65a63b 100644 --- a/src/lib/stats/stats_mgr.h +++ b/src/lib/stats/stats_mgr.h @@ -408,8 +408,7 @@ class StatsMgr : public boost::noncopyable { /// @brief Handles statistic-sample-count-set-all command /// /// This method handles statistic-sample-count-set-all command, - /// which set max_sample_count_ limit of a given statistic - /// and leaves max_sample_age_ disabled. + /// which set max_sample_count_ limit of all statistics. /// It expects one parameter stored in params map: /// max-samples: count limit /// -- GitLab From 1bd589f1a38f1d9e8c5748f3c8f82a8299131fc9 Mon Sep 17 00:00:00 2001 From: Razvan Becheriu Date: Mon, 5 Aug 2019 20:38:42 +0300 Subject: [PATCH 12/12] [#731.459] updated ChangeLog --- ChangeLog | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ChangeLog b/ChangeLog index 388e0ccc9b..06d729e24c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +1634. [func] franek, razvan + Kea statistics improvements: Added commands for set sample age and + set sample count. + (Gitlab #731,!459, git dde1b96b33ed20dbe2c815f1168e62b66635e39f) + 1633. [bug] fdupont Added missing YANG Kea test module in distributions. (Gitlab #747,!436, git a800e79c7917acc723cbc71b626adc360e15a8d7) -- GitLab