Skip to content

Commit 8d651bb

Browse files
b84330808claude
andcommitted
fix(go.d/docker): check every chart when removing a container's charts
Charts().Get returns only the first chart with an ID. A container that is removed and recreated before its old charts are pruned has two charts with the same ID, so check all of them. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 4492d5e commit 8d651bb

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

‎src/go/plugin/go.d/collector/docker/charts.go‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,16 @@ func (c *Collector) addContainerCharts(name, image string) {
165165
func (c *Collector) removeContainerCharts(name string) {
166166
// Match exact chart IDs: a prefix match would also remove the charts of
167167
// other containers whose names start with this one (e.g. "foo" and "foo-bar").
168+
ids := make(map[string]bool, len(containerChartsTmpl))
168169
for _, tmpl := range containerChartsTmpl {
169-
if chart := c.Charts().Get(fmt.Sprintf(tmpl.ID, name)); chart != nil {
170+
ids[fmt.Sprintf(tmpl.ID, name)] = true
171+
}
172+
173+
// Check every chart rather than Charts().Get, which returns only the first
174+
// match: a container removed and recreated before the old charts are pruned
175+
// has two charts with the same ID.
176+
for _, chart := range *c.Charts() {
177+
if ids[chart.ID] {
170178
chart.MarkRemove()
171179
chart.MarkNotCreated()
172180
}

0 commit comments

Comments
 (0)