Skip to content

Feature/improved collected and added tests#1310

Merged
mickem merged 4 commits into
mainfrom
feature/improved_collected_and_added_tests
Jun 5, 2026
Merged

Feature/improved collected and added tests#1310
mickem merged 4 commits into
mainfrom
feature/improved_collected_and_added_tests

Conversation

@mickem
Copy link
Copy Markdown
Owner

@mickem mickem commented Jun 5, 2026

No description provided.

mickem added 3 commits June 5, 2026 07:26
 - 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>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread modules/CollectdClient/collectd_client.hpp
Comment thread modules/CollectdClient/collectd_handler.hpp
Comment thread include/net/collectd/collectd_packet.hpp Outdated
Signed-off-by: Michael Medin <michael@medin.name>
@mickem mickem merged commit e967422 into main Jun 5, 2026
28 checks passed
@mickem mickem deleted the feature/improved_collected_and_added_tests branch June 5, 2026 08:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants