Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix the issue that duplicated CR metrics are generated when CRD is deleted/applied multiple times #2257

Closed
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions internal/store/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,22 @@ func (b *Builder) WithEnabledResources(r []string) error {
sort.Strings(sortedResources)

b.enabledResources = append(b.enabledResources, sortedResources...)
b.enabledResources = unique(b.enabledResources)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense to have a map[string] bool here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think using unique is fine as a mitigation.

It didn't remove deleted CR https://github.com/rexagod/kube-state-metrics/blob/25a1d8da057cf761d614c59a52785335d34082d1/internal/discovery/discovery.go#L232. After this is fixed, we can remove unique.

return nil
}

func unique(arr []string) []string {
mp := make(map[string]bool)
for _, s := range arr {
mp[s] = true
}
result := []string{}
for key, _ := range mp {
result = append(result, key)
}
return result
}

// WithFieldSelectorFilter sets the fieldSelector property of a Builder.
func (b *Builder) WithFieldSelectorFilter(fieldSelectorFilter string) {
b.fieldSelectorFilter = fieldSelectorFilter
Expand Down
Loading