From: Florian Forster Date: Fri, 22 Dec 2023 07:13:22 +0000 (+0100) Subject: src/daemon/resource.c: Allow default resource attributes to be empty. X-Git-Tag: 6.0.0-rc0~25^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F4199%2Fhead;p=thirdparty%2Fcollectd.git 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. --- 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) {