Feature/improved collected and added tests#1310
Merged
Merged
Conversation
- UB / sanitizer-unsafe encoding (collectd_packet.hpp): replaced all reinterpret_cast writes into the std::string buffer (unaligned + aliasing UB) with aligned-local + append helpers. - Gauge endianness: gauges are now explicitly little-endian per the collectd spec (was raw native — wrong on big-endian), verified by a round-trip test. - IPv6 multicast never sent (collectd_client.hpp): the send loop now matches the target's address family for both v4 and v6, with a default-bound-socket fallback. - submit() emitted empty datagrams: now returns an explicit "not supported — collectd only forwards metrics" response. - Hard-coded 5s interval: now a configurable interval setting (default 10s), carried through to the wire. - Per-packet io_context churn + buffer reuse bug: one io_context per flush; udp_sender owns a per-send buffer via a captured shared_ptr, so multiple packets can be queued safely. - counter_value/untyped_value dropped in flatten_metrics: now mapped instead of logged as "unknown". Hardening / cleanup - is_full() raised from 200 bytes to the real 1452-byte collectd network MTU (named constant), with a fragmentation test asserting every packet stays within it. - Metric→collectd mapping is now settings-driven ([/settings/collectd/client/variables] and [.../metrics]) with the previous hard-coded table preserved as built-in defaults. - Copy-paste leftovers removed: client id nsca→collectd, the "NSCA passive check module" section text, Windows-only hostname help, and the dead NRPE/NSCA CLI options (payload-length, password, time-offset, …) replaced with a real interval option. Signed-off-by: Michael Medin <michael@medin.name>
Signed-off-by: Michael Medin <michael@medin.name>
Signed-off-by: Michael Medin <michael@medin.name>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves NSClient++’s CollectdClient by making its collectd binary protocol output more correct/configurable and adds both unit and integration tests to validate real-world interoperability with collectd (including a real collectd daemon over UDP).
Changes:
- Add settings-driven metric mapping/variable expansion and interval reporting for CollectdClient, plus better UDP send behavior.
- Introduce unit tests for collectd packet encoding/builder behavior and Jest integration tests (in-process UDP decoder + real collectd daemon container).
- Refactor collectd packet encoding internals to avoid UB/aliasing issues and add protocol constants/size limits.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/Dockerfiles/entrypoints/collectd.conf | Minimal collectd config for daemon-based integration testing (network receiver + csv output). |
| tests/Dockerfiles/collectd.Dockerfile | Debian-based collectd image for UDP-based end-to-end integration tests. |
| tests/collectd-submit.test.ts | In-process UDP receiver/decoder validating collectd binary packets emitted by NSClient++. |
| tests/collectd-daemon.test.ts | End-to-end validation against a real collectd daemon writing CSV output. |
| modules/CollectdClient/CollectdClient.h | Keep a shared handler instance for settings-driven configuration. |
| modules/CollectdClient/CollectdClient.cpp | Wire settings for hostname, interval, variables, and metrics mapping into the handler. |
| modules/CollectdClient/collectd_packet_test.cpp | New GTest suite validating packet layout, endianness, mapping expansion, and fragmentation. |
| modules/CollectdClient/collectd_handler.hpp | Simplify/adjust target options reader (now includes an interval option). |
| modules/CollectdClient/collectd_client.hpp | Implement platform-specific default mappings, interval handling, and improved UDP sending/metrics handling. |
| modules/CollectdClient/CMakeLists.txt | Register the new collectd packet unit test target. |
| include/net/collectd/collectd_packet.hpp | Refactor protocol encoding (TLV enums, endian-safe appends, max packet sizing). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: Michael Medin <michael@medin.name>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.