From: sergey.kitov Date: Thu, 30 Sep 2021 15:42:08 +0000 (+0300) Subject: stats: Remove metric from stats dump, when removing dynamically. X-Git-Tag: 2.3.17~15 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=8da67de232f3edb3389206452f7f994d5b8bb998;p=thirdparty%2Fdovecot%2Fcore.git stats: Remove metric from stats dump, when removing dynamically. --- diff --git a/src/stats/stats-metrics.c b/src/stats/stats-metrics.c index e339d3705a..ff8c799d6a 100644 --- a/src/stats/stats-metrics.c +++ b/src/stats/stats-metrics.c @@ -174,12 +174,15 @@ stats_metric_settings_dup(pool_t pool, const struct stats_metric_settings *src) } static struct metric * -stats_metrics_find(struct stats_metrics *metrics, const char *name) +stats_metrics_find(struct stats_metrics *metrics, + const char *name, unsigned int *idx_r) { - struct metric *m; - array_foreach_elem(&metrics->metrics, m) { - if (strcmp(m->name, name) == 0) - return m; + struct metric *const *m; + array_foreach(&metrics->metrics, m) { + if (strcmp((*m)->name, name) == 0) { + *idx_r = array_foreach_idx(&metrics->metrics, m); + return *m; + } } return NULL; } @@ -188,7 +191,8 @@ bool stats_metrics_add_dynamic(struct stats_metrics *metrics, struct stats_metric_settings *set, const char **error_r) { - if (stats_metrics_find(metrics, set->metric_name) != NULL) { + unsigned int existing_idx ATTR_UNUSED; + if (stats_metrics_find(metrics, set->metric_name, &existing_idx) != NULL) { *error_r = "Metric already exists"; return FALSE; } @@ -204,9 +208,12 @@ bool stats_metrics_add_dynamic(struct stats_metrics *metrics, bool stats_metrics_remove_dynamic(struct stats_metrics *metrics, const char *name) { - struct metric *m = stats_metrics_find(metrics, name); - if (m != NULL) + unsigned int m_idx; + struct metric *m = stats_metrics_find(metrics, name, &m_idx); + if (m != NULL) { + array_delete(&metrics->metrics, m_idx, 1); return event_filter_remove_queries_with_context(metrics->filter, m); + } return FALSE; }