]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-master: Use event_minimize() to simplify the event before sending to stats
authorJosef 'Jeff' Sipek <jeff.sipek@open-xchange.com>
Mon, 1 Apr 2019 12:52:04 +0000 (15:52 +0300)
committerAki Tuomi <aki.tuomi@open-xchange.com>
Mon, 20 May 2019 06:46:32 +0000 (06:46 +0000)
src/lib-master/stats-client.c

index 06328e2a94d2a795b52fa133a287bd87b5dbd04b..dfa00b4e24c70da24a094b9f841ab5b1912ff41c 100644 (file)
@@ -158,60 +158,15 @@ static const struct connection_vfuncs stats_client_vfuncs = {
        .input_args = stats_client_input_args,
 };
 
-static struct event *stats_event_get_merged(struct event *event)
-{
-       struct event *res = event;
-       struct event *p;
-       unsigned int cat_count, field_count;
-       bool use_original = TRUE;
-
-       for (p = event->parent;
-            p != NULL && !p->id_sent_to_stats &&
-                    timeval_cmp(&p->tv_created_ioloop, &res->tv_created_ioloop) == 0;
-            p = p->parent) {
-               // Merge all parents with the same timestamp into result.
-               if (!event_has_all_categories(res, p) ||
-                   !event_has_all_fields(res, p)) {
-                       if (use_original) {
-                               res = event_dup(event);
-                               use_original = FALSE;
-                       }
-                       event_copy_categories(res, p);
-                       event_copy_fields(res, p);
-               }
-       }
-
-       for (; p != NULL && !p->id_sent_to_stats; p = p->parent) {
-               // Now skip parents with empty fields and categories.
-               (void)event_get_fields(p, &field_count);
-               (void)event_get_categories(p, &cat_count);
-               if (field_count > 0 || cat_count > 0)
-                       break;
-       }
-
-       if (res->parent != p) {
-               /* p is NULL or
-                  p sent to stats or
-                  p is the first parent that has different timestamp from event
-                  and have fields and/or categories
-                  use p as parent,
-                  because we do not want parent without fields and categoris */
-               if (use_original)
-                       res = event_dup(event);
-               event_unref(&res->parent);
-               res->parent = p;
-               if (res->parent != NULL)
-                       event_ref(res->parent);
-       }
-       return res;
-}
-
 static void
 stats_event_write(struct event *event, const struct failure_context *ctx,
                  string_t *str, bool begin)
 {
-       struct event *merged_event = begin? event: stats_event_get_merged(event);
-       struct event *parent_event = merged_event->parent;
+       struct event *merged_event;
+       struct event *parent_event;
+
+       merged_event = begin ? event_ref(event) : event_minimize(event);
+       parent_event = merged_event->parent;
 
        if (parent_event != NULL) {
                if (!parent_event->id_sent_to_stats)
@@ -229,8 +184,7 @@ stats_event_write(struct event *event, const struct failure_context *ctx,
                    ctx->type);
        event_export(merged_event, str);
        str_append_c(str, '\n');
-       if (merged_event != event)
-               event_unref(&merged_event);
+       event_unref(&merged_event);
 }
 
 static void