From: Josef 'Jeff' Sipek Date: Wed, 4 Mar 2020 11:34:06 +0000 (-0500) Subject: stats: Add support for explicit discrete group-by function X-Git-Tag: 2.3.11.2~541 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6d6a2f4c328902b49f0cf803f3a5dd28cd1a725b;p=thirdparty%2Fdovecot%2Fcore.git stats: Add support for explicit discrete group-by function One can specify the function as: :discrete This has the same exact behavior as the bare field name syntax before this change. For example, the following two lines have identical semantics: group_by = cmd_name:discrete group_by = cmd_name --- diff --git a/src/stats/stats-settings.c b/src/stats/stats-settings.c index f6b05887bf..db2ad5df26 100644 --- a/src/stats/stats-settings.c +++ b/src/stats/stats-settings.c @@ -301,7 +301,16 @@ static bool parse_metric_group_by(struct stats_metric_settings *set, params = t_strsplit(*tmp, ":"); if (params[1] == NULL) { + /* - alias for :discrete */ group_by.func = STATS_METRIC_GROUPBY_DISCRETE; + } else if (strcmp(params[1], "discrete") == 0) { + /* :discrete */ + group_by.func = STATS_METRIC_GROUPBY_DISCRETE; + if (params[2] != NULL) { + *error_r = "group_by 'discrete' aggregate function " + "does not take any args"; + return FALSE; + } } else { *error_r = t_strdup_printf("unknown aggregation function " "'%s' on field '%s'", params[1], params[0]); diff --git a/src/stats/test-stats-metrics.c b/src/stats/test-stats-metrics.c index e80ef64ebe..81b19a5eed 100644 --- a/src/stats/test-stats-metrics.c +++ b/src/stats/test-stats-metrics.c @@ -143,6 +143,18 @@ static const struct discrete_test discrete_tests[] = { { "eta", "kappa", "nu", }, { "upsilon", "pi", "epsilon", }, }, + { + "test_name:discrete sub_name:discrete", + 3, + { "apple", "bannana", "orange", }, + { "pie", "yoghurt", "cobbler", }, + }, + { + "test_name sub_name:discrete", + 3, + { "apollo", "gaia", "hermes", }, + { "thor", "odin", "loki", }, + }, }; static void test_stats_metrics_group_by_discrete_real(const struct discrete_test *test)