/* 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.");
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.");
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;
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;
ERROR("write_prometheus plugin: Deleting a metric in family \"%s\" "
"failed with status %d",
fam->name, status);
+
continue;
}