]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
stats: event exporter - Use category exporting helper to avoid duplicates (json)
authorJosef 'Jeff' Sipek <jeff.sipek@open-xchange.com>
Fri, 21 Aug 2020 18:23:50 +0000 (14:23 -0400)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Fri, 11 Sep 2020 13:35:56 +0000 (13:35 +0000)
src/stats/event-exporter-fmt-json.c

index 3ccf09f3e9c8ba4402ef6a07689e9b8e10a35e17..ce98911a81bd6aab482bfd9b53cb4b7d0ddb4d91 100644 (file)
@@ -96,23 +96,11 @@ static void json_export_timestamps(string_t *dest, struct event *event,
        str_append_c(dest, ',');
 }
 
-static void append_category(string_t *dest, struct event_category *cat)
-{
-       /* append parent's categories */
-       if (cat->parent != NULL)
-               append_category(dest, cat->parent);
-
-       /* append this */
-       append_str(dest, cat->name);
-       str_append_c(dest, ',');
-}
-
 static void json_export_categories(string_t *dest, struct event *event,
                                   const struct metric_export_info *info)
 {
        struct event_category *const *cats;
        unsigned int count;
-       unsigned int i;
 
        if ((info->include & EVENT_EXPORTER_INCL_CATEGORIES) == 0)
                return;
@@ -121,12 +109,8 @@ static void json_export_categories(string_t *dest, struct event *event,
        str_append(dest, ":[");
 
        cats = event_get_categories(event, &count);
-       for (i = 0; i < count; i++)
-               append_category(dest, cats[i]);
-
-       /* remove trailing comma */
-       if (count != 0)
-               str_truncate(dest, str_len(dest) - 1);
+       event_export_helper_fmt_categories(dest, cats, count,
+                                          append_str, ",");
 
        str_append(dest, "],");
 }