Add the COLLECTION_OWNERSHIP method

Draft
IL
5h ago
+9475-53

Summary

Adds method 6, COLLECTION_OWNERSHIP, served as collection-ownership. Several hosts can be configured to collect the same units (for example one SNMP device); a local provider coordinates them so that one host collects each unit. A collecting process asks the provider whether this host owns its units and keeps that interest alive by asking again: the request is also the heartbeat, and a unit that is no longer renewed loses its lease on the provider side. An explicit release ends a lease at once.

The contract is docs/codec-collection-ownership.md. In short:

  • Request: a non-zero random consumer_id and a consumer name, then zero or more items. Each item has an intent (RENEW or RELEASE), a COLLECTING flag, a node id, and four strings: group, unit, module and job. Canonical packing: every offset is determined by the lengths, and decoders reject anything else.
  • Response: provider_instance, lease_ms, renew_ms, and one fixed 8-byte status per request item, in request order: OWNED, STANDBY, PENDING, RELEASED, NO_GROUP or INVALID_UNIT.
  • Idempotency: every item states the consumer's full current state for a unit, so a duplicated delivery has the same effect as one.
  • Not in the wire contract: what a consumer does with an answer or without one, and the timing values a provider uses. Those are policy of the deployment.

What is implemented, in C, Rust and Go:

  • Codecs, response builder and dispatch.
  • Typed Level 2 client and server. One request per call: a request above the configured payload limit fails with an overflow error before anything is sent and the client stays connected, so callers split their units across calls. Clients reject a response that does not answer the request; servers reject a handler response that leaves a status unset or answers against an item's intent.
  • Round-trip, rejection, every-prefix truncation, builder and dispatch tests; decode fuzz targets with a canonical re-encode check; shared interop fixtures, the codec interop files and the lookup-scale interop matrix (POSIX and Windows scripts).
  • Docs and the coverage, fuzz and interop script lists.
  • Go consumers import github.com/netdata/plugin-ipc/src/go/pkg/netipc/service/collection_ownership (typed client and server) and github.com/netdata/plugin-ipc/src/go/pkg/netipc/protocol (codec). The branch is merged with main, so it uses the module path from #22 and carries no test_uds change of its own (#20 is in main).

The existing methods are not changed. The lookup family's stitching and generation rules are not reused: ownership items are independent, so they would add rules without value.

Validation

  • Linux x86_64: cargo fmt --check, clippy with the CI gates and 442 Rust lib tests; go vet and go test -race ./...; ctest 32/32 including the Rust and Go suites; ASan/UBSan 7/7 with no findings; codec interop, service interop on baseline and SHM, and lookup-scale 45/45 on both profiles, including the nine ownership pairs.
  • Linux arm64: codec interop and lookup-scale 45/45 on both profiles.
  • macOS arm64: the C protocol and service tests, with no warnings; the Go protocol and service packages with -race.
  • Coverage of the new files: C codec 98.3% and C service 90.3%; the Go typed package 100% and the Go raw call function 86.5%, where the remainder is defensive branches a working client does not reach.
  • Not run locally: Windows builds and tests (the new Windows C tests have not been compiled yet) and the 32-bit targets, whose expectations come from reading the code. Both are left to CI here.

Notes for the reviewer

  • The C apps and cgroups lookup clients resend header bytes as the payload when they retry over SHM after a reconnect. This PR does not touch that code; #19 fixes it. The ownership client is not affected because it encodes the request again on every attempt.
  • On an aborted call the C ownership client ends the session, as Go and Rust do; the existing C lookup clients still stay READY.
  • The remaining-timeout helper now exists in three C service files and could move into a shared one.
  • The Rust apps-lookup dispatch handles a failing handler differently from the ownership dispatch.

Summary by cubic

Adds the COLLECTION_OWNERSHIP method (code 6) as the collection-ownership service in C, Rust, and Go. Collecting processes lease collection units from a local provider: a request also serves as the heartbeat, so a missed renewal ends the lease, and an explicit RELEASE ends it immediately. One public call is one request and one response; oversized requests fail with an overflow error before sending, so callers split units across calls.

Also merges upstream main, which brings in the glibc time64 test fixture guard (#20) and moves the Go module to github.com/netdata/plugin-ipc/src/go; the ownership Go files now use the new path.

Validation

  • Tested on Linux x86_64, Linux arm64, and macOS arm64; C codec coverage is 98.3% and C service 90.3%, Go typed package 100%.
  • Windows and 32-bit targets are not built or tested here; CI will run them.

Notes

  • The C apps and cgroups lookup clients resend header bytes as payload when retrying over SHM; not touched here, and #19 fixes it.
  • Review findings addressed: typed clients check the configured request limit before growing their buffer, the C client ends the session when a pending abort ends a call, and the contract states that PENDING, NO_GROUP, and INVALID_UNIT answer RENEW items only.
  • The Rust typed facade now routes through the raw client's default call instead of the timeout variant with zero, so the default-timeout call has one definition and is covered by facade tests.