Skip to content

Fix WithGroup metric option being silently ignored - #129

Open
riptide-01 wants to merge 4 commits into
mainfrom
fix/metric-expire-not-working
Open

Fix WithGroup metric option being silently ignored#129
riptide-01 wants to merge 4 commits into
mainfrom
fix/metric-expire-not-working

Conversation

@riptide-01

@riptide-01 riptide-01 commented Aug 14, 2026

Copy link
Copy Markdown
Member

Description

operation.WithGroup() is the only public way for a Go hook to assign a metric to a group, but it never actually took effect. The option method was declared on a value receiver, so the assignment mutated a copy of the operation and was thrown away, even though the collector correctly applies options through a pointer.

Tests

func handlerHook(_ context.Context, input *pkg.HookInput) error {
	input.MetricsCollector.Set(metricName, 1, map[string]string{"test": "1"}, operation.WithGroup(metricGroup))
	input.MetricsCollector.Set(metricName2, 2, map[string]string{"test": "2"})
	input.MetricsCollector.Expire(metricGroup)
	return nil
}

Before:
image

After:
image

…e return types for MetricOperations functions

Signed-off-by: Smyslov Maxim <maksim.smyslov@flant.com>
Signed-off-by: Smyslov Maxim <maksim.smyslov@flant.com>
Signed-off-by: Smyslov Maxim <maksim.smyslov@flant.com>
Signed-off-by: Smyslov Maxim <maksim.smyslov@flant.com>
@riptide-01
riptide-01 requested a review from ldmonster August 14, 2026 14:34
@riptide-01 riptide-01 self-assigned this Aug 14, 2026
@riptide-01 riptide-01 changed the title Fix/metric expire not working WithGroup() operation don't set the metric group Aug 17, 2026
@riptide-01 riptide-01 changed the title WithGroup() operation don't set the metric group Fix WithGroup metric option being silently ignored Aug 17, 2026
@riptide-01
riptide-01 marked this pull request as ready for review August 17, 2026 07:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant