Skip to content

Commit

Permalink
remove labels from deleted reports and rules
Browse files Browse the repository at this point in the history
  • Loading branch information
Frank Jogeleit committed Feb 23, 2021
1 parent a9f9fcd commit 04c220d
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 56 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.16 as builder
FROM golang:1.16-buster as builder

WORKDIR /app
COPY . .
Expand Down
4 changes: 2 additions & 2 deletions charts/policy-reporter/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion charts/policy-reporter/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ metrics:
image:
repository: fjogeleit/policy-reporter
pullPolicy: IfNotPresent
tag: 0.5.0
tag: 0.5.1

imagePullSecrets: []

Expand Down
46 changes: 21 additions & 25 deletions pkg/metrics/cluster_policy_report.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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())
Expand Down
51 changes: 24 additions & 27 deletions pkg/metrics/policy_report.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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())
Expand Down

0 comments on commit 04c220d

Please sign in to comment.