From: Timo Sirainen Date: Mon, 2 Sep 2024 10:28:10 +0000 (+0300) Subject: stats: Move metrics_group_by_exponential/linear_init() X-Git-Tag: 2.4.0~440 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=061140422bf2be65ccfae773b370c2594663e1b9;p=thirdparty%2Fdovecot%2Fcore.git stats: Move metrics_group_by_exponential/linear_init() Simplifies the following commits. --- diff --git a/src/stats/stats-settings.c b/src/stats/stats-settings.c index 3350495bbd..fb67b4858f 100644 --- a/src/stats/stats-settings.c +++ b/src/stats/stats-settings.c @@ -222,44 +222,6 @@ static bool stats_exporter_settings_check(void *_set, pool_t pool ATTR_UNUSED, return TRUE; } -static bool parse_metric_group_by_common(const char *func, - const char *const *params, - intmax_t *min_r, - intmax_t *max_r, - intmax_t *other_r, - const char **error_r) -{ - intmax_t min, max, other; - - if ((str_array_length(params) != 3) || - (str_to_intmax(params[0], &min) < 0) || - (str_to_intmax(params[1], &max) < 0) || - (str_to_intmax(params[2], &other) < 0)) { - *error_r = t_strdup_printf("group_by '%s' aggregate function takes " - "3 int args", func); - return FALSE; - } - - if ((min < 0) || (max < 0) || (other < 0)) { - *error_r = t_strdup_printf("group_by '%s' aggregate function " - "arguments must be >= 0", func); - return FALSE; - } - - if (min >= max) { - *error_r = t_strdup_printf("group_by '%s' aggregate function " - "min must be < max (%ju must be < %ju)", - func, min, max); - return FALSE; - } - - *min_r = min; - *max_r = max; - *other_r = other; - - return TRUE; -} - static void metrics_group_by_exponential_init(struct stats_metric_settings_group_by *group_by, pool_t pool, unsigned int base, @@ -293,25 +255,6 @@ metrics_group_by_exponential_init(struct stats_metric_settings_group_by *group_b } } -static bool parse_metric_group_by_exp(pool_t pool, struct stats_metric_settings_group_by *group_by, - const char *const *params, const char **error_r) -{ - intmax_t min, max, base; - - if (!parse_metric_group_by_common("exponential", params, &min, &max, &base, error_r)) - return FALSE; - - if ((base != 2) && (base != 10)) { - *error_r = t_strdup_printf("group_by 'exponential' aggregate function " - "base must be one of: 2, 10 (base=%ju)", - base); - return FALSE; - } - - metrics_group_by_exponential_init(group_by, pool, base, min, max); - return TRUE; -} - static void metrics_group_by_linear_init(struct stats_metric_settings_group_by *group_by, pool_t pool, uint64_t min, uint64_t max, @@ -345,6 +288,63 @@ metrics_group_by_linear_init(struct stats_metric_settings_group_by *group_by, } } +static bool parse_metric_group_by_common(const char *func, + const char *const *params, + intmax_t *min_r, + intmax_t *max_r, + intmax_t *other_r, + const char **error_r) +{ + intmax_t min, max, other; + + if ((str_array_length(params) != 3) || + (str_to_intmax(params[0], &min) < 0) || + (str_to_intmax(params[1], &max) < 0) || + (str_to_intmax(params[2], &other) < 0)) { + *error_r = t_strdup_printf("group_by '%s' aggregate function takes " + "3 int args", func); + return FALSE; + } + + if ((min < 0) || (max < 0) || (other < 0)) { + *error_r = t_strdup_printf("group_by '%s' aggregate function " + "arguments must be >= 0", func); + return FALSE; + } + + if (min >= max) { + *error_r = t_strdup_printf("group_by '%s' aggregate function " + "min must be < max (%ju must be < %ju)", + func, min, max); + return FALSE; + } + + *min_r = min; + *max_r = max; + *other_r = other; + + return TRUE; +} + +static bool parse_metric_group_by_exp(pool_t pool, struct stats_metric_settings_group_by *group_by, + const char *const *params, const char **error_r) +{ + intmax_t min, max, base; + + if (!parse_metric_group_by_common("exponential", params, &min, &max, &base, error_r)) + return FALSE; + + if ((base != 2) && (base != 10)) { + *error_r = t_strdup_printf("group_by 'exponential' aggregate function " + "base must be one of: 2, 10 (base=%ju)", + base); + return FALSE; + } + + metrics_group_by_exponential_init(group_by, pool, base, min, max); + return TRUE; +} + static bool parse_metric_group_by_lin(pool_t pool, struct stats_metric_settings_group_by *group_by, const char *const *params, const char **error_r) {