mirror of
https://github.com/kyverno/policy-reporter.git
synced 2024-12-14 11:57:32 +00:00
remove labels from deleted reports and rules
This commit is contained in:
parent
a9f9fcd5c9
commit
04c220d3e3
5 changed files with 49 additions and 56 deletions
|
@ -1,4 +1,4 @@
|
|||
FROM golang:1.16 as builder
|
||||
FROM golang:1.16-buster as builder
|
||||
|
||||
WORKDIR /app
|
||||
COPY . .
|
||||
|
|
|
@ -3,5 +3,5 @@ name: policy-reporter
|
|||
description: K8s PolicyReporter watches for wgpolicyk8s.io/v1alpha1.PolicyReport resources. It creates Prometheus Metrics and can send rule validation events to Loki
|
||||
|
||||
type: application
|
||||
version: 0.6.0
|
||||
appVersion: 0.5.0
|
||||
version: 0.6.1
|
||||
appVersion: 0.5.1
|
||||
|
|
|
@ -15,7 +15,7 @@ metrics:
|
|||
image:
|
||||
repository: fjogeleit/policy-reporter
|
||||
pullPolicy: IfNotPresent
|
||||
tag: 0.5.0
|
||||
tag: 0.5.1
|
||||
|
||||
imagePullSecrets: []
|
||||
|
||||
|
|
|
@ -64,16 +64,14 @@ func (m ClusterPolicyReportMetrics) GenerateMetrics() error {
|
|||
|
||||
for _, rule := range m.getCachedReport(report.GetIdentifier()).Results {
|
||||
res := rule.Resources[0]
|
||||
ruleGauge.
|
||||
WithLabelValues(
|
||||
rule.Rule,
|
||||
rule.Policy,
|
||||
report.Name,
|
||||
res.Kind,
|
||||
res.Name,
|
||||
rule.Status,
|
||||
).
|
||||
Set(0)
|
||||
ruleGauge.DeleteLabelValues(
|
||||
rule.Rule,
|
||||
rule.Policy,
|
||||
report.Name,
|
||||
res.Kind,
|
||||
res.Name,
|
||||
rule.Status,
|
||||
)
|
||||
}
|
||||
|
||||
for _, rule := range report.Results {
|
||||
|
@ -92,24 +90,22 @@ func (m ClusterPolicyReportMetrics) GenerateMetrics() error {
|
|||
|
||||
m.cachedReport(report)
|
||||
case watch.Deleted:
|
||||
policyGauge.WithLabelValues(report.Name, "Pass").Set(0)
|
||||
policyGauge.WithLabelValues(report.Name, "Fail").Set(0)
|
||||
policyGauge.WithLabelValues(report.Name, "Warn").Set(0)
|
||||
policyGauge.WithLabelValues(report.Name, "Error").Set(0)
|
||||
policyGauge.WithLabelValues(report.Name, "Skip").Set(0)
|
||||
policyGauge.DeleteLabelValues(report.Name, "Pass")
|
||||
policyGauge.DeleteLabelValues(report.Name, "Fail")
|
||||
policyGauge.DeleteLabelValues(report.Name, "Warn")
|
||||
policyGauge.DeleteLabelValues(report.Name, "Error")
|
||||
policyGauge.DeleteLabelValues(report.Name, "Skip")
|
||||
|
||||
for _, rule := range report.Results {
|
||||
res := rule.Resources[0]
|
||||
ruleGauge.
|
||||
WithLabelValues(
|
||||
rule.Rule,
|
||||
rule.Policy,
|
||||
report.Name,
|
||||
res.Kind,
|
||||
res.Name,
|
||||
rule.Status,
|
||||
).
|
||||
Set(0)
|
||||
ruleGauge.DeleteLabelValues(
|
||||
rule.Rule,
|
||||
rule.Policy,
|
||||
report.Name,
|
||||
res.Kind,
|
||||
res.Name,
|
||||
rule.Status,
|
||||
)
|
||||
}
|
||||
|
||||
m.removeCachedReport(report.GetIdentifier())
|
||||
|
|
|
@ -74,17 +74,15 @@ func (m PolicyReportMetrics) GenerateMetrics() error {
|
|||
|
||||
for _, rule := range m.getCachedReport(report.GetIdentifier()).Results {
|
||||
res := rule.Resources[0]
|
||||
ruleGauge.
|
||||
WithLabelValues(
|
||||
report.Namespace,
|
||||
rule.Rule,
|
||||
rule.Policy,
|
||||
report.Name,
|
||||
res.Kind,
|
||||
res.Name,
|
||||
rule.Status,
|
||||
).
|
||||
Set(0)
|
||||
ruleGauge.DeleteLabelValues(
|
||||
report.Namespace,
|
||||
rule.Rule,
|
||||
rule.Policy,
|
||||
report.Name,
|
||||
res.Kind,
|
||||
res.Name,
|
||||
rule.Status,
|
||||
)
|
||||
}
|
||||
|
||||
for _, rule := range report.Results {
|
||||
|
@ -104,25 +102,24 @@ func (m PolicyReportMetrics) GenerateMetrics() error {
|
|||
|
||||
m.cachedReport(report)
|
||||
case watch.Deleted:
|
||||
policyGauge.WithLabelValues(report.Namespace, report.Name, "Pass").Set(0)
|
||||
policyGauge.WithLabelValues(report.Namespace, report.Name, "Fail").Set(0)
|
||||
policyGauge.WithLabelValues(report.Namespace, report.Name, "Warn").Set(0)
|
||||
policyGauge.WithLabelValues(report.Namespace, report.Name, "Error").Set(0)
|
||||
policyGauge.WithLabelValues(report.Namespace, report.Name, "Skip").Set(0)
|
||||
policyGauge.DeleteLabelValues(report.Namespace, report.Name, "Pass")
|
||||
policyGauge.DeleteLabelValues(report.Namespace, report.Name, "Fail")
|
||||
policyGauge.DeleteLabelValues(report.Namespace, report.Name, "Warn")
|
||||
policyGauge.DeleteLabelValues(report.Namespace, report.Name, "Error")
|
||||
policyGauge.DeleteLabelValues(report.Namespace, report.Name, "Skip")
|
||||
|
||||
for _, rule := range report.Results {
|
||||
res := rule.Resources[0]
|
||||
ruleGauge.
|
||||
WithLabelValues(
|
||||
report.Namespace,
|
||||
rule.Rule,
|
||||
rule.Policy,
|
||||
report.Name,
|
||||
res.Kind,
|
||||
res.Name,
|
||||
rule.Status,
|
||||
).
|
||||
Set(0)
|
||||
|
||||
ruleGauge.DeleteLabelValues(
|
||||
report.Namespace,
|
||||
rule.Rule,
|
||||
rule.Policy,
|
||||
report.Name,
|
||||
res.Kind,
|
||||
res.Name,
|
||||
rule.Status,
|
||||
)
|
||||
}
|
||||
|
||||
m.removeCachedReport(report.GetIdentifier())
|
||||
|
|
Loading…
Reference in a new issue