Hi list,

This series adds a 'clear counters server <backend>/<server>' CLI command to 
reset the statistics counters of a single server at runtime, without touching 
the rest of the proxy.

The motivation is the same operational context as my earlier 'set server name' 
series [1] (thanks again, Amaury, for the review): in Kubernetes-style setups a 
server slot is recycled and renamed to point at a fresh endpoint ('set server 
<b>/<s> name'), but the old cumulative counters stay attached to the slot and 
pollute the new entity's attribution. Being able to clear just that server's 
counters after a rename gives clean per-entity stats without a reload.

While implementing this I found and fixed a pre-existing bug, so the first
patch is a BUG/MEDIUM that stands on its own and is a backport candidate:

  1. BUG/MEDIUM: proxy_stats_clear_counters() did a blanket memset() on
     the counter structs for 'clear counters all'. Since the switch to
     per-thread-group shared counters that also zeroed the shared.tg
     pointer array, which the hot path dereferences with no NULL check ->
     segfault on the next request after the clear. It also silently failed
     to reset the cumulative counters. Replaced with helpers that preserve
     the pointer array and reset only the contents. Includes a regtest
     that reproduces the segfault.

  2. MINOR: factor the max-only reset (plain 'clear counters', OPER level)
     into counters_{fe,be}_reset_max() helpers, removing the open-coded
     inline field lists. While consolidating, the backend and server
     branches turned out to clear different subsets of the (identical)
     struct; the helper now clears the union, closing those latent gaps.
     No functional change for the 'all' path.

Now the patches that are actually related to the new feature:

  3. MINOR: the new command itself. OPER level, opt-in nothing, takes a
     SERVER_LOCK, resets both the native be_counters and the clearable
     module-registered extra counters, and leaves runtime state (address,
     weight, admin state) and health checks untouched.

  4. REGTESTS: drives traffic pinned to one server (a second, backup
     server stays idle), clears only the served server, and checks via
     'show stat' that its sessions dropped to zero while the backup is
     untouched.

  5. DOC: management.txt entry alongside 'clear counters' / 'clear
     counters all'.

The series builds at every step and both regtests pass. You can find it with 
the CI in this PR: https://github.com/sap-contributions/haproxy/pull/19

Curious to know what you think! This would also be part of 
https://github.com/jcmoraisjr/haproxy-ingress/pull/1481 and finalizes the 
server rename support of the ingress-controller.

Best regards,

Alexander

[1] https://www.mail-archive.com/[email protected]/msg47211.html


Attachment: 0001-BUG-MEDIUM-counters-preserve-shared.tg-pointer-on-cl.patch
Description: 0001-BUG-MEDIUM-counters-preserve-shared.tg-pointer-on-cl.patch

Attachment: 0002-MINOR-counters-add-max-only-reset-helpers-and-use-th.patch
Description: 0002-MINOR-counters-add-max-only-reset-helpers-and-use-th.patch

Attachment: 0003-MINOR-server-add-clear-counters-server-backend-serve.patch
Description: 0003-MINOR-server-add-clear-counters-server-backend-serve.patch

Attachment: 0004-REGTESTS-stats-add-test-for-clear-counters-server.patch
Description: 0004-REGTESTS-stats-add-test-for-clear-counters-server.patch

Attachment: 0005-DOC-management-document-clear-counters-server.patch
Description: 0005-DOC-management-document-clear-counters-server.patch

Reply via email to