1
0
Fork 0
mirror of https://github.com/kyverno/policy-reporter.git synced 2024-12-14 11:57:32 +00:00

Monitoring improvements (#23)

* 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
This commit is contained in:
Frank Jogeleit 2021-04-10 11:16:46 +02:00 committed by GitHub
parent d2cc2af7d6
commit 15ad03d552
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 334 additions and 76 deletions

View file

@ -1,5 +1,19 @@
# Changelog # 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 ## 1.0.0
* Support Priority by Severity * Support Priority by Severity

View file

@ -1,9 +1,9 @@
dependencies: dependencies:
- name: monitoring - name: monitoring
repository: "" repository: ""
version: 1.0.0 version: 1.1.0
- name: ui - name: ui
repository: "" repository: ""
version: 1.0.0 version: 1.1.0
digest: sha256:fb651a8155fa0d875e5cf260b34dc7bdd4b0331f93f58fa560139861d6988b02 digest: sha256:0240e537ce9603e3d2b8edf73ac16e547f7169edbeb7ba76b70cdaf3feab34d1
generated: "2021-04-02T11:55:33.612666+02:00" generated: "2021-04-10T10:51:37.534358+02:00"

View file

@ -5,15 +5,15 @@ description: |
It creates Prometheus Metrics and can send rule validation events to different targets like Loki, Elasticsearch, Slack or Discord It creates Prometheus Metrics and can send rule validation events to different targets like Loki, Elasticsearch, Slack or Discord
type: application type: application
version: 1.0.0 version: 1.1.0
appVersion: 1.0.0 appVersion: 1.1.0
dependencies: dependencies:
- name: monitoring - name: monitoring
condition: monitoring.enabled condition: monitoring.enabled
repository: "" repository: ""
version: "1.0.0" version: "1.1.0"
- name: ui - name: ui
condition: ui.enabled condition: ui.enabled
repository: "" repository: ""
version: "1.0.0" version: "1.1.0"

View file

@ -3,5 +3,5 @@ name: monitoring
description: Policy Reporter Monitoring with predefined ServiceMonitor and Grafana Dashboards description: Policy Reporter Monitoring with predefined ServiceMonitor and Grafana Dashboards
type: application type: application
version: 1.0.0 version: 1.1.0
appVersion: 0.0.0 appVersion: 0.0.0

View file

@ -112,7 +112,7 @@ data:
"pluginVersion": "7.1.5", "pluginVersion": "7.1.5",
"targets": [ "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, "instant": true,
"interval": "", "interval": "",
"legendFormat": "", "legendFormat": "",
@ -168,7 +168,7 @@ data:
"pluginVersion": "7.1.5", "pluginVersion": "7.1.5",
"targets": [ "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, "instant": true,
"interval": "", "interval": "",
"legendFormat": "", "legendFormat": "",
@ -224,7 +224,7 @@ data:
"pluginVersion": "7.1.5", "pluginVersion": "7.1.5",
"targets": [ "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, "instant": true,
"interval": "", "interval": "",
"legendFormat": "", "legendFormat": "",
@ -280,7 +280,7 @@ data:
"pluginVersion": "7.1.5", "pluginVersion": "7.1.5",
"targets": [ "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, "instant": true,
"interval": "", "interval": "",
"legendFormat": "", "legendFormat": "",
@ -341,7 +341,7 @@ data:
"steppedLine": false, "steppedLine": false,
"targets": [ "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": "", "interval": "",
"legendFormat": "{{`{{ status }}`}}", "legendFormat": "{{`{{ status }}`}}",
"refId": "A" "refId": "A"
@ -428,7 +428,7 @@ data:
"pluginVersion": "7.1.5", "pluginVersion": "7.1.5",
"targets": [ "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", "format": "table",
"instant": true, "instant": true,
"interval": "", "interval": "",
@ -448,7 +448,17 @@ data:
"Value": true, "Value": true,
"status": false "status": false
}, },
"indexByName": {}, "indexByName": {
"Time": 0,
"Value": 8,
"category": 1,
"kind": 3,
"name": 4,
"policy": 5,
"rule": 6,
"severity": 2,
"status": 7
},
"renameByName": { "renameByName": {
"exported_namespace": "namespace" "exported_namespace": "namespace"
} }
@ -495,7 +505,7 @@ data:
"pluginVersion": "7.1.5", "pluginVersion": "7.1.5",
"targets": [ "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", "format": "table",
"instant": true, "instant": true,
"interval": "", "interval": "",
@ -515,7 +525,17 @@ data:
"Value": true, "Value": true,
"status": false "status": false
}, },
"indexByName": {}, "indexByName": {
"Time": 0,
"Value": 8,
"category": 1,
"kind": 3,
"name": 4,
"policy": 5,
"rule": 6,
"severity": 2,
"status": 7
},
"renameByName": { "renameByName": {
"exported_namespace": "namespace" "exported_namespace": "namespace"
} }
@ -559,7 +579,7 @@ data:
"pluginVersion": "7.1.5", "pluginVersion": "7.1.5",
"targets": [ "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", "format": "table",
"instant": true, "instant": true,
"interval": "", "interval": "",
@ -579,7 +599,17 @@ data:
"Value": true, "Value": true,
"status": false "status": false
}, },
"indexByName": {}, "indexByName": {
"Time": 0,
"Value": 8,
"category": 1,
"kind": 3,
"name": 4,
"policy": 5,
"rule": 6,
"severity": 2,
"status": 7
},
"renameByName": { "renameByName": {
"exported_namespace": "namespace" "exported_namespace": "namespace"
} }
@ -623,7 +653,7 @@ data:
"pluginVersion": "7.1.5", "pluginVersion": "7.1.5",
"targets": [ "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", "format": "table",
"instant": true, "instant": true,
"interval": "", "interval": "",
@ -643,7 +673,17 @@ data:
"Value": true, "Value": true,
"status": false "status": false
}, },
"indexByName": {}, "indexByName": {
"Time": 0,
"Value": 8,
"category": 1,
"kind": 3,
"name": 4,
"policy": 5,
"rule": 6,
"severity": 2,
"status": 7
},
"renameByName": { "renameByName": {
"exported_namespace": "namespace" "exported_namespace": "namespace"
} }
@ -662,11 +702,11 @@ data:
"templating": { "templating": {
"list": [ "list": [
{ {
"allValue": null, "allValue": ".*",
"current": {}, "current": {},
"definition": "label_values(cluster_policy_report_result, policy)", "definition": "label_values(cluster_policy_report_result, policy)",
"hide": 0, "hide": 0,
"includeAll": false, "includeAll": true,
"label": "Policy", "label": "Policy",
"multi": true, "multi": true,
"name": "policy", "name": "policy",
@ -681,6 +721,66 @@ data:
"tagsQuery": "", "tagsQuery": "",
"type": "query", "type": "query",
"useTags": false "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
} }
] ]
}, },

View file

@ -110,7 +110,7 @@ data:
"pluginVersion": "7.1.5", "pluginVersion": "7.1.5",
"targets": [ "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, "instant": true,
"interval": "", "interval": "",
"legendFormat": "{{`{{ exported_namespace }}`}}", "legendFormat": "{{`{{ exported_namespace }}`}}",
@ -164,7 +164,7 @@ data:
"pluginVersion": "7.1.5", "pluginVersion": "7.1.5",
"targets": [ "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, "instant": true,
"interval": "", "interval": "",
"legendFormat": "{{`{{ exported_namespace }}`}}", "legendFormat": "{{`{{ exported_namespace }}`}}",
@ -219,7 +219,7 @@ data:
"pluginVersion": "7.1.5", "pluginVersion": "7.1.5",
"targets": [ "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, "instant": true,
"interval": "", "interval": "",
"legendFormat": "{{`{{ exported_namespace }}`}}", "legendFormat": "{{`{{ exported_namespace }}`}}",
@ -273,7 +273,7 @@ data:
"pluginVersion": "7.1.5", "pluginVersion": "7.1.5",
"targets": [ "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, "instant": true,
"interval": "", "interval": "",
"legendFormat": "{{`{{ exported_namespace }}`}}", "legendFormat": "{{`{{ exported_namespace }}`}}",
@ -335,7 +335,7 @@ data:
"steppedLine": false, "steppedLine": false,
"targets": [ "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": "", "interval": "",
"legendFormat": "{{`{{ exported_namespace }}`}} {{`{{ status }}`}}", "legendFormat": "{{`{{ exported_namespace }}`}} {{`{{ status }}`}}",
"refId": "A" "refId": "A"
@ -422,7 +422,7 @@ data:
"pluginVersion": "7.1.5", "pluginVersion": "7.1.5",
"targets": [ "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", "format": "table",
"instant": true, "instant": true,
"interval": "", "interval": "",
@ -442,7 +442,18 @@ data:
"Value": true, "Value": true,
"status": false "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": { "renameByName": {
"exported_namespace": "namespace" "exported_namespace": "namespace"
} }
@ -489,7 +500,7 @@ data:
"pluginVersion": "7.1.5", "pluginVersion": "7.1.5",
"targets": [ "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", "format": "table",
"instant": true, "instant": true,
"interval": "", "interval": "",
@ -509,7 +520,18 @@ data:
"Value": true, "Value": true,
"status": false "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": { "renameByName": {
"exported_namespace": "namespace" "exported_namespace": "namespace"
} }
@ -553,7 +575,7 @@ data:
"pluginVersion": "7.1.5", "pluginVersion": "7.1.5",
"targets": [ "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", "format": "table",
"instant": true, "instant": true,
"interval": "", "interval": "",
@ -573,7 +595,18 @@ data:
"Value": true, "Value": true,
"status": false "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": { "renameByName": {
"exported_namespace": "namespace" "exported_namespace": "namespace"
} }
@ -617,7 +650,7 @@ data:
"pluginVersion": "7.1.5", "pluginVersion": "7.1.5",
"targets": [ "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", "format": "table",
"instant": true, "instant": true,
"interval": "", "interval": "",
@ -637,7 +670,18 @@ data:
"Value": true, "Value": true,
"status": false "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": { "renameByName": {
"exported_namespace": "namespace" "exported_namespace": "namespace"
} }
@ -656,10 +700,10 @@ data:
"templating": { "templating": {
"list": [ "list": [
{ {
"allValue": null, "allValue": ".*",
"definition": "label_values(policy_report_result, policy)", "definition": "label_values(policy_report_result, policy)",
"hide": 0, "hide": 0,
"includeAll": false, "includeAll": true,
"label": "Policy", "label": "Policy",
"multi": true, "multi": true,
"name": "policy", "name": "policy",
@ -674,6 +718,86 @@ data:
"tagsQuery": "", "tagsQuery": "",
"type": "query", "type": "query",
"useTags": false "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
} }
] ]
}, },

View file

@ -6,7 +6,7 @@ serviceMonitor:
policyReportDetails: policyReportDetails:
firstStatusRow: firstStatusRow:
height: 6 height: 8
secondStatusRow: secondStatusRow:
enabled: true enabled: true
height: 2 height: 2

View file

@ -3,5 +3,5 @@ name: ui
description: Policy Reporter UI description: Policy Reporter UI
type: application type: application
version: 1.0.0 version: 1.1.0
appVersion: 0.6.0 appVersion: 0.7.0

View file

@ -7,7 +7,7 @@ log:
image: image:
repository: fjogeleit/policy-reporter-ui repository: fjogeleit/policy-reporter-ui
pullPolicy: IfNotPresent pullPolicy: IfNotPresent
tag: 0.6.0 tag: 0.7.0
imagePullSecrets: [] imagePullSecrets: []

View file

@ -1,7 +1,7 @@
image: image:
repository: fjogeleit/policy-reporter repository: fjogeleit/policy-reporter
pullPolicy: IfNotPresent pullPolicy: IfNotPresent
tag: 1.0.1 tag: 1.1.0
imagePullSecrets: [] imagePullSecrets: []

Binary file not shown.

Before

Width:  |  Height:  |  Size: 283 KiB

After

Width:  |  Height:  |  Size: 344 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 410 KiB

After

Width:  |  Height:  |  Size: 297 KiB

View file

@ -17,7 +17,7 @@ func CreateClusterPolicyReportMetricsCallback() report.ClusterPolicyReportCallba
ruleGauge := promauto.NewGaugeVec(prometheus.GaugeOpts{ ruleGauge := promauto.NewGaugeVec(prometheus.GaugeOpts{
Name: "cluster_policy_report_result", Name: "cluster_policy_report_result",
Help: "List of all ClusterPolicyReport Results", 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(policyGauge)
prometheus.Register(ruleGauge) prometheus.Register(ruleGauge)
@ -37,6 +37,7 @@ func CreateClusterPolicyReportMetricsCallback() report.ClusterPolicyReportCallba
res.Name, res.Name,
rule.Status, rule.Status,
rule.Severity, rule.Severity,
rule.Category,
).Set(1) ).Set(1)
} }
case watch.Modified: case watch.Modified:
@ -52,6 +53,7 @@ func CreateClusterPolicyReportMetricsCallback() report.ClusterPolicyReportCallba
res.Name, res.Name,
rule.Status, rule.Status,
rule.Severity, rule.Severity,
rule.Category,
) )
} }
@ -66,6 +68,7 @@ func CreateClusterPolicyReportMetricsCallback() report.ClusterPolicyReportCallba
res.Name, res.Name,
rule.Status, rule.Status,
rule.Severity, rule.Severity,
rule.Category,
). ).
Set(1) Set(1)
} }
@ -86,6 +89,7 @@ func CreateClusterPolicyReportMetricsCallback() report.ClusterPolicyReportCallba
res.Name, res.Name,
rule.Status, rule.Status,
rule.Severity, rule.Severity,
rule.Category,
) )
} }
} }

