From bc654849e8604caaf8a459f6cd961c2932abf156 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Thu, 2 May 2019 08:40:09 +0300 Subject: [PATCH] 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. --- server/core/config.cc | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/server/core/config.cc b/server/core/config.cc index af29eacf3..fc1670c98 100644 --- a/server/core/config.cc +++ b/server/core/config.cc @@ -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 +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(value) : + duration_to_int(value)); + break; + + case MXS_MODULE_PARAM_BOOL: rval = json_boolean(config_truth_value(value.c_str())); break;