]> git.ipfire.org Git - thirdparty/collectd.git/commitdiff
write_prometheus plugin: Emit resource attributes only, if they differ from the default.
authorFlorian Forster <octo@collectd.org>
Fri, 22 Dec 2023 22:44:09 +0000 (23:44 +0100)
committerFlorian Forster <octo@collectd.org>
Thu, 28 Dec 2023 19:13:31 +0000 (20:13 +0100)
src/write_prometheus.c

index 8a0e35f7e3f2de8b6c7d30e1f5222df778effdc4..5a77a3066fa6fc6fbbb26f50d70b2ddd7165bf24 100644 (file)
@@ -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;
   }