View file

@ -214,50 +214,56 @@ func testClusterSummaryMetricLabels(
} }
func testClusterResultMetricLabels(metric *io_prometheus_client.Metric, result report.Result) error { 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) 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) 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) 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) 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) return fmt.Errorf("Unexpected Name Label: %s", name)
} }
if value := *metric.Label[3].Value; value != result.Policy {
if value := *metric.Label[2].Value; value != result.Policy {
return fmt.Errorf("Unexpected Policy Label Value: %s", value) 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) 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) 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) 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) 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) 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) 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) return fmt.Errorf("Unexpected Status Label Value: %s", value)
} }

View file

@ -17,7 +17,7 @@ func CreatePolicyReportMetricsCallback() report.PolicyReportCallback {
ruleGauge := promauto.NewGaugeVec(prometheus.GaugeOpts{ ruleGauge := promauto.NewGaugeVec(prometheus.GaugeOpts{
Name: "policy_report_result", Name: "policy_report_result",
Help: "List of all PolicyReport Results", 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(policyGauge)
prometheus.Register(ruleGauge) prometheus.Register(ruleGauge)
@ -39,6 +39,7 @@ func CreatePolicyReportMetricsCallback() report.PolicyReportCallback {
res.Name, res.Name,
rule.Status, rule.Status,
rule.Severity, rule.Severity,
rule.Category,
). ).
Set(1) Set(1)
} }
@ -56,6 +57,7 @@ func CreatePolicyReportMetricsCallback() report.PolicyReportCallback {
res.Name, res.Name,
rule.Status, rule.Status,
rule.Severity, rule.Severity,
rule.Category,
) )
} }
@ -71,6 +73,7 @@ func CreatePolicyReportMetricsCallback() report.PolicyReportCallback {
res.Name, res.Name,
rule.Status, rule.Status,
rule.Severity, rule.Severity,
rule.Category,
). ).
Set(1) Set(1)
} }
@ -93,6 +96,7 @@ func CreatePolicyReportMetricsCallback() report.PolicyReportCallback {
res.Name, res.Name,
rule.Status, rule.Status,
rule.Severity, rule.Severity,
rule.Category,
) )
} }
} }

View file

@ -223,57 +223,63 @@ func testSummaryMetricLabels(
} }
func testResultMetricLabels(metric *io_prometheus_client.Metric, result report.Result) error { 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) 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) 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) 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) 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) 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) 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) return fmt.Errorf("Unexpected Name Label: %s", name)
} }
if value := *metric.Label[4].Value; value != result.Policy {
if value := *metric.Label[3].Value; value != result.Policy {
return fmt.Errorf("Unexpected Policy Label Value: %s", value) 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) 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) 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) 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) 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) 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) 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) return fmt.Errorf("Unexpected Status Label Value: %s", value)
} }