From 4d1840342b02f27a763902af4ebd4ef136b4635e Mon Sep 17 00:00:00 2001 From: Frank Jogeleit Date: Tue, 21 Nov 2023 11:39:06 +0100 Subject: [PATCH] Fix cache fallback (#369) * Fix Cache fallback Signed-off-by: Frank Jogeleit * update changelog Signed-off-by: Frank Jogeleit --------- Signed-off-by: Frank Jogeleit --- CHANGELOG.md | 7 ++++++- pkg/listener/metrics/cache.go | 5 +---- pkg/listener/metrics/result_custom.go | 4 +++- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 65e7f5eb..c7ea03e8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,13 @@ # Changelog +# Next +* Policy Reporter v2.17.3 + * Fix handling if metric cache fallback + # 2.21.2 -* Policy Reporter +* Policy Reporter v2.17.2 * Fix ID generation for Policy Reports which using `scope` as resource reference + * Add optional `message` metric label * Helm Chart * fix: Add chart parameters for setting `revisionHistoryLimit` [[#363](https://github.com/kyverno/policy-reporter/pull/363) by [bodgit](https://github.com/bodgit)] * fix: allow not setting `.Values.podSecurityContext` for kyvernoPlugin [[#361](https://github.com/kyverno/policy-reporter/pull/361) by [haraldsk](https://github.com/haraldsk)] diff --git a/pkg/listener/metrics/cache.go b/pkg/listener/metrics/cache.go index 2122b0b1..5a5d21ac 100644 --- a/pkg/listener/metrics/cache.go +++ b/pkg/listener/metrics/cache.go @@ -61,10 +61,7 @@ func (c *Cache) GetReportLabels(id string) []*CacheItem { return item.([]*CacheItem) } - return []*CacheItem{{ - Labels: make(prometheus.Labels), - Value: 0, - }} + return []*CacheItem{} } func labelHash(labels prometheus.Labels) string { diff --git a/pkg/listener/metrics/result_custom.go b/pkg/listener/metrics/result_custom.go index c31658a0..5e5d729a 100644 --- a/pkg/listener/metrics/result_custom.go +++ b/pkg/listener/metrics/result_custom.go @@ -60,7 +60,9 @@ func CreateCustomResultMetricsListener( case report.Deleted: items := cache.GetReportLabels(newReport.GetID()) for _, item := range items { - decreaseOrDelete(gauge, item.Labels, item.Value) + if len(item.Labels) > 0 { + decreaseOrDelete(gauge, item.Labels, item.Value) + } } cache.Remove(newReport.GetID())