Skip to content

Commit

Permalink
Use correct namespace label based on configuration (#357)
Browse files Browse the repository at this point in the history
Signed-off-by: Frank Jogeleit <frank.jogeleit@web.de>
  • Loading branch information
fjogeleit committed Oct 24, 2023
1 parent f1dfdff commit 50a1a8a
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 65 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

# 2.21.1
* Helm Chart
* Use correct namespace label based on the `monitoring.serviceMonitor.honorLabels` configuration in all Dashboards

# 2.21.0
* Policy Reporter
* Migrate to AWS SDK v2
Expand Down
6 changes: 3 additions & 3 deletions charts/policy-reporter/Chart.lock
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
dependencies:
- name: monitoring
repository: ""
version: 2.8.0
version: 2.8.1
- name: ui
repository: ""
version: 2.10.1
- name: kyvernoPlugin
repository: ""
version: 1.6.1
digest: sha256:b9fa7ca2c2245840d8e6b1202986589a948b8151b77c61bc8364f5899240b713
generated: "2023-10-20T11:23:44.58793+02:00"
digest: sha256:441dc00e311f2e5cfba50be2663e6c1560fb2d5c6ae611cd779271252a39a7ea
generated: "2023-10-24T09:58:54.455272+02:00"
4 changes: 2 additions & 2 deletions charts/policy-reporter/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description: |
It creates Prometheus Metrics and can send rule validation events to different targets like Loki, Elasticsearch, Slack or Discord
type: application
version: 2.21.0
version: 2.21.1
appVersion: 2.17.0

icon: https://github.com/kyverno/kyverno/raw/main/img/logo.png
Expand All @@ -18,7 +18,7 @@ maintainers:
dependencies:
- name: monitoring
condition: monitoring.enabled
version: "2.8.0"
version: "2.8.1"
- name: ui
condition: ui.enabled
version: "2.10.1"
Expand Down
2 changes: 1 addition & 1 deletion charts/policy-reporter/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Policy Reporter

![Version: v2.21.0](https://img.shields.io/badge/Version-v2.21.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: v2.17.0](https://img.shields.io/badge/AppVersion-v2.17.0-informational?style=flat-square)
![Version: v2.21.1](https://img.shields.io/badge/Version-v2.21.1-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: v2.17.0](https://img.shields.io/badge/AppVersion-v2.17.0-informational?style=flat-square)

## Motivation

Expand Down
2 changes: 1 addition & 1 deletion charts/policy-reporter/charts/monitoring/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ name: monitoring
description: Policy Reporter Monitoring with predefined ServiceMonitor and Grafana Dashboards

type: application
version: 2.8.0
version: 2.8.1
appVersion: 0.0.0
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
{{- if and .Values.grafana.dashboards.multicluster.enabled .Values.grafana.dashboards.multicluster.label }}
{{- $filters = append $filters .Values.grafana.dashboards.multicluster.label }}
{{- end }}

{{- $nsLabel := "exported_namespace" }}
{{- if .Values.serviceMonitor.honorLabels }}
{{- $nsLabel = "namespace" }}
{{- end }}

apiVersion: v1
kind: ConfigMap
metadata:
Expand Down Expand Up @@ -472,7 +478,7 @@ data:
"Value": 8
},
"renameByName": {
"exported_namespace": "namespace"
"{{ $nsLabel }}": "namespace"
}
}
}
Expand Down Expand Up @@ -551,7 +557,7 @@ data:
"Value": 8
},
"renameByName": {
"exported_namespace": "namespace"
"{{ $nsLabel }}": "namespace"
}
}
}
Expand Down Expand Up @@ -627,7 +633,7 @@ data:
"Value": 8
},
"renameByName": {
"exported_namespace": "namespace"
"{{ $nsLabel }}": "namespace"
}
}
}
Expand Down Expand Up @@ -703,7 +709,7 @@ data:
"Value": 8
},
"renameByName": {
"exported_namespace": "namespace"
"{{ $nsLabel }}": "namespace"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
{{- if and .Values.grafana.dashboards.multicluster.enabled .Values.grafana.dashboards.multicluster.label }}
{{- $filters = append $filters .Values.grafana.dashboards.multicluster.label }}
{{- end }}

{{- $nsLabel := "exported_namespace" }}
{{- if .Values.serviceMonitor.honorLabels }}
{{- $nsLabel = "namespace" }}
{{- end }}

apiVersion: v1
kind: ConfigMap
metadata:
Expand Down Expand Up @@ -109,10 +115,10 @@ data:
"pluginVersion": "7.1.5",
"targets": [
{
"expr": "sum(policy_report_result{policy=~\"$policy\", category=~\"$category\", severity=~\"$severity\", source=~\"$source\", kind=~\"$kind\", exported_namespace=~\"$namespace\", status=~\"fail|error\"{{ range $filters }}, {{.}}=~\"${{.}}\"{{ end }} } > 0) by (exported_namespace)",
"expr": "sum(policy_report_result{policy=~\"$policy\", category=~\"$category\", severity=~\"$severity\", source=~\"$source\", kind=~\"$kind\", {{ $nsLabel }}=~\"$namespace\", status=~\"fail|error\"{{ range $filters }}, {{.}}=~\"${{.}}\"{{ end }} } > 0) by ({{ $nsLabel }})",
"instant": true,
"interval": "",
"legendFormat": "{{`{{ exported_namespace }}`}}",
"legendFormat": "{{ printf `{{%s}}` $nsLabel }}",
"refId": "A"
}
],
Expand Down Expand Up @@ -238,7 +244,7 @@ data:
"refId": "A"
},
{
"expr": "sum(policy_report_result{policy=~\"$policy\", category=~\"$category\", severity=~\"$severity\", source=~\"$source\", kind=~\"$kind\", exported_namespace=~\"$namespace\", status=~\"fail|error\"{{ range $filters }}, {{.}}=~\"${{.}}\"{{ end }} } > 0) by (policy)",
"expr": "sum(policy_report_result{policy=~\"$policy\", category=~\"$category\", severity=~\"$severity\", source=~\"$source\", kind=~\"$kind\", {{ $nsLabel }}=~\"$namespace\", status=~\"fail|error\"{{ range $filters }}, {{.}}=~\"${{.}}\"{{ end }} } > 0) by (policy)",
"interval": "",
"legendFormat": "{{`{{ policy }}`}}",
"refId": "B"
Expand Down Expand Up @@ -323,11 +329,11 @@ data:
"pluginVersion": "7.1.5",
"targets": [
{
"expr": "sum(policy_report_result{policy=~\"$policy\", category=~\"$category\", severity=~\"$severity\", source=~\"$source\", kind=~\"$kind\", exported_namespace=~\"$namespace\", status=~\"fail|error\"{{ range $filters }}, {{.}}=~\"${{.}}\"{{ end }} }) by (exported_namespace,policy,rule,kind,name,status,category,severity,source{{ range $filters }},{{.}}{{ end }})",
"expr": "sum(policy_report_result{policy=~\"$policy\", category=~\"$category\", severity=~\"$severity\", source=~\"$source\", kind=~\"$kind\", {{ $nsLabel }}=~\"$namespace\", status=~\"fail|error\"{{ range $filters }}, {{.}}=~\"${{.}}\"{{ end }} }) by ({{ $nsLabel }},policy,rule,kind,name,status,category,severity,source{{ range $filters }},{{.}}{{ end }})",
"format": "table",
"instant": true,
"interval": "",
"legendFormat": "{{`{{ exported_namespace }}`}}: {{`{{ policy }}`}}",
"legendFormat": "{{ printf `{{%s}}` $nsLabel }}: {{`{{ policy }}`}}",
"refId": "A"
}
],
Expand All @@ -346,15 +352,15 @@ data:
"source": 0,
"category": 1,
"severity": 2,
"exported_namespace": 3,
"{{ $nsLabel }}": 3,
"kind": 4,
"name": 5,
"policy": 6,
"rule": 7,
"status": 8
},
"renameByName": {
"exported_namespace": "namespace"
"{{ $nsLabel }}": "namespace"
}
}
}
Expand Down Expand Up @@ -526,14 +532,14 @@ data:
{
"allValue": ".*",
"datasource": "${DS_PROMETHEUS}",
"definition": "label_values({__name__= \"policy_report_result\", status=~\"fail|error\"}, exported_namespace)",
"definition": "label_values({__name__= \"policy_report_result\", status=~\"fail|error\"}, {{ $nsLabel }})",
"hide": 0,
"includeAll": true,
"label": "Namespace",
"multi": true,
"name": "namespace",
"options": [],
"query": "label_values({__name__= \"policy_report_result\", status=~\"fail|error\"}, exported_namespace)",
"query": "label_values({__name__= \"policy_report_result\", status=~\"fail|error\"}, {{ $nsLabel }})",
"refresh": 2,
"regex": "",
"skipUrlSync": false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
{{- if and .Values.grafana.dashboards.multicluster.enabled .Values.grafana.dashboards.multicluster.label }}
{{- $filters = append $filters .Values.grafana.dashboards.multicluster.label }}
{{- end }}

{{- $nsLabel := "exported_namespace" }}
{{- if .Values.serviceMonitor.honorLabels }}
{{- $nsLabel = "namespace" }}
{{- end }}

apiVersion: v1
kind: ConfigMap
metadata:
Expand Down Expand Up @@ -119,10 +125,10 @@ data:
"pluginVersion": "7.1.5",
"targets": [
{
"expr": "sum(policy_report_result{policy=~\"$policy\", category=~\"$category\", severity=~\"$severity\", source=~\"$source\", kind=~\"$kind\", exported_namespace=~\"$namespace\", status=\"pass\"{{ range $filters }}, {{.}}=~\"${{.}}\"{{ end }} } > 0) by (exported_namespace)",
"expr": "sum(policy_report_result{policy=~\"$policy\", category=~\"$category\", severity=~\"$severity\", source=~\"$source\", kind=~\"$kind\", {{ $nsLabel }}=~\"$namespace\", status=\"pass\"{{ range $filters }}, {{.}}=~\"${{.}}\"{{ end }} } > 0) by ({{ $nsLabel }})",
"instant": true,
"interval": "",
"legendFormat": "{{`{{ exported_namespace }}`}}",
"legendFormat": "{{ printf `{{%s}}` $nsLabel }}",
"refId": "A"
}
],
Expand Down Expand Up @@ -174,10 +180,10 @@ data:
"pluginVersion": "7.1.5",
"targets": [
{
"expr": "sum(policy_report_result{policy=~\"$policy\", category=~\"$category\", severity=~\"$severity\", source=~\"$source\", kind=~\"$kind\", exported_namespace=~\"$namespace\", status=\"fail\"{{ range $filters }}, {{.}}=~\"${{.}}\"{{ end }} } > 0) by (exported_namespace)",
"expr": "sum(policy_report_result{policy=~\"$policy\", category=~\"$category\", severity=~\"$severity\", source=~\"$source\", kind=~\"$kind\", {{ $nsLabel }}=~\"$namespace\", status=\"fail\"{{ range $filters }}, {{.}}=~\"${{.}}\"{{ end }} } > 0) by ({{ $nsLabel }})",
"instant": true,
"interval": "",
"legendFormat": "{{`{{ exported_namespace }}`}}",
"legendFormat": "{{ printf `{{%s}}` $nsLabel }}",
"refId": "A"
}
],
Expand Down Expand Up @@ -230,10 +236,10 @@ data:
"pluginVersion": "7.1.5",
"targets": [
{
"expr": "sum(policy_report_result{policy=~\"$policy\", category=~\"$category\", severity=~\"$severity\", source=~\"$source\", kind=~\"$kind\", exported_namespace=~\"$namespace\", status=\"warn\"{{ range $filters }}, {{.}}=~\"${{.}}\"{{ end }} } > 0) by (exported_namespace)",
"expr": "sum(policy_report_result{policy=~\"$policy\", category=~\"$category\", severity=~\"$severity\", source=~\"$source\", kind=~\"$kind\", {{ $nsLabel }}=~\"$namespace\", status=\"warn\"{{ range $filters }}, {{.}}=~\"${{.}}\"{{ end }} } > 0) by ({{ $nsLabel }})",
"instant": true,
"interval": "",
"legendFormat": "{{`{{ exported_namespace }}`}}",
"legendFormat": "{{ printf `{{%s}}` $nsLabel }}",
"refId": "A"
}
],
Expand Down Expand Up @@ -285,10 +291,10 @@ data:
"pluginVersion": "7.1.5",
"targets": [
{
"expr": "sum(policy_report_result{policy=~\"$policy\", category=~\"$category\", severity=~\"$severity\", source=~\"$source\", kind=~\"$kind\", exported_namespace=~\"$namespace\", status=\"error\"{{ range $filters }}, {{.}}=~\"${{.}}\"{{ end }} } > 0) by (exported_namespace)",
"expr": "sum(policy_report_result{policy=~\"$policy\", category=~\"$category\", severity=~\"$severity\", source=~\"$source\", kind=~\"$kind\", {{ $nsLabel }}=~\"$namespace\", status=\"error\"{{ range $filters }}, {{.}}=~\"${{.}}\"{{ end }} } > 0) by ({{ $nsLabel }})",
"instant": true,
"interval": "",
"legendFormat": "{{`{{ exported_namespace }}`}}",
"legendFormat": "{{ printf `{{%s}}` $nsLabel }}",
"refId": "A"
}
],
Expand Down Expand Up @@ -348,9 +354,9 @@ data:
"steppedLine": false,
"targets": [
{
"expr": "sum(policy_report_result{policy=~\"$policy\", category=~\"$category\", severity=~\"$severity\", source=~\"$source\", kind=~\"$kind\", exported_namespace=~\"$namespace\"{{ range $filters }}, {{.}}=~\"${{.}}\"{{ end }} } > 0) by (status, exported_namespace)",
"expr": "sum(policy_report_result{policy=~\"$policy\", category=~\"$category\", severity=~\"$severity\", source=~\"$source\", kind=~\"$kind\", {{ $nsLabel }}=~\"$namespace\"{{ range $filters }}, {{.}}=~\"${{.}}\"{{ end }} } > 0) by (status, {{ $nsLabel }})",
"interval": "",
"legendFormat": "{{`{{ exported_namespace }}`}} {{`{{ status }}`}}",
"legendFormat": "{{ printf `{{%s}}` $nsLabel }} {{`{{ status }}`}}",
"refId": "A"
}
],
Expand Down Expand Up @@ -436,7 +442,7 @@ data:
"pluginVersion": "7.1.5",
"targets": [
{
"expr": "sum(policy_report_result{policy=~\"$policy\", category=~\"$category\", severity=~\"$severity\", source=~\"$source\", kind=~\"$kind\", exported_namespace=~\"$namespace\", status=\"pass\"{{ range $filters }}, {{.}}=~\"${{.}}\"{{ end }} }) by (exported_namespace,category,policy,rule,kind,name,severity,status,source{{ range $filters }},{{.}}{{ end }} )",
"expr": "sum(policy_report_result{policy=~\"$policy\", category=~\"$category\", severity=~\"$severity\", source=~\"$source\", kind=~\"$kind\", {{ $nsLabel }}=~\"$namespace\", status=\"pass\"{{ range $filters }}, {{.}}=~\"${{.}}\"{{ end }} }) by ({{ $nsLabel }},category,policy,rule,kind,name,severity,status,source{{ range $filters }},{{.}}{{ end }} )",
"format": "table",
"instant": true,
"interval": "",
Expand All @@ -460,7 +466,7 @@ data:
"Time": 0,
"source": 1,
"category": 2,
"exported_namespace": 3,
"{{ $nsLabel }}": 3,
"kind": 4,
"name": 5,
"policy": 6,
Expand All @@ -470,7 +476,7 @@ data:
"Value": 9
},
"renameByName": {
"exported_namespace": "namespace"
"{{ $nsLabel }}": "namespace"
}
}
}
Expand Down Expand Up @@ -516,7 +522,7 @@ data:
"pluginVersion": "7.1.5",
"targets": [
{
"expr": "sum(policy_report_result{policy=~\"$policy\", category=~\"$category\", severity=~\"$severity\", source=~\"$source\", kind=~\"$kind\", exported_namespace=~\"$namespace\", status=\"fail\"{{ range $filters }}, {{.}}=~\"${{.}}\"{{ end }} }) by (exported_namespace,category,policy,rule,kind,name,severity,status,source{{ range $filters }},{{.}}{{ end }})",
"expr": "sum(policy_report_result{policy=~\"$policy\", category=~\"$category\", severity=~\"$severity\", source=~\"$source\", kind=~\"$kind\", {{ $nsLabel }}=~\"$namespace\", status=\"fail\"{{ range $filters }}, {{.}}=~\"${{.}}\"{{ end }} }) by ({{ $nsLabel }},category,policy,rule,kind,name,severity,status,source{{ range $filters }},{{.}}{{ end }})",
"format": "table",
"instant": true,
"interval": "",
Expand All @@ -540,7 +546,7 @@ data:
"Time": 0,
"source": 1,
"category": 2,
"exported_namespace": 3,
"{{ $nsLabel }}": 3,
"kind": 4,
"name": 5,
"policy": 6,
Expand All @@ -550,7 +556,7 @@ data:
"Value": 9
},
"renameByName": {
"exported_namespace": "namespace"
"{{ $nsLabel }}": "namespace"
}
}
}
Expand Down Expand Up @@ -593,7 +599,7 @@ data:
"pluginVersion": "7.1.5",
"targets": [
{
"expr": "sum(policy_report_result{policy=~\"$policy\", category=~\"$category\", severity=~\"$severity\", source=~\"$source\", kind=~\"$kind\", exported_namespace=~\"$namespace\", status=\"warn\"{{ range $filters }}, {{.}}=~\"${{.}}\"{{ end }} }) by (exported_namespace,category,policy,rule,kind,name,severity,status,source{{ range $filters }},{{.}}{{ end }} )",
"expr": "sum(policy_report_result{policy=~\"$policy\", category=~\"$category\", severity=~\"$severity\", source=~\"$source\", kind=~\"$kind\", {{ $nsLabel }}=~\"$namespace\", status=\"warn\"{{ range $filters }}, {{.}}=~\"${{.}}\"{{ end }} }) by ({{ $nsLabel }},category,policy,rule,kind,name,severity,status,source{{ range $filters }},{{.}}{{ end }} )",
"format": "table",
"instant": true,
"interval": "",
Expand All @@ -617,7 +623,7 @@ data:
"Time": 0,
"source": 1,
"category": 2,
"exported_namespace": 3,
"{{ $nsLabel }}": 3,
"kind": 4,
"name": 5,
"policy": 6,
Expand All @@ -627,7 +633,7 @@ data:
"Value": 9
},
"renameByName": {
"exported_namespace": "namespace"
"{{ $nsLabel }}": "namespace"
}
}
}
Expand Down Expand Up @@ -670,7 +676,7 @@ data:
"pluginVersion": "7.1.5",
"targets": [
{
"expr": "sum(policy_report_result{policy=~\"$policy\", category=~\"$category\", severity=~\"$severity\", source=~\"$source\", kind=~\"$kind\", exported_namespace=~\"$namespace\", status=\"error\"{{ range $filters }}, {{.}}=~\"${{.}}\"{{ end }} }) by (exported_namespace,category,policy,rule,kind,name,severity,status,source{{ range $filters }},{{.}}{{ end }} )",
"expr": "sum(policy_report_result{policy=~\"$policy\", category=~\"$category\", severity=~\"$severity\", source=~\"$source\", kind=~\"$kind\", {{ $nsLabel }}=~\"$namespace\", status=\"error\"{{ range $filters }}, {{.}}=~\"${{.}}\"{{ end }} }) by ({{ $nsLabel }},category,policy,rule,kind,name,severity,status,source{{ range $filters }},{{.}}{{ end }} )",
"format": "table",
"instant": true,
"interval": "",
Expand All @@ -694,7 +700,7 @@ data:
"Time": 0,
"Value": 9,
"category": 1,
"exported_namespace": 3,
"{{ $nsLabel }}": 3,
"kind": 4,
"name": 5,
"policy": 6,
Expand All @@ -703,7 +709,7 @@ data:
"status": 8
},
"renameByName": {
"exported_namespace": "namespace"
"{{ $nsLabel }}": "namespace"
}
}
}
Expand Down Expand Up @@ -795,14 +801,14 @@ data:
{
"allValue": ".*",
"datasource": "${DS_PROMETHEUS}",
"definition": "label_values(policy_report_result, exported_namespace)",
"definition": "label_values(policy_report_result, {{ $nsLabel }})",
"hide": 0,
"includeAll": true,
"label": "Namespace",
"multi": true,
"name": "namespace",
"options": [],
"query": "label_values(policy_report_result, exported_namespace)",
"query": "label_values(policy_report_result, {{ $nsLabel }})",
"refresh": 2,
"regex": "",
"skipUrlSync": false,
Expand Down
Loading

0 comments on commit 50a1a8a

Please sign in to comment.