From c53c496b6db4e11fd8aed8df9556dad481220196 Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Mon, 24 Oct 2016 09:03:32 +0200 Subject: [PATCH] write_prometheus plugin: Don't allocate metric families in prom_missing(). --- src/write_prometheus.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/write_prometheus.c b/src/write_prometheus.c index 6fb5a866..43a60fc9 100644 --- a/src/write_prometheus.c +++ b/src/write_prometheus.c @@ -637,8 +637,8 @@ static char *metric_family_name(data_set_t const *ds, value_list_t const *vl, /* metric_family_get looks up the matching metric family, allocating it if * necessary. */ static Io__Prometheus__Client__MetricFamily * -metric_family_get(data_set_t const *ds, value_list_t const *vl, - size_t ds_index) { +metric_family_get(data_set_t const *ds, value_list_t const *vl, size_t ds_index, + _Bool allocate) { char *name = metric_family_name(ds, vl, ds_index); if (name == NULL) { ERROR("write_prometheus plugin: Allocating metric family name failed."); @@ -652,6 +652,9 @@ metric_family_get(data_set_t const *ds, value_list_t const *vl, return fam; } + if (!allocate) + return NULL; + fam = metric_family_create(name, ds, vl, ds_index); if (fam == NULL) { ERROR("write_prometheus plugin: Allocating metric family failed."); @@ -733,7 +736,8 @@ static int prom_write(data_set_t const *ds, value_list_t const *vl, pthread_mutex_lock(&metrics_lock); for (size_t i = 0; i < ds->ds_num; i++) { - Io__Prometheus__Client__MetricFamily *fam = metric_family_get(ds, vl, i); + Io__Prometheus__Client__MetricFamily *fam = + metric_family_get(ds, vl, i, /* allocate = */ 1); if (fam == NULL) continue; @@ -759,7 +763,8 @@ static int prom_missing(value_list_t const *vl, pthread_mutex_lock(&metrics_lock); for (size_t i = 0; i < ds->ds_num; i++) { - Io__Prometheus__Client__MetricFamily *fam = metric_family_get(ds, vl, i); + Io__Prometheus__Client__MetricFamily *fam = + metric_family_get(ds, vl, i, /* allocate = */ 0); if (fam == NULL) continue; @@ -768,6 +773,7 @@ static int prom_missing(value_list_t const *vl, ERROR("write_prometheus plugin: Deleting a metric in family \"%s\" " "failed with status %d", fam->name, status); + continue; } -- 2.30.2