From: Aki Tuomi Date: Thu, 6 Jul 2023 06:54:16 +0000 (+0300) Subject: stats: Allow total length of all sub-metrics to be 256 bytes X-Git-Tag: 2.4.0~2641 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a9fb9e5e8517a053ed96128b68960883fc783afe;p=thirdparty%2Fdovecot%2Fcore.git stats: Allow total length of all sub-metrics to be 256 bytes 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. --- diff --git a/src/stats/stats-metrics.c b/src/stats/stats-metrics.c index 7eadcaed02..301a0e5fc4 100644 --- a/src/stats/stats-metrics.c +++ b/src/stats/stats-metrics.c @@ -15,6 +15,7 @@ #include #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); diff --git a/src/stats/stats-metrics.h b/src/stats/stats-metrics.h index 65b8b74889..5cd0d7e230 100644 --- a/src/stats/stats-metrics.h +++ b/src/stats/stats-metrics.h @@ -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;