]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
stats: Move metrics_group_by_exponential/linear_init()
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Mon, 2 Sep 2024 10:28:10 +0000 (13:28 +0300)
committerAki Tuomi <aki.tuomi@open-xchange.com>
Fri, 17 Jan 2025 08:39:59 +0000 (10:39 +0200)
Simplifies the following commits.

src/stats/stats-settings.c

index 3350495bbd68eaa76c47c6eb6b62120730abc5da..fb67b4858f99fcc7a82e3540a2272621bb7bf666 100644 (file)
@@ -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)
 {