Florian Forster [Thu, 21 Dec 2023 15:10:55 +0000 (16:10 +0100)]
strbuf: Rewrite `strbuf_print_restricted` using a bitmap.
Instead of building the buffer piece by piece, copy the entire string into
the buffer and do the replacements there.
I think the code is quite efficient, but I haven't profiled either
version so can't say for sure that there is a speedup. The new code
*may* be easier to reason about, since the "copy and replace" approach
has a much simpler loop body than the previous approach.
Florian Forster [Thu, 21 Dec 2023 10:38:20 +0000 (11:38 +0100)]
strbuf: Add `strbuf_print_restricted`.
This new function is similar to `strbuf_print_escaped` but differs in two
important aspects:
* `strbuf_print_restricted` expects a list of acceptable characters,
i.e. an allow list. `strbuf_print_escaped` expects a deny list.
* `strbuf_print_restricted` *replaces* characters not in the allow list.
`strbuf_print_escaped` adds an escape character in front of the
denied character.
Florian Forster [Sun, 17 Dec 2023 08:45:11 +0000 (09:45 +0100)]
resource_metrics: Skip duplicate metrics instead of erroring out.
The semantics have been changed to simply ignore metrics that are already
in the set. The previous semantic was optimized for a "add and if that
fails flush and try again" plugin behavior. With the support for multiple
instances of the same metric (at different times), there no longer is a
need to ensure metrics in the set are unique.
Florian Forster [Sat, 16 Dec 2023 11:58:37 +0000 (12:58 +0100)]
resource_metrics: Fix bugs surfaced by the unit test.
* Sort metric families after inserting.
* Dereference the pointer-pointer returned by `bsearch` in `lookup_family`.
* Delete the metrics created by `metric_family_clone`.
* Run ./contrib/format.sh
Florian Forster [Sat, 16 Dec 2023 07:26:26 +0000 (08:26 +0100)]
New utility: resource_metrics.
Resource metrics allows plugin to stage metric families, grouped by
resource. This is designed to work well with plugins that export the
OpenTelemetry protocol.
Florian Forster [Wed, 29 Nov 2023 12:41:32 +0000 (13:41 +0100)]
write_riemann plugin: use reference counting to when freeing user data.
While reference counting was present previously, it had problems:
* The reference passed to `plugin_register_flush()` was not counted.
* If a flush plugin was registered, `free_func` was set to NULL but
the reference passed to `plugin_register_notification()` was still
counted, meaning in that case the counter never went to zero.
* Mutexes must be unlocked when calling `pthread_mutex_destroy()`.
* The code limped on after an error, returning a failure eventually.
This is unnecessarily complex control flow that has been simplified.
Leonard Göhrs [Fri, 24 Mar 2023 09:49:24 +0000 (10:49 +0100)]
src/write_http.c: use reference counting to decide when to free user_data
The teardown code for the wh_callback_t struct previously relied on
the order in which the different callback functions are de-initialized
to be known and to never change.
This is prone to failure and is indeed currently broken, leading to a
segmentation fault on collectd exit.
Fix this by counting the active references to the user data and freeing
it once it reaches zero.
Signed-off-by: Leonard Göhrs <l.goehrs@pengutronix.de>
Apparently we defined a bunch of `plugin_foo` variables that were never
used. The generated list from the arguments to `AC_PLUGIN` now appear as
duplicates. This removes the previously unused definitions and leaves
the generated ones.
Florian Forster [Tue, 28 Nov 2023 18:31:11 +0000 (19:31 +0100)]
procevent plugin: remove use of a nested flexible array member.
The previous code used an ad-hoc struct to construct or parse a Netlink
message. This relied on allocating a field _after_ the struct with the
flexible array member, which is prohibited by the C standard, leading to
compiler warnings.
Florian Forster [Sat, 25 Nov 2023 13:12:59 +0000 (14:12 +0100)]
SMART plugin: initialize struct passed to `ioctl(2)`.
Valgrind is complaining about a conditional jump based on uninitialized
memory:
```
==66462== Conditional jump or move depends on uninitialised value(s)
==66462== at 0x10C500: smart_read_nvme_intel_disk (in /__w/collectd/collectd/test_plugin_smart)
==66462== by 0x10D366: test_x (in /__w/collectd/collectd/test_plugin_smart)
==66462== by 0x10D638: main (in /__w/collectd/collectd/test_plugin_smart)
```
This may be due to the `struct nvme_additional_smart_log` being
uninitialized when it's being passed to `ioctl(2)`.
This there, this removed an unnecessary level of indentation.
Florian Forster [Sat, 25 Nov 2023 12:51:57 +0000 (13:51 +0100)]
Netlink plugin: complete initialize structs used for testing.
Valgrind complains about a conditional jump based on uninitialized
memory:
```
==66438== Conditional jump or move depends on uninitialised value(s)
==66438== at 0x10CA06: vf_info_submit (in /__w/collectd/collectd/test_plugin_netlink)
==66438== by 0x1110F2: test_vf_submit_test (in /__w/collectd/collectd/test_plugin_netlink)
==66438== by 0x112EAC: main (in /__w/collectd/collectd/test_plugin_netlink)
```
This is likely caused by the `vf_stats_t` being only partially
initialized. Using a struct initializer is not only cleaner, it also
ensures the remainder of the struct is initialized to zero.