]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
stats: Process 'duration' like any other metric value
authorJosef 'Jeff' Sipek <jeff.sipek@open-xchange.com>
Thu, 20 Feb 2020 19:19:29 +0000 (14:19 -0500)
committerjeff.sipek <jeff.sipek@open-xchange.com>
Fri, 13 Mar 2020 08:25:17 +0000 (08:25 +0000)
This will allow the soon-to-be-added group-by quantization functions to work
on the duration value.

src/stats/stats-metrics.c

index fe0fd4fa728f32f8cf95fba0e444adc028b1795d..beb3f3dae2a5c3b0f9fdc5801fb829d7d3112dcb 100644 (file)
@@ -452,11 +452,9 @@ stats_metric_event_field(struct event *event, const char *fieldname,
 static void
 stats_metric_event(struct metric *metric, struct event *event, pool_t pool)
 {
-       intmax_t duration;
-
-       event_get_last_duration(event, &duration);
-       stats_dist_add(metric->duration_stats, duration);
-
+       /* duration is special - we always add it */
+       stats_metric_event_field(event, "duration",
+                                metric->duration_stats);
 
        for (unsigned int i = 0; i < metric->fields_count; i++)
                stats_metric_event_field(event,
@@ -495,6 +493,13 @@ void stats_metrics_event(struct stats_metrics *metrics, struct event *event,
 {
        struct event_filter_match_iter *iter;
        struct metric *metric;
+       intmax_t duration;
+
+       /* Note: Adding the field here means that it will get exported
+          below.  This is necessary to allow group-by functions to quantize
+          based on the event duration. */
+       event_get_last_duration(event, &duration);
+       event_add_int(event, "duration", duration);
 
        /* process stats */
        iter = event_filter_match_iter_init(metrics->stats_filter, event, ctx);