]> git.ipfire.org Git - thirdparty/collectd.git/commitdiff
src/daemon/resource.c: Allow default resource attributes to be empty. 4199/head
authorFlorian Forster <octo@collectd.org>
Fri, 22 Dec 2023 07:13:22 +0000 (08:13 +0100)
committerFlorian Forster <octo@collectd.org>
Thu, 28 Dec 2023 08:08:20 +0000 (09:08 +0100)
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
src/daemon/resource.c

index d24202c14ac94f8df8a755ff673fde2cd33fe6c2..cbc385f71a4aad2490b6bcec87e56956e495711a 100644 (file)
@@ -362,6 +362,13 @@ L<https://opentelemetry.io/docs/specs/semconv/resource/host/>.
 Minimal defaults for maximum flexibility. Only the C<service.name> attribute is
 populated.
 
+To also remove the C<service.name> resource attribute, set it to an empty
+string:
+
+  <Resource Generic>
+    Attribute "service.name" ""
+  </Resource>
+
 =back
 
 Inside the B<Resource> block, the following configuration options are valid:
index eebb98b3fed2fcb0cc32193b89977ed224457613..d2d828da1fc0392779cf34bd0e4eaf9de1cdbb70 100644 (file)
@@ -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) {