From: Florian Forster Date: Fri, 22 Dec 2023 22:44:09 +0000 (+0100) Subject: write_prometheus plugin: Emit resource attributes only, if they differ from the default. X-Git-Tag: 6.0.0-rc0~23^2~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1b88478aa4b330bd2f5699a77aba163d53b1817f;p=thirdparty%2Fcollectd.git write_prometheus plugin: Emit resource attributes only, if they differ from the default. --- diff --git a/src/write_prometheus.c b/src/write_prometheus.c index 8a0e35f7e..5a77a3066 100644 --- a/src/write_prometheus.c +++ b/src/write_prometheus.c @@ -111,19 +111,20 @@ static int format_metric(strbuf_t *buf, metric_t const *m) { if ((buf == NULL) || (m == NULL) || (m->family == NULL)) { return EINVAL; } - label_set_t const *resource = &m->family->resource; + label_set_t resource = m->family->resource; int status = strbuf_print_restricted(buf, m->family->name, VALID_NAME_CHARS, '_'); - if (resource->num == 0 && m->label.num == 0) { + if (resource.num == 0 && m->label.num == 0) { return status; } status = status || strbuf_print(buf, "{"); bool first_label = true; - if (resource->num != 0) { - status = status || format_label_set(buf, resource, RESOURCE_LABEL_PREFIX, + if (resource.num != 0 && + label_set_compare(resource, default_resource_attributes()) != 0) { + status = status || format_label_set(buf, &resource, RESOURCE_LABEL_PREFIX, true, first_label); first_label = false; }