Fix duration JSON representation

Duration values converted to JSON are now again returned as integers. This
keeps the REST API backwards compatible until suffixed durations are no
longer supported at which point all duration values can be represented in
milliseconds.
This commit is contained in:
Markus Mäkelä 2019-05-02 08:40:09 +03:00
parent 864c38aa96
commit bc654849e8
No known key found for this signature in database
GPG Key ID: 72D48FCE664F7B19

View File

@ -70,6 +70,8 @@
using std::set;
using std::string;
using maxscale::Monitor;
using std::chrono::milliseconds;
using std::chrono::seconds;
const char CN_ACCOUNT[] = "account";
const char CN_ADDRESS[] = "address";
@ -3766,6 +3768,14 @@ void config_add_defaults(CONFIG_CONTEXT* ctx, const MXS_MODULE_PARAM* params)
}
}
template<class T>
inline int64_t duration_to_int(const string& value)
{
T duration;
get_suffixed_duration(value.c_str(), &duration);
return duration.count();
}
/**
* Convert a config value to a json object.
*
@ -3785,6 +3795,13 @@ json_t* param_value_to_json(const MXS_MODULE_PARAM* param_info, const string& na
rval = json_integer(strtol(value.c_str(), NULL, 10));
break;
case MXS_MODULE_PARAM_DURATION:
rval = json_integer((param_info->options & MXS_MODULE_OPT_DURATION_S) ?
duration_to_int<seconds>(value) :
duration_to_int<milliseconds>(value));
break;
case MXS_MODULE_PARAM_BOOL:
rval = json_boolean(config_truth_value(value.c_str()));
break;