]> git.ipfire.org Git - thirdparty/collectd.git/commitdiff
write_open_telemetry plugin: Take the resource attributes into account when comparing...
authorFlorian Forster <octo@collectd.org>
Thu, 14 Dec 2023 11:54:42 +0000 (12:54 +0100)
committerFlorian Forster <octo@collectd.org>
Wed, 3 Jan 2024 16:16:28 +0000 (17:16 +0100)
The `staged_metric_families` tree was only using the metric family's name
to stage metrics, which is incorrect with the new resource attributes.

The code is now using the new `metric_family_compare` function to take the
attributes also into account.

src/write_open_telemetry.cc

index a27ed6bdd0f69a399ae79b04912311c4fb5f0c6e..669e2b2531d68458a90634e7ec6d110920e3b4d4 100644 (file)
@@ -234,7 +234,7 @@ static bool ot_metric_is_staged(ot_callback_t *cb, metric_t const *m) {
 }
 
 static bool ot_need_flush(ot_callback_t *cb, metric_family_t const *fam) {
-  int status = c_avl_get(cb->staged_metric_families, fam->name, NULL);
+  int status = c_avl_get(cb->staged_metric_families, fam, NULL);
   if (status != 0) {
     return false;
   }
@@ -288,7 +288,7 @@ static int ot_mark_metric_staged(ot_callback_t *cb, metric_t const *m) {
 static metric_family_t *ot_staged_metric_family(ot_callback_t *cb,
                                                 metric_family_t const *fam) {
   metric_family_t *ret = NULL;
-  int status = c_avl_get(cb->staged_metric_families, fam->name, (void **)&ret);
+  int status = c_avl_get(cb->staged_metric_families, fam, (void **)&ret);
   if (status == 0) {
     DEBUG("write_open_telemetry plugin: Found staged metric family \"%s\"",
           ret->name);
@@ -296,7 +296,7 @@ static metric_family_t *ot_staged_metric_family(ot_callback_t *cb,
   }
 
   ret = metric_family_clone_shallow(fam);
-  c_avl_insert(cb->staged_metric_families, ret->name, ret);
+  c_avl_insert(cb->staged_metric_families, ret, ret);
   DEBUG("write_open_telemetry plugin: Successfully staged metric family \"%s\"",
         ret->name);
   return ret;
@@ -349,7 +349,7 @@ static int ot_config_node(oconfig_item_t *ci) {
   cb->staged_metrics =
       c_avl_create((int (*)(const void *, const void *))strcmp);
   cb->staged_metric_families =
-      c_avl_create((int (*)(const void *, const void *))strcmp);
+      c_avl_create((int (*)(const void *, const void *))metric_family_compare);
 
   pthread_mutex_init(&cb->mu, /* attr = */ NULL);