chrony: add support for REQ_CLIENT_ACCESSES_BY_INDEX#522
Conversation
Adds the REQ_CLIENT_ACCESSES_BY_INDEX3 codec so client.Communicate can return decoded per-client statistics (the data backing 'chronyc clients'): NTP/NKE/Cmd hit and drop counters plus last-hit timestamps. Constants and struct layouts follow chrony's candm.h. Only the v3 codec is implemented: modern chronyd (4.0+) always replies with v3 regardless of the request version, and chrony 3.x changed the wire layout of reply code 10 without changing the code itself, which makes v1 decoding ambiguous. chronyd older than 4.0 returns BADPKTVERSION, documented on the constructor. Resetting chronyd's accounting (the 'chronyc -r clients' flag) is exposed through a separate NewClientAccessesByIndexResetPacket constructor to keep the counter-clearing side effect off the default API. Motivation: unblocks per-client Prometheus metrics in chrony_exporter (SuperQ/chrony_exporter#136).
|
Hi @luca-seemann! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
|
I am fixing CI sorry about that |
Summary
Adds the
REQ_CLIENT_ACCESSES_BY_INDEX3codec tontp/chronysoClient.Communicatecan return decoded per-client statistics — thedata that backs
chronyc clients: NTP/NKE/Cmd hit and drop countersplus last-hit timestamps tracked by chronyd internally.
Motivation: unblocks per-client Prometheus metrics in
chrony_exporter(SuperQ/chrony_exporter#136),
where downstream consumers currently have to hand-roll the wire format
because this library doesn't expose the command.
Constants and struct layouts follow chrony's
candm.h.Only the v3 codec is implemented because modern chronyd (4.0+) always
replies with
RPY_CLIENT_ACCESSES_BY_INDEX3regardless of the requestversion, and chrony 3.x changed the wire layout of reply code 10 without
changing the code itself, which makes v1 decoding ambiguous. chronyd
older than 4.0 returns
BADPKTVERSION; this is documented on theconstructor.
Request padding: chronyd's
PKL_CommandLength(pktlength.c) enforces ananti-amplification minimum so the request must be at least as large as
the reply. The v3 'clients' reply is 520 bytes, so the request also
needs to be 520 bytes — the
dataarray onRequestClientAccessesByIndexis sized accordingly. Smaller requests are rejected with
BADPKTLENGTH.Two constructors are provided:
NewClientAccessesByIndexPacketfornormal polling and
NewClientAccessesByIndexResetPacketfor thechronyc -r clientsequivalent that clears chronyd's accounting afterthe reply. Keeping the counter-clearing variant separate avoids
accidentally resetting stats from a polling loop.
Test Plan
go test ./ntp/chrony/...- all tests pass, including:TestDecodeClientAccessesByIndex3- real bytes captured from chronyd4.6.1 via
strace, IPs substituted with RFC 5737/3849 documentationranges
TestDecodeClientAccessesByIndex3Empty-NClients == 0edge caseTestEncodeClientAccessesByIndexPacket- asserts exact 520-bytewire size
TestEncodeClientAccessesByIndexResetPacket- verifies the resetvariant sets
Reset=1TestClientCommunicateClientAccessesByIndex- end-to-end viaClient.Communicatewith a mock connectiongo test ./ntp/chrony/... -fuzz=FuzzDecodePacket -fuzztime=10s- over1.4M random inputs with no panics
go vet ./ntp/chrony/...cleanpaginated through 4096 clients (513 pages), output matches
chronyc clientsline-for-line.