diff --git a/CHANGELOG.md b/CHANGELOG.md index c8794304..e8018a1f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,19 @@ # Changelog +## 1.1.0 + +* Added PolicyReport Category to Metrics +* New (Cluster)PolicyReport filter for Grafana Dashboards + * Add __All__ Selection for Policy Filter + * Category Filter + * Severity Filter + * Kind Filter + * Namespacefilter (PolicyReports only) +* New (Cluster)PolicyReport filter for Policy Reporter UI + * Category Filter + * Severity Filter + * Kind Filter + ## 1.0.0 * Support Priority by Severity diff --git a/charts/policy-reporter/Chart.lock b/charts/policy-reporter/Chart.lock index ab6dac83..e8536cf6 100644 --- a/charts/policy-reporter/Chart.lock +++ b/charts/policy-reporter/Chart.lock @@ -1,9 +1,9 @@ dependencies: - name: monitoring repository: "" - version: 1.0.0 + version: 1.1.0 - name: ui repository: "" - version: 1.0.0 -digest: sha256:fb651a8155fa0d875e5cf260b34dc7bdd4b0331f93f58fa560139861d6988b02 -generated: "2021-04-02T11:55:33.612666+02:00" + version: 1.1.0 +digest: sha256:0240e537ce9603e3d2b8edf73ac16e547f7169edbeb7ba76b70cdaf3feab34d1 +generated: "2021-04-10T10:51:37.534358+02:00" diff --git a/charts/policy-reporter/Chart.yaml b/charts/policy-reporter/Chart.yaml index 5ee9ac9a..32d5cb5c 100644 --- a/charts/policy-reporter/Chart.yaml +++ b/charts/policy-reporter/Chart.yaml @@ -5,15 +5,15 @@ description: | It creates Prometheus Metrics and can send rule validation events to different targets like Loki, Elasticsearch, Slack or Discord type: application -version: 1.0.0 -appVersion: 1.0.0 +version: 1.1.0 +appVersion: 1.1.0 dependencies: - name: monitoring condition: monitoring.enabled repository: "" - version: "1.0.0" + version: "1.1.0" - name: ui condition: ui.enabled repository: "" - version: "1.0.0" + version: "1.1.0" diff --git a/charts/policy-reporter/charts/monitoring/Chart.yaml b/charts/policy-reporter/charts/monitoring/Chart.yaml index 9b6179bd..e179b2d8 100644 --- a/charts/policy-reporter/charts/monitoring/Chart.yaml +++ b/charts/policy-reporter/charts/monitoring/Chart.yaml @@ -3,5 +3,5 @@ name: monitoring description: Policy Reporter Monitoring with predefined ServiceMonitor and Grafana Dashboards type: application -version: 1.0.0 +version: 1.1.0 appVersion: 0.0.0 diff --git a/charts/policy-reporter/charts/monitoring/templates/clusterpolicy-details.dashboard.yaml b/charts/policy-reporter/charts/monitoring/templates/clusterpolicy-details.dashboard.yaml index f3ef86f8..182553e4 100644 --- a/charts/policy-reporter/charts/monitoring/templates/clusterpolicy-details.dashboard.yaml +++ b/charts/policy-reporter/charts/monitoring/templates/clusterpolicy-details.dashboard.yaml @@ -112,7 +112,7 @@ data: "pluginVersion": "7.1.5", "targets": [ { - "expr": "sum(cluster_policy_report_result{policy=~\"$policy\", status=\"pass\"})", + "expr": "sum(cluster_policy_report_result{policy=~\"$policy\", category=~\"$category\", severity=~\"$severity\", kind=~\"$kind\", status=\"pass\"})", "instant": true, "interval": "", "legendFormat": "", @@ -168,7 +168,7 @@ data: "pluginVersion": "7.1.5", "targets": [ { - "expr": "sum(policy_report_result{policy=~\"$policy\", status=\"warn\"})", + "expr": "sum(policy_report_result{policy=~\"$policy\", category=~\"$category\", severity=~\"$severity\", kind=~\"$kind\", status=\"warn\"})", "instant": true, "interval": "", "legendFormat": "", @@ -224,7 +224,7 @@ data: "pluginVersion": "7.1.5", "targets": [ { - "expr": "sum(cluster_policy_report_result{policy=~\"$policy\", status=\"fail\"})", + "expr": "sum(cluster_policy_report_result{policy=~\"$policy\", category=~\"$category\", severity=~\"$severity\", kind=~\"$kind\", status=\"fail\"})", "instant": true, "interval": "", "legendFormat": "", @@ -280,7 +280,7 @@ data: "pluginVersion": "7.1.5", "targets": [ { - "expr": "sum(cluster_policy_report_result{policy=~\"$policy\", status=\"error\"})", + "expr": "sum(cluster_policy_report_result{policy=~\"$policy\", category=~\"$category\", severity=~\"$severity\", kind=~\"$kind\", status=\"error\"})", "instant": true, "interval": "", "legendFormat": "", @@ -341,7 +341,7 @@ data: "steppedLine": false, "targets": [ { - "expr": "sum(cluster_policy_report_result{policy=~\"$policy\"} > 0) by (status)", + "expr": "sum(cluster_policy_report_result{policy=~\"$policy\", category=~\"$category\", severity=~\"$severity\", kind=~\"$kind\"} > 0) by (status)", "interval": "", "legendFormat": "{{`{{ status }}`}}", "refId": "A" @@ -428,7 +428,7 @@ data: "pluginVersion": "7.1.5", "targets": [ { - "expr": "sum(cluster_policy_report_result{policy=~\"$policy\", status=\"pass\"}) by (policy,rule,kind,name,status)", + "expr": "sum(cluster_policy_report_result{policy=~\"$policy\", category=~\"$category\", severity=~\"$severity\", kind=~\"$kind\", status=\"pass\"}) by (policy,rule,kind,name,status,severity,category)", "format": "table", "instant": true, "interval": "", @@ -448,7 +448,17 @@ data: "Value": true, "status": false }, - "indexByName": {}, + "indexByName": { + "Time": 0, + "Value": 8, + "category": 1, + "kind": 3, + "name": 4, + "policy": 5, + "rule": 6, + "severity": 2, + "status": 7 + }, "renameByName": { "exported_namespace": "namespace" } @@ -495,7 +505,7 @@ data: "pluginVersion": "7.1.5", "targets": [ { - "expr": "sum(cluster_policy_report_result{policy=~\"$policy\", status=\"fail\"}) by (policy,rule,kind,name,status)", + "expr": "sum(cluster_policy_report_result{policy=~\"$policy\", category=~\"$category\", severity=~\"$severity\", kind=~\"$kind\", status=\"fail\"}) by (policy,rule,kind,name,status,severity,category)", "format": "table", "instant": true, "interval": "", @@ -515,7 +525,17 @@ data: "Value": true, "status": false }, - "indexByName": {}, + "indexByName": { + "Time": 0, + "Value": 8, + "category": 1, + "kind": 3, + "name": 4, + "policy": 5, + "rule": 6, + "severity": 2, + "status": 7 + }, "renameByName": { "exported_namespace": "namespace" } @@ -559,7 +579,7 @@ data: "pluginVersion": "7.1.5", "targets": [ { - "expr": "sum(cluster_policy_report_result{policy=~\"$policy\", status=\"warn\"}) by (policy,rule,kind,name,status)", + "expr": "sum(cluster_policy_report_result{policy=~\"$policy\", category=~\"$category\", severity=~\"$severity\", kind=~\"$kind\", status=\"warn\"}) by (policy,rule,kind,name,status,severity,category)", "format": "table", "instant": true, "interval": "", @@ -579,7 +599,17 @@ data: "Value": true, "status": false }, - "indexByName": {}, + "indexByName": { + "Time": 0, + "Value": 8, + "category": 1, + "kind": 3, + "name": 4, + "policy": 5, + "rule": 6, + "severity": 2, + "status": 7 + }, "renameByName": { "exported_namespace": "namespace" } @@ -623,7 +653,7 @@ data: "pluginVersion": "7.1.5", "targets": [ { - "expr": "sum(cluster_policy_report_result{policy=~\"$policy\", status=\"error\"}) by (policy,rule,kind,name,status)", + "expr": "sum(cluster_policy_report_result{policy=~\"$policy\", category=~\"$category\", severity=~\"$severity\", kind=~\"$kind\", status=\"error\"}) by (policy,rule,kind,name,status,severity,category)", "format": "table", "instant": true, "interval": "", @@ -643,7 +673,17 @@ data: "Value": true, "status": false }, - "indexByName": {}, + "indexByName": { + "Time": 0, + "Value": 8, + "category": 1, + "kind": 3, + "name": 4, + "policy": 5, + "rule": 6, + "severity": 2, + "status": 7 + }, "renameByName": { "exported_namespace": "namespace" } @@ -662,11 +702,11 @@ data: "templating": { "list": [ { - "allValue": null, + "allValue": ".*", "current": {}, "definition": "label_values(cluster_policy_report_result, policy)", "hide": 0, - "includeAll": false, + "includeAll": true, "label": "Policy", "multi": true, "name": "policy", @@ -681,6 +721,66 @@ data: "tagsQuery": "", "type": "query", "useTags": false + }, + { + "allValue": ".*", + "definition": "label_values(cluster_policy_report_result, category)", + "hide": 0, + "includeAll": true, + "label": "Category", + "multi": true, + "name": "category", + "options": [], + "query": "label_values(cluster_policy_report_result, category)", + "refresh": 2, + "regex": "", + "skipUrlSync": false, + "sort": 5, + "tagValuesQuery": "", + "tags": [], + "tagsQuery": "", + "type": "query", + "useTags": false + }, + { + "allValue": ".*", + "definition": "label_values(cluster_policy_report_result, severity)", + "hide": 0, + "includeAll": true, + "label": "Severity", + "multi": true, + "name": "severity", + "options": [], + "query": "label_values(cluster_policy_report_result, severity)", + "refresh": 2, + "regex": "", + "skipUrlSync": false, + "sort": 5, + "tagValuesQuery": "", + "tags": [], + "tagsQuery": "", + "type": "query", + "useTags": false + }, + { + "allValue": ".*", + "definition": "label_values(cluster_policy_report_result, kind)", + "hide": 0, + "includeAll": true, + "label": "Kind", + "multi": true, + "name": "kind", + "options": [], + "query": "label_values(cluster_policy_report_result, kind)", + "refresh": 2, + "regex": "", + "skipUrlSync": false, + "sort": 5, + "tagValuesQuery": "", + "tags": [], + "tagsQuery": "", + "type": "query", + "useTags": false } ] }, diff --git a/charts/policy-reporter/charts/monitoring/templates/policy-details.dashboard.yaml b/charts/policy-reporter/charts/monitoring/templates/policy-details.dashboard.yaml index 42c0bd47..54abf207 100644 --- a/charts/policy-reporter/charts/monitoring/templates/policy-details.dashboard.yaml +++ b/charts/policy-reporter/charts/monitoring/templates/policy-details.dashboard.yaml @@ -110,7 +110,7 @@ data: "pluginVersion": "7.1.5", "targets": [ { - "expr": "sum(policy_report_result{policy=~\"$policy\", status=\"pass\"} > 0) by (exported_namespace)", + "expr": "sum(policy_report_result{policy=~\"$policy\", category=~\"$category\", severity=~\"$severity\", kind=~\"$kind\", exported_namespace=~\"$namespace\", status=\"pass\"} > 0) by (exported_namespace)", "instant": true, "interval": "", "legendFormat": "{{`{{ exported_namespace }}`}}", @@ -164,7 +164,7 @@ data: "pluginVersion": "7.1.5", "targets": [ { - "expr": "sum(policy_report_result{policy=~\"$policy\", status=\"fail\"} > 0) by (exported_namespace)", + "expr": "sum(policy_report_result{policy=~\"$policy\", category=~\"$category\", severity=~\"$severity\", kind=~\"$kind\", exported_namespace=~\"$namespace\", status=\"fail\"} > 0) by (exported_namespace)", "instant": true, "interval": "", "legendFormat": "{{`{{ exported_namespace }}`}}", @@ -219,7 +219,7 @@ data: "pluginVersion": "7.1.5", "targets": [ { - "expr": "sum(policy_report_result{policy=~\"$policy\", status=\"warn\"} > 0) by (exported_namespace)", + "expr": "sum(policy_report_result{policy=~\"$policy\", category=~\"$category\", severity=~\"$severity\", kind=~\"$kind\", exported_namespace=~\"$namespace\", status=\"warn\"} > 0) by (exported_namespace)", "instant": true, "interval": "", "legendFormat": "{{`{{ exported_namespace }}`}}", @@ -273,7 +273,7 @@ data: "pluginVersion": "7.1.5", "targets": [ { - "expr": "sum(policy_report_result{policy=~\"$policy\", status=\"error\"} > 0) by (exported_namespace)", + "expr": "sum(policy_report_result{policy=~\"$policy\", category=~\"$category\", severity=~\"$severity\", kind=~\"$kind\", exported_namespace=~\"$namespace\", status=\"error\"} > 0) by (exported_namespace)", "instant": true, "interval": "", "legendFormat": "{{`{{ exported_namespace }}`}}", @@ -335,7 +335,7 @@ data: "steppedLine": false, "targets": [ { - "expr": "sum(policy_report_result{policy=~\"$policy\"} > 0) by (status, exported_namespace)", + "expr": "sum(policy_report_result{policy=~\"$policy\", category=~\"$category\", severity=~\"$severity\", kind=~\"$kind\", exported_namespace=~\"$namespace\"} > 0) by (status, exported_namespace)", "interval": "", "legendFormat": "{{`{{ exported_namespace }}`}} {{`{{ status }}`}}", "refId": "A" @@ -422,7 +422,7 @@ data: "pluginVersion": "7.1.5", "targets": [ { - "expr": "sum(policy_report_result{policy=~\"$policy\", status=\"pass\"}) by (exported_namespace,policy,rule,kind,name,status)", + "expr": "sum(policy_report_result{policy=~\"$policy\", category=~\"$category\", severity=~\"$severity\", kind=~\"$kind\", exported_namespace=~\"$namespace\", status=\"pass\"}) by (exported_namespace,category,policy,rule,kind,name,severity,status)", "format": "table", "instant": true, "interval": "", @@ -442,7 +442,18 @@ data: "Value": true, "status": false }, - "indexByName": {}, + "indexByName": { + "Time": 0, + "Value": 9, + "category": 1, + "exported_namespace": 3, + "kind": 4, + "name": 5, + "policy": 6, + "rule": 7, + "severity": 2, + "status": 8 + }, "renameByName": { "exported_namespace": "namespace" } @@ -489,7 +500,7 @@ data: "pluginVersion": "7.1.5", "targets": [ { - "expr": "sum(policy_report_result{policy=~\"$policy\", status=\"fail\"}) by (exported_namespace,policy,rule,kind,name,status)", + "expr": "sum(policy_report_result{policy=~\"$policy\", category=~\"$category\", severity=~\"$severity\", kind=~\"$kind\", exported_namespace=~\"$namespace\", status=\"fail\"}) by (exported_namespace,category,policy,rule,kind,name,severity,status)", "format": "table", "instant": true, "interval": "", @@ -509,7 +520,18 @@ data: "Value": true, "status": false }, - "indexByName": {}, + "indexByName": { + "Time": 0, + "Value": 9, + "category": 1, + "exported_namespace": 3, + "kind": 4, + "name": 5, + "policy": 6, + "rule": 7, + "severity": 2, + "status": 8 + }, "renameByName": { "exported_namespace": "namespace" } @@ -553,7 +575,7 @@ data: "pluginVersion": "7.1.5", "targets": [ { - "expr": "sum(policy_report_result{policy=~\"$policy\", status=\"warn\"}) by (exported_namespace,policy,rule,kind,name,status)", + "expr": "sum(policy_report_result{policy=~\"$policy\", category=~\"$category\", severity=~\"$severity\", kind=~\"$kind\", exported_namespace=~\"$namespace\", status=\"warn\"}) by (exported_namespace,category,policy,rule,kind,name,severity,status)", "format": "table", "instant": true, "interval": "", @@ -573,7 +595,18 @@ data: "Value": true, "status": false }, - "indexByName": {}, + "indexByName": { + "Time": 0, + "Value": 9, + "category": 1, + "exported_namespace": 3, + "kind": 4, + "name": 5, + "policy": 6, + "rule": 7, + "severity": 2, + "status": 8 + }, "renameByName": { "exported_namespace": "namespace" } @@ -617,7 +650,7 @@ data: "pluginVersion": "7.1.5", "targets": [ { - "expr": "sum(policy_report_result{policy=~\"$policy\", status=\"error\"}) by (exported_namespace,policy,rule,kind,name,status)", + "expr": "sum(policy_report_result{policy=~\"$policy\", category=~\"$category\", severity=~\"$severity\", kind=~\"$kind\", exported_namespace=~\"$namespace\", status=\"error\"}) by (exported_namespace,category,policy,rule,kind,name,severity,status)", "format": "table", "instant": true, "interval": "", @@ -637,7 +670,18 @@ data: "Value": true, "status": false }, - "indexByName": {}, + "indexByName": { + "Time": 0, + "Value": 9, + "category": 1, + "exported_namespace": 3, + "kind": 4, + "name": 5, + "policy": 6, + "rule": 7, + "severity": 2, + "status": 8 + }, "renameByName": { "exported_namespace": "namespace" } @@ -656,10 +700,10 @@ data: "templating": { "list": [ { - "allValue": null, + "allValue": ".*", "definition": "label_values(policy_report_result, policy)", "hide": 0, - "includeAll": false, + "includeAll": true, "label": "Policy", "multi": true, "name": "policy", @@ -674,6 +718,86 @@ data: "tagsQuery": "", "type": "query", "useTags": false + }, + { + "allValue": ".*", + "definition": "label_values(policy_report_result, category)", + "hide": 0, + "includeAll": true, + "label": "Category", + "multi": true, + "name": "category", + "options": [], + "query": "label_values(policy_report_result, category)", + "refresh": 2, + "regex": "", + "skipUrlSync": false, + "sort": 5, + "tagValuesQuery": "", + "tags": [], + "tagsQuery": "", + "type": "query", + "useTags": false + }, + { + "allValue": ".*", + "definition": "label_values(policy_report_result, severity)", + "hide": 0, + "includeAll": true, + "label": "Severity", + "multi": true, + "name": "severity", + "options": [], + "query": "label_values(policy_report_result, severity)", + "refresh": 2, + "regex": "", + "skipUrlSync": false, + "sort": 5, + "tagValuesQuery": "", + "tags": [], + "tagsQuery": "", + "type": "query", + "useTags": false + }, + { + "allValue": ".*", + "definition": "label_values(policy_report_result, exported_namespace)", + "hide": 0, + "includeAll": true, + "label": "Namespace", + "multi": true, + "name": "namespace", + "options": [], + "query": "label_values(policy_report_result, exported_namespace)", + "refresh": 2, + "regex": "", + "skipUrlSync": false, + "sort": 5, + "tagValuesQuery": "", + "tags": [], + "tagsQuery": "", + "type": "query", + "useTags": false + }, + { + "allValue": ".*", + "definition": "label_values(policy_report_result, kind)", + "hide": 0, + "includeAll": true, + "label": "Kind", + "multi": true, + "name": "kind", + "options": [], + "query": "label_values(policy_report_result, kind)", + "refresh": 2, + "regex": "", + "skipUrlSync": false, + "sort": 5, + "tagValuesQuery": "", + "tags": [], + "tagsQuery": "", + "type": "query", + "useTags": false } ] }, diff --git a/charts/policy-reporter/charts/monitoring/values.yaml b/charts/policy-reporter/charts/monitoring/values.yaml index ace104e4..e79a4671 100644 --- a/charts/policy-reporter/charts/monitoring/values.yaml +++ b/charts/policy-reporter/charts/monitoring/values.yaml @@ -6,7 +6,7 @@ serviceMonitor: policyReportDetails: firstStatusRow: - height: 6 + height: 8 secondStatusRow: enabled: true height: 2 diff --git a/charts/policy-reporter/charts/ui/Chart.yaml b/charts/policy-reporter/charts/ui/Chart.yaml index d2cb8b72..d7904d1f 100644 --- a/charts/policy-reporter/charts/ui/Chart.yaml +++ b/charts/policy-reporter/charts/ui/Chart.yaml @@ -3,5 +3,5 @@ name: ui description: Policy Reporter UI type: application -version: 1.0.0 -appVersion: 0.6.0 +version: 1.1.0 +appVersion: 0.7.0 diff --git a/charts/policy-reporter/charts/ui/values.yaml b/charts/policy-reporter/charts/ui/values.yaml index 94c87079..60d98138 100644 --- a/charts/policy-reporter/charts/ui/values.yaml +++ b/charts/policy-reporter/charts/ui/values.yaml @@ -7,7 +7,7 @@ log: image: repository: fjogeleit/policy-reporter-ui pullPolicy: IfNotPresent - tag: 0.6.0 + tag: 0.7.0 imagePullSecrets: [] diff --git a/charts/policy-reporter/values.yaml b/charts/policy-reporter/values.yaml index 2bcaa812..b083a51d 100644 --- a/charts/policy-reporter/values.yaml +++ b/charts/policy-reporter/values.yaml @@ -1,7 +1,7 @@ image: repository: fjogeleit/policy-reporter pullPolicy: IfNotPresent - tag: 1.0.1 + tag: 1.1.0 imagePullSecrets: [] diff --git a/docs/images/cluster-policy-details.png b/docs/images/cluster-policy-details.png index 21a68329..5bf498b2 100644 Binary files a/docs/images/cluster-policy-details.png and b/docs/images/cluster-policy-details.png differ diff --git a/docs/images/policy-details.png b/docs/images/policy-details.png index d0c9e6a8..a08f84b9 100644 Binary files a/docs/images/policy-details.png and b/docs/images/policy-details.png differ diff --git a/pkg/metrics/cluster_policy_report.go b/pkg/metrics/cluster_policy_report.go index 593841df..cb5c6c13 100644 --- a/pkg/metrics/cluster_policy_report.go +++ b/pkg/metrics/cluster_policy_report.go @@ -17,7 +17,7 @@ func CreateClusterPolicyReportMetricsCallback() report.ClusterPolicyReportCallba ruleGauge := promauto.NewGaugeVec(prometheus.GaugeOpts{ Name: "cluster_policy_report_result", Help: "List of all ClusterPolicyReport Results", - }, []string{"rule", "policy", "report", "kind", "name", "status", "severity"}) + }, []string{"rule", "policy", "report", "kind", "name", "status", "severity", "category"}) prometheus.Register(policyGauge) prometheus.Register(ruleGauge) @@ -37,6 +37,7 @@ func CreateClusterPolicyReportMetricsCallback() report.ClusterPolicyReportCallba res.Name, rule.Status, rule.Severity, + rule.Category, ).Set(1) } case watch.Modified: @@ -52,6 +53,7 @@ func CreateClusterPolicyReportMetricsCallback() report.ClusterPolicyReportCallba res.Name, rule.Status, rule.Severity, + rule.Category, ) } @@ -66,6 +68,7 @@ func CreateClusterPolicyReportMetricsCallback() report.ClusterPolicyReportCallba res.Name, rule.Status, rule.Severity, + rule.Category, ). Set(1) } @@ -86,6 +89,7 @@ func CreateClusterPolicyReportMetricsCallback() report.ClusterPolicyReportCallba res.Name, rule.Status, rule.Severity, + rule.Category, ) } } diff --git a/pkg/metrics/cluster_policy_report_test.go b/pkg/metrics/cluster_policy_report_test.go index c59ae587..9c53e130 100644 --- a/pkg/metrics/cluster_policy_report_test.go +++ b/pkg/metrics/cluster_policy_report_test.go @@ -214,50 +214,56 @@ func testClusterSummaryMetricLabels( } func testClusterResultMetricLabels(metric *io_prometheus_client.Metric, result report.Result) error { - if name := *metric.Label[0].Name; name != "kind" { + if name := *metric.Label[0].Name; name != "category" { return fmt.Errorf("Unexpected Name Label: %s", name) } - if value := *metric.Label[0].Value; value != result.Resources[0].Kind { + if value := *metric.Label[0].Value; value != result.Category { + return fmt.Errorf("Unexpected Category Label Value: %s", value) + } + + if name := *metric.Label[1].Name; name != "kind" { + return fmt.Errorf("Unexpected Name Label: %s", name) + } + if value := *metric.Label[1].Value; value != result.Resources[0].Kind { return fmt.Errorf("Unexpected Kind Label Value: %s", value) } - if name := *metric.Label[1].Name; name != "name" { + if name := *metric.Label[2].Name; name != "name" { return fmt.Errorf("Unexpected Name Label: %s", name) } - if value := *metric.Label[1].Value; value != result.Resources[0].Name { + if value := *metric.Label[2].Value; value != result.Resources[0].Name { return fmt.Errorf("Unexpected Name Label Value: %s", value) } - if name := *metric.Label[2].Name; name != "policy" { + if name := *metric.Label[3].Name; name != "policy" { return fmt.Errorf("Unexpected Name Label: %s", name) } - - if value := *metric.Label[2].Value; value != result.Policy { + if value := *metric.Label[3].Value; value != result.Policy { return fmt.Errorf("Unexpected Policy Label Value: %s", value) } - if name := *metric.Label[3].Name; name != "report" { + if name := *metric.Label[4].Name; name != "report" { return fmt.Errorf("Unexpected Name Label: %s", name) } - if name := *metric.Label[4].Name; name != "rule" { + if name := *metric.Label[5].Name; name != "rule" { return fmt.Errorf("Unexpected Name Label: %s", name) } - if value := *metric.Label[4].Value; value != result.Rule { + if value := *metric.Label[5].Value; value != result.Rule { return fmt.Errorf("Unexpected Rule Label Value: %s", value) } - if name := *metric.Label[5].Name; name != "severity" { + if name := *metric.Label[6].Name; name != "severity" { return fmt.Errorf("Unexpected Name Label: %s", name) } - if value := *metric.Label[5].Value; value != result.Severity { + if value := *metric.Label[6].Value; value != result.Severity { return fmt.Errorf("Unexpected Severity Label Value: %s", value) } - if name := *metric.Label[6].Name; name != "status" { + if name := *metric.Label[7].Name; name != "status" { return fmt.Errorf("Unexpected Name Label: %s", name) } - if value := *metric.Label[6].Value; value != result.Status { + if value := *metric.Label[7].Value; value != result.Status { return fmt.Errorf("Unexpected Status Label Value: %s", value) } diff --git a/pkg/metrics/policy_report.go b/pkg/metrics/policy_report.go index eb84a52c..71a51d6d 100644 --- a/pkg/metrics/policy_report.go +++ b/pkg/metrics/policy_report.go @@ -17,7 +17,7 @@ func CreatePolicyReportMetricsCallback() report.PolicyReportCallback { ruleGauge := promauto.NewGaugeVec(prometheus.GaugeOpts{ Name: "policy_report_result", Help: "List of all PolicyReport Results", - }, []string{"namespace", "rule", "policy", "report", "kind", "name", "status", "severity"}) + }, []string{"namespace", "rule", "policy", "report", "kind", "name", "status", "severity", "category"}) prometheus.Register(policyGauge) prometheus.Register(ruleGauge) @@ -39,6 +39,7 @@ func CreatePolicyReportMetricsCallback() report.PolicyReportCallback { res.Name, rule.Status, rule.Severity, + rule.Category, ). Set(1) } @@ -56,6 +57,7 @@ func CreatePolicyReportMetricsCallback() report.PolicyReportCallback { res.Name, rule.Status, rule.Severity, + rule.Category, ) } @@ -71,6 +73,7 @@ func CreatePolicyReportMetricsCallback() report.PolicyReportCallback { res.Name, rule.Status, rule.Severity, + rule.Category, ). Set(1) } @@ -93,6 +96,7 @@ func CreatePolicyReportMetricsCallback() report.PolicyReportCallback { res.Name, rule.Status, rule.Severity, + rule.Category, ) } } diff --git a/pkg/metrics/policy_report_test.go b/pkg/metrics/policy_report_test.go index 33f86ce2..a27be9b1 100644 --- a/pkg/metrics/policy_report_test.go +++ b/pkg/metrics/policy_report_test.go @@ -223,57 +223,63 @@ func testSummaryMetricLabels( } func testResultMetricLabels(metric *io_prometheus_client.Metric, result report.Result) error { - if name := *metric.Label[0].Name; name != "kind" { + if name := *metric.Label[0].Name; name != "category" { return fmt.Errorf("Unexpected Name Label: %s", name) } - if value := *metric.Label[0].Value; value != result.Resources[0].Kind { + if value := *metric.Label[0].Value; value != result.Category { + return fmt.Errorf("Unexpected Category Label Value: %s", value) + } + + if name := *metric.Label[1].Name; name != "kind" { + return fmt.Errorf("Unexpected Name Label: %s", name) + } + if value := *metric.Label[1].Value; value != result.Resources[0].Kind { return fmt.Errorf("Unexpected Kind Label Value: %s", value) } - if name := *metric.Label[1].Name; name != "name" { + if name := *metric.Label[2].Name; name != "name" { return fmt.Errorf("Unexpected Name Label: %s", name) } - if value := *metric.Label[1].Value; value != result.Resources[0].Name { + if value := *metric.Label[2].Value; value != result.Resources[0].Name { return fmt.Errorf("Unexpected Name Label Value: %s", value) } - if name := *metric.Label[2].Name; name != "namespace" { + if name := *metric.Label[3].Name; name != "namespace" { return fmt.Errorf("Unexpected Name Label: %s", name) } - if value := *metric.Label[2].Value; value != result.Resources[0].Namespace { + if value := *metric.Label[3].Value; value != result.Resources[0].Namespace { return fmt.Errorf("Unexpected Namespace Label Value: %s", value) } - if name := *metric.Label[3].Name; name != "policy" { + if name := *metric.Label[4].Name; name != "policy" { return fmt.Errorf("Unexpected Name Label: %s", name) } - - if value := *metric.Label[3].Value; value != result.Policy { + if value := *metric.Label[4].Value; value != result.Policy { return fmt.Errorf("Unexpected Policy Label Value: %s", value) } - if name := *metric.Label[4].Name; name != "report" { + if name := *metric.Label[5].Name; name != "report" { return fmt.Errorf("Unexpected Name Label: %s", name) } - if name := *metric.Label[5].Name; name != "rule" { + if name := *metric.Label[6].Name; name != "rule" { return fmt.Errorf("Unexpected Name Label: %s", name) } - if value := *metric.Label[5].Value; value != result.Rule { + if value := *metric.Label[6].Value; value != result.Rule { return fmt.Errorf("Unexpected Rule Label Value: %s", value) } - if name := *metric.Label[6].Name; name != "severity" { + if name := *metric.Label[7].Name; name != "severity" { return fmt.Errorf("Unexpected Name Label: %s", name) } - if value := *metric.Label[6].Value; value != result.Severity { + if value := *metric.Label[7].Value; value != result.Severity { return fmt.Errorf("Unexpected Severity Label Value: %s", value) } - if name := *metric.Label[7].Name; name != "status" { + if name := *metric.Label[8].Name; name != "status" { return fmt.Errorf("Unexpected Name Label: %s", name) } - if value := *metric.Label[7].Value; value != result.Status { + if value := *metric.Label[8].Value; value != result.Status { return fmt.Errorf("Unexpected Status Label Value: %s", value) }