MXS-2329 Make duration misuse harder

Now the desired type must be specified when getting a duration.
The type also dictates how durations without suffixes should be
interpreted.

That removes the need for remembering that to convert a returned
millisecond duration to a second duration.
This commit is contained in:
Johan Wikman
2019-04-29 10:00:44 +03:00
parent 8bf0e00b1c
commit 8a250a8b13
4 changed files with 43 additions and 10 deletions

View File

@ -90,9 +90,7 @@ public:
if (new_instance)
{
new_instance->m_count = params->get_integer("count");
new_instance->m_time = params->get_duration("time", mxs::config::INTERPRET_AS_SECONDS).count();
// The window is in seconds.
new_instance->m_time = std::lround(new_instance->m_time / 1000.0);
new_instance->m_time = params->get_duration<std::chrono::seconds>("time").count();
new_instance->m_match = params->get_string(PARAM_MATCH);
new_instance->m_nomatch = params->get_string(PARAM_IGNORE);

View File

@ -65,11 +65,11 @@ ThrottleFilter* ThrottleFilter::create(const char* zName, MXS_CONFIG_PARAMETER*
{
int max_qps = pParams->get_integer(MAX_QPS_CFG);
int sample_msecs =
pParams->get_duration(SAMPLING_DURATION_CFG, mxs::config::INTERPRET_AS_MILLISECONDS).count();
pParams->get_duration<std::chrono::milliseconds>(SAMPLING_DURATION_CFG).count();
int throttle_msecs =
pParams->get_duration(THROTTLE_DURATION_CFG, mxs::config::INTERPRET_AS_MILLISECONDS).count();
pParams->get_duration<std::chrono::milliseconds>(THROTTLE_DURATION_CFG).count();
int cont_msecs =
pParams->get_duration(CONTINUOUS_DURATION_CFG, mxs::config::INTERPRET_AS_MILLISECONDS).count();
pParams->get_duration<std::chrono::milliseconds>(CONTINUOUS_DURATION_CFG).count();
bool config_ok = true;
if (max_qps < 2)