From 1685de59899ecba60e56e711f1c392af40949e99 Mon Sep 17 00:00:00 2001 From: Catherine Fang Date: Tue, 5 Dec 2023 20:41:42 -0500 Subject: [PATCH] Remove obsolete CR metrics --- internal/store/builder.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/internal/store/builder.go b/internal/store/builder.go index 5c38857d7b..b538305eaf 100644 --- a/internal/store/builder.go +++ b/internal/store/builder.go @@ -195,6 +195,14 @@ func (b *Builder) DefaultGenerateCustomResourceStoresFunc() ksmtypes.BuildCustom // WithCustomResourceStoreFactories returns configures a custom resource stores factory func (b *Builder) WithCustomResourceStoreFactories(fs ...customresource.RegistryFactory) { + obsoleteCustomResource := map[string]bool{} + for k := range availableStores { + if notCustomResource(k) { + continue + } + obsoleteCustomResource[k] = true + } + for i := range fs { f := fs[i] gvr := util.GVRFromType(f.Name(), f.ExpectedType()) @@ -207,6 +215,7 @@ func (b *Builder) WithCustomResourceStoreFactories(fs ...customresource.Registry if _, ok := availableStores[gvrString]; ok { klog.InfoS("Updating store", "GVR", gvrString) } + obsoleteCustomResource[f.Name()] = false availableStores[gvrString] = func(b *Builder) []cache.Store { return b.buildCustomResourceStoresFunc( f.Name(), @@ -217,6 +226,11 @@ func (b *Builder) WithCustomResourceStoreFactories(fs ...customresource.Registry ) } } + for k, v := range obsoleteCustomResource { + if v { + delete(availableStores, k) + } + } } // allowList validates the given map and checks if the resources exists. @@ -616,3 +630,7 @@ func cacheStoresToMetricStores(cStores []cache.Store) []*metricsstore.MetricsSto return mStores } + +func notCustomResource(name string) bool { + return resourceExists(name) +}