fix: delete Prometheus series for removed streams - #4694
Open
bookcherry wants to merge 1 commit into
Open
Conversation
Implement metric deletion for counters, gauges, summaries, and histograms so Benthos stream cleanup removes stale Prometheus series. 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
DeleteLabelValuesDependency
Depends on redpanda-data/benthos#474, which adds stream-scoped metric lifecycle cleanup.
Manual integration verification
This Connect branch and the Benthos PR branch were combined in a temporary Go workspace so the running process used both changes. Redpanda Connect was started in streams mode with file watching enabled, the HTTP API listening on port 4195, and the Prometheus exporter enabled.
The observability configuration was:
The watched stream continuously generated messages and emitted a custom counter through a metric processor.
Stream deletion
Before deleting stream
trigger-g, the Prometheus endpoint exposed 22 series labelled with that stream ID:After deleting the stream configuration, the watcher logged successful removal:
The metrics endpoint was queried again after removal completed:
The test was repeated with
verify-a,verify-b, andverify-c. Each stream exposed 22 series while active. After all three configurations were deleted, no series remained for any of those IDs.Stream update
Stream
fooinitially emittedstream_old_metric. Its configuration was changed in place to emitstream_new_metric.After the watcher applied the update:
This verifies both that the old Prometheus series is removed and that cleanup does not remove the replacement stream series.
Same-ID recreation
Stream
foowas deleted, and the endpoint was checked until the number of series labelledstream="foo"reached 0. The same stream ID was then recreated with a different metric name.The new series appeared normally. After deleting the recreated stream, the series count returned to 0.
Pre-fix comparison
The identical procedure was run against Benthos
70c0dfc70and Connectf5203c9a5, before these changes. Deleting four streams left 22 stale series per stream, or 88 stale series in total. With the patched branches, the stale-series count was 0.Automated verification
Prometheus exporter tests:
go test -race ./internal/impl/prometheusThe same test suite was also run while resolving the Benthos dependency to the companion PR branch.
The tests cover deletion of:
Related issue: redpanda-data/benthos#275.