From 0b1dd30a1d02f76f78a334db59ac8679a81f22cb Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Fri, 22 Dec 2023 08:13:22 +0100 Subject: [PATCH] src/daemon/resource.c: Allow default resource attributes to be empty. To achieve this, track whether or not the struct has been initialized separately, so that users can remove all the attributes if they wish. --- src/collectd.conf.pod | 7 +++++++ src/daemon/resource.c | 7 +++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod index d24202c14..cbc385f71 100644 --- a/src/collectd.conf.pod +++ b/src/collectd.conf.pod @@ -362,6 +362,13 @@ L. Minimal defaults for maximum flexibility. Only the C attribute is populated. +To also remove the C resource attribute, set it to an empty +string: + + + Attribute "service.name" "" + + =back Inside the B block, the following configuration options are valid: diff --git a/src/daemon/resource.c b/src/daemon/resource.c index eebb98b3f..d2d828da1 100644 --- a/src/daemon/resource.c +++ b/src/daemon/resource.c @@ -29,6 +29,7 @@ #include "utils/common/common.h" +static bool default_resource_initialized = false; static label_set_t default_resource; static void otel_service_name(void) { @@ -105,7 +106,7 @@ static int machine_id(void) { } static void resource_host_init(void) { - if (default_resource.num != 0) { + if (default_resource_initialized) { return; } @@ -113,15 +114,17 @@ static void resource_host_init(void) { otel_resource_attributes(); host_name(); machine_id(); + default_resource_initialized = true; } static void resource_generic_init(void) { - if (default_resource.num != 0) { + if (default_resource_initialized) { return; } otel_service_name(); otel_resource_attributes(); + default_resource_initialized = true; } int resource_attributes_init(char const *type) { -- 2.47.2