]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
stats: Allow total length of all sub-metrics to be 256 bytes
authorAki Tuomi <aki.tuomi@open-xchange.com>
Thu, 6 Jul 2023 06:54:16 +0000 (09:54 +0300)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Tue, 11 Jul 2023 10:46:43 +0000 (10:46 +0000)
Previously, we only allowed 32 bytes per sub-metric name, so this
new code changes this to allow total length of all components
to be up to 256 bytes.

This change allow e.g. using full DNS names in sub-metric labels.

src/stats/stats-metrics.c
src/stats/stats-metrics.h

index 7eadcaed02cc91fc69f8b0658ba339a2f4bf85a8..301a0e5fc4a8b429ecf9df5209fc821dc5acb462 100644 (file)
@@ -15,6 +15,7 @@
 #include <ctype.h>
 
 #define LOG_EXPORTER_LONG_FIELD_TRUNCATE_LEN 1000
+#define STATS_SUB_METRIC_MAX_LENGTH 256
 
 struct stats_metrics {
        pool_t pool;
@@ -395,7 +396,10 @@ stats_metric_sub_metric_alloc(struct metric *metric, const char *name, pool_t po
        array_append_zero(&fields);
        sub_metric = stats_metric_alloc(pool, metric->name, metric->set,
                                        array_idx(&fields, 0));
-       sub_metric->sub_name = p_strdup(pool, str_sanitize_utf8(name, 32));
+       size_t max_len = STATS_SUB_METRIC_MAX_LENGTH - metric->sub_name_used_size;
+       sub_metric->sub_name = p_strdup(pool, str_sanitize_utf8(name, max_len));
+       sub_metric->sub_name_used_size =
+               metric->sub_name_used_size + strlen(sub_metric->sub_name);
        array_append(&metric->sub_metrics, &sub_metric, 1);
        return sub_metric;
 }
@@ -603,6 +607,8 @@ stats_metric_group_by_field(struct metric *metric, struct event *event,
        if (!stats_metric_group_by_get_value(field, &metric->group_by[0], &value))
                return;
 
+       if (metric->sub_name_used_size >= STATS_SUB_METRIC_MAX_LENGTH)
+               return;
        if (!array_is_created(&metric->sub_metrics))
                p_array_init(&metric->sub_metrics, pool, 8);
        sub_metric = stats_metric_get_sub_metric(metric, field, &value, pool);
index 65b8b74889820f289a684df0c34598991637b9f0..5cd0d7e230358ff5799fc46e66b95a6fba5180e5 100644 (file)
@@ -91,6 +91,7 @@ struct metric {
           This is a display name and does not guarantee uniqueness.
        */
        const char *sub_name;
+       size_t sub_name_used_size;
 
        /* Timing for how long the event existed */
        struct stats_dist *duration_stats;