fix: remove metrics when streams are deleted - #474
Open
bookcherry wants to merge 1 commit into
Open
Conversation
Track metric series created within each stream scope and delete them when the stream is removed, updated, or stopped. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
|
This was referenced Aug 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Companion PR
DeleteLabelValuessupportManual verification
The Benthos and Redpanda Connect branches were combined in a temporary Go workspace so the Connect process used the modified Benthos module. Redpanda Connect was then started in streams mode with file watching enabled, the HTTP API listening on port 4195, and the Prometheus metrics exporter enabled.
The root configuration used for verification was:
Each test stream continuously generated messages and emitted a custom counter:
Pre-fix reproduction
The same test was first run against the commits immediately before these changes:
70c0dfc70f5203c9a5After creating stream
trigger-g, the Prometheus endpoint exposed 22 series carrying the stream label:The stream configuration was then deleted. The file watcher confirmed successful stream removal:
However, all 22 series remained visible after waiting for the removal to complete:
The procedure was repeated with four unique stream IDs:
trigger-g,verify-a,verify-b, andverify-c. Each deleted stream retained 22 series, resulting in 88 stale series in total.Patched behavior
The identical test was run with both patched branches. Stream
trigger-ginitially exposed 22 series. After deleting the stream configuration and observing the removal logs, no corresponding series remained:The three additional stream IDs were also created and deleted. Each exposed 22 series while active, and the combined stale-series count after deletion was 0.
Update lifecycle
A stream named
foowas created with a custom metric namedstream_old_metric. Its configuration was then updated in place to emitstream_new_metricinstead.After the watcher completed the update:
This confirms that the previous stream instance is cleaned up before the replacement remains active.
Same-ID recreation
Stream
foowas deleted and the metrics endpoint was checked until no series labelledstream="foo"remained. A new configuration using the same stream ID was then created with a different custom metric.The recreated stream emitted its new series normally. Deleting the recreated stream removed all of its series again, confirming that cleanup from the original instance does not delete metrics belonging to the replacement instance.
Manager shutdown
The stream manager test creates multiple active streams, calls
Stop(), and immediately inspects the metrics exporter afterStop()returns. No series for either stream remain, confirming that cleanup completes synchronously before shutdown returns.Automated verification
go test -race ./internal/component/metrics ./internal/stream/manager ./public/serviceThe tests cover:
Related to #275.