sems-stats: port to safe Rust, add -q switch#439
Open
hecko wants to merge 2 commits into
Open
Conversation
The Rust port lives alongside the other Rust monitoring tools in the existing Cargo workspace. It is feature-parity with the C++ client (same flags, same exit codes, same default output) plus a new `-q` / `--quiet` switch that prints only the server reply - useful for shell captures and Zabbix UserParameters. The C++ sources (core/plug-in/stats/query_stats.cxx) are untouched and still build; the install step only triggers when the Rust toolchain is unavailable, so there is no binary collision. Tests: 12 lib-level unit tests plus 3 integration tests that spin up a local UDP responder to exercise the request/reply roundtrip and the timeout path. `cargo test -p sems-stats` is wired into ctest via add_test. https://claude.ai/code/session_01BDutRs8JU8stspu6kpCQpd
sems-stats is an admin CLI for the stats/control UDP plug-in, not a monitoring query. It has no dependency on sems-monitoring-lib, the monitoring app, or xmlrpc2di - unlike every other Rust crate in apps/monitoring/tools/. Its natural home is /tools/, next to the sems-rtp-mux-* shell wrappers that call it. Cargo workspace is now at the repo root so /tools/sems-stats and apps/monitoring/tools/* share one target/ directory and one dependency graph. Rust toolchain detection is hoisted to the root CMakeLists.txt (SEMS_RUST_OK as a plain variable), which lets core/plug-in/stats/CMakeLists.txt gate its C++ install directly without the CACHE INTERNAL workaround. No behaviour change: the same binary ships to the same path; `cargo test -p sems-stats` still runs via ctest; all 15 tests pass. On a host without cargo the C++ sems-stats is still installed as the fallback. https://claude.ai/code/session_01BDutRs8JU8stspu6kpCQpd
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.
Summary
sems-statsin safe Rust (#![forbid(unsafe_code)]), std-only, no external crates. Lives in the existing Cargo workspace atapps/monitoring/tools/sems-stats/alongside the other Rust monitoring tools.-s -p -c -t -h), same defaults (127.0.0.1:5040,calls, 5s), same human-readable framing (sending '...\n' to host:port/received:\n<reply>), same exit-code semantics.-q/--quietswitch that prints only the server reply with a single trailing newline — useful for shell captures ($(sems-stats -q -c calls)) and Zabbix UserParameters.core/plug-in/stats/query_stats.cxx) are untouched. The C++ target still builds as a reference / fallback; the install step only runs when the Rust toolchain is unavailable, so there is no binary collision at$SEMS_EXEC_PREFIX/sbin/sems-stats.Build integration
sems-statstoapps/monitoring/tools/Cargo.tomlworkspace members.SEMS_MONITORING_BINARIESinapps/monitoring/CMakeLists.txtso the existing cargo build / install plumbing picks it up.CACHE INTERNAL(SEMS_HAS_RUST) socore/plug-in/stats/CMakeLists.txtcan skip itsinstall()when the Rust port is being shipped.cargo test -p sems-statswith CTest viaadd_test, soctest -Vexercises the crate.Tests
src/lib.rscoveringparse_args(defaults, every flag combination, every error variant),resolve_server,trim_reply(including the trailing-NUL semantic matching the C++ server's wire format), and the usage text.tests/udp_roundtrip.rsthat spin up a local UDP responder on127.0.0.1:0and exercise:set_loglevel 1) to confirm argv isn't tokenised,cargo test -p sems-stats --release→ 15 passed, 0 failed.Test plan
cmake -S . -B build && cmake --build buildsucceeds on a host with a recent Rust toolchain and producesapps/monitoring/tools/target/release/sems-stats.ctest -Vin the build directory runs the cargo tests and they pass.sems-statsis still installed (existing behaviour preserved).sems-stats -c callsprints the samesending ... / received: ...framing as the C++ version against a live SEMS instance.sems-stats -q -c callsprints a single lineActive calls: N.Dockerfile-rhel{8,9,10}) still lands asems-statsin the package at the same path.Refs #438 (indirectly — this is the Zabbix-UserParameter-friendly output path that issue will rely on).
https://claude.ai/code/session_01BDutRs8JU8stspu6kpCQpd