fix(hook): keep counter add metrics ungrouped by default#876
Conversation
When a hook emits {"action":"add"} without an explicit group, the parser
assigned the hook name as the default group. Grouped batches expire all
metrics in the group before applying new values, so counters were reset on
every run and stayed at the last increment only.
Leave group empty for counter add operations without an explicit group so
ApplyBatchOperations uses the non-grouped path and values accumulate.
|
The correct way to use hook metrics with expire previous runs metrics. |
|
Thanks for the note. Could you clarify or share an example? My understanding: counters with If there is a preferred pattern (e.g. always requiring an explicit |
Thanks for the follow-up. In the current design, accumulating metrics across hook runs is outside the scope of what hooks are meant to do. Shell-operator is a tool for running hooks in Kubernetes; hook metrics exist to track what happens inside a single hook execution, not to carry state from one run to the next. The scenario described in #868 is effectively trying to use hook metrics as cross-run storage. That is not a supported use case, so resetting counters via ExpireGroupMetrics before each batch is consistent with the intended model rather than a regression. If you need values to persist across runs, that should be handled outside the hook metrics layer—for example via Kubernetes objects, external storage, or another mechanism appropriate to your workflow—not by relying on action: add counters to accumulate between invocations. Happy to discuss further if a concrete example would help clarify the boundary. |
|
Thanks for the detailed explanation - that makes the design intent clear. Closing this PR. The behavior is correct as designed. |
What
Fixes #868
When a hook emits a counter with
action: addand no explicitgroup, the parser assigned the hook name as the default group. Grouped metric batches expire all series in the group before applying new values, so counters were reset on every run.Changes
defaultGroupforaction: addwhengroupis omittedApplyBatchOperationsVerification
go test ./pkg/hook/ -run 'TestMetricOperations|TestCounterAdd' -count=1