mirror of
https://github.com/kyverno/policy-reporter.git
synced 2024-12-14 11:57:32 +00:00
Fix PolicyDeleteEvent processing, Fix dashboard labels
This commit is contained in:
parent
fce86e7a60
commit
a55318e01a
6 changed files with 325 additions and 157 deletions
|
@ -3,8 +3,8 @@ name: policy-reporter
|
|||
description: K8s PolicyReporter watches for wgpolicyk8s.io/v1alpha1.PolicyReport resources. It creates Prometheus Metrics and can send rule validation events to different targets like Loki, Elasticsearch, Slack or Discord
|
||||
|
||||
type: application
|
||||
version: 0.14.0
|
||||
appVersion: 0.11.0
|
||||
version: 0.14.1
|
||||
appVersion: 0.11.1
|
||||
|
||||
dependencies:
|
||||
- name: monitoring
|
||||
|
|
|
@ -8,29 +8,47 @@ metadata:
|
|||
data:
|
||||
cluster-policy-reporter-details-dashboard.json: |
|
||||
{
|
||||
"__inputs": [
|
||||
{
|
||||
"name": "DS_PROMETHEUS",
|
||||
"label": "prometheus",
|
||||
"description": "",
|
||||
"type": "datasource",
|
||||
"pluginId": "prometheus",
|
||||
"pluginName": "Prometheus"
|
||||
}
|
||||
],
|
||||
"__requires": [
|
||||
{
|
||||
"type": "grafana",
|
||||
"id": "grafana",
|
||||
"name": "Grafana",
|
||||
"version": "7.1.5"
|
||||
},
|
||||
{
|
||||
"type": "datasource",
|
||||
"id": "prometheus",
|
||||
"name": "Prometheus",
|
||||
"version": "1.0.0"
|
||||
}
|
||||
"__inputs": [
|
||||
{
|
||||
"name": "DS_PROMETHEUS",
|
||||
"label": "Prometheus",
|
||||
"description": "",
|
||||
"type": "datasource",
|
||||
"pluginId": "prometheus",
|
||||
"pluginName": "Prometheus"
|
||||
}
|
||||
],
|
||||
"__requires": [
|
||||
{
|
||||
"type": "grafana",
|
||||
"id": "grafana",
|
||||
"name": "Grafana",
|
||||
"version": "7.1.5"
|
||||
},
|
||||
{
|
||||
"type": "panel",
|
||||
"id": "graph",
|
||||
"name": "Graph",
|
||||
"version": ""
|
||||
},
|
||||
{
|
||||
"type": "datasource",
|
||||
"id": "prometheus",
|
||||
"name": "Prometheus",
|
||||
"version": "1.0.0"
|
||||
},
|
||||
{
|
||||
"type": "panel",
|
||||
"id": "stat",
|
||||
"name": "Stat",
|
||||
"version": ""
|
||||
},
|
||||
{
|
||||
"type": "panel",
|
||||
"id": "table",
|
||||
"name": "Table",
|
||||
"version": ""
|
||||
}
|
||||
],
|
||||
"annotations": {
|
||||
"list": [
|
||||
|
@ -48,12 +66,9 @@ data:
|
|||
"editable": true,
|
||||
"gnetId": null,
|
||||
"graphTooltip": 0,
|
||||
"id": 49,
|
||||
"iteration": 1614702969043,
|
||||
"links": [],
|
||||
"panels": [
|
||||
{
|
||||
"datasource": null,
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"custom": {},
|
||||
|
@ -110,7 +125,6 @@ data:
|
|||
"type": "stat"
|
||||
},
|
||||
{
|
||||
"datasource": null,
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"custom": {},
|
||||
|
@ -167,7 +181,6 @@ data:
|
|||
"type": "stat"
|
||||
},
|
||||
{
|
||||
"datasource": null,
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"custom": {},
|
||||
|
@ -224,7 +237,6 @@ data:
|
|||
"type": "stat"
|
||||
},
|
||||
{
|
||||
"datasource": null,
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"custom": {},
|
||||
|
@ -281,7 +293,101 @@ data:
|
|||
"type": "stat"
|
||||
},
|
||||
{
|
||||
"datasource": null,
|
||||
"aliasColors": {},
|
||||
"bars": false,
|
||||
"dashLength": 10,
|
||||
"dashes": false,
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"custom": {}
|
||||
},
|
||||
"overrides": []
|
||||
},
|
||||
"fill": 1,
|
||||
"fillGradient": 0,
|
||||
"gridPos": {
|
||||
"h": 8,
|
||||
"w": 24,
|
||||
"x": 0,
|
||||
"y": 7
|
||||
},
|
||||
"hiddenSeries": false,
|
||||
"id": 13,
|
||||
"legend": {
|
||||
"alignAsTable": true,
|
||||
"avg": false,
|
||||
"current": false,
|
||||
"max": false,
|
||||
"min": false,
|
||||
"rightSide": true,
|
||||
"show": true,
|
||||
"total": false,
|
||||
"values": false
|
||||
},
|
||||
"lines": true,
|
||||
"linewidth": 1,
|
||||
"nullPointMode": "null",
|
||||
"percentage": false,
|
||||
"pluginVersion": "7.1.5",
|
||||
"pointradius": 2,
|
||||
"points": false,
|
||||
"renderer": "flot",
|
||||
"seriesOverrides": [],
|
||||
"spaceLength": 10,
|
||||
"stack": false,
|
||||
"steppedLine": false,
|
||||
"targets": [
|
||||
{
|
||||
"expr": "sum(cluster_policy_report_result{policy=~\"$policy\"} > 0) by (status)",
|
||||
"interval": "",
|
||||
"legendFormat": "{{`{{ status }}`}}",
|
||||
"refId": "A"
|
||||
}
|
||||
],
|
||||
"thresholds": [],
|
||||
"timeFrom": null,
|
||||
"timeRegions": [],
|
||||
"timeShift": null,
|
||||
"title": "Status Timeline",
|
||||
"tooltip": {
|
||||
"shared": true,
|
||||
"sort": 0,
|
||||
"value_type": "individual"
|
||||
},
|
||||
"type": "graph",
|
||||
"xaxis": {
|
||||
"buckets": null,
|
||||
"mode": "time",
|
||||
"name": null,
|
||||
"show": true,
|
||||
"values": []
|
||||
},
|
||||
"yaxes": [
|
||||
{
|
||||
"decimals": 0,
|
||||
"format": "none",
|
||||
"label": null,
|
||||
"logBase": 1,
|
||||
"max": null,
|
||||
"min": "0",
|
||||
"show": true
|
||||
},
|
||||
{
|
||||
"decimals": 0,
|
||||
"format": "short",
|
||||
"label": null,
|
||||
"logBase": 1,
|
||||
"max": null,
|
||||
"min": null,
|
||||
"show": true
|
||||
}
|
||||
],
|
||||
"yaxis": {
|
||||
"align": false,
|
||||
"alignLevel": null
|
||||
}
|
||||
},
|
||||
{
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"custom": {
|
||||
|
@ -308,7 +414,7 @@ data:
|
|||
"h": 8,
|
||||
"w": 24,
|
||||
"x": 0,
|
||||
"y": 7
|
||||
"y": 15
|
||||
},
|
||||
"id": 8,
|
||||
"options": {
|
||||
|
@ -347,7 +453,6 @@ data:
|
|||
"type": "table"
|
||||
},
|
||||
{
|
||||
"datasource": null,
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"custom": {
|
||||
|
@ -374,7 +479,7 @@ data:
|
|||
"h": 8,
|
||||
"w": 24,
|
||||
"x": 0,
|
||||
"y": 15
|
||||
"y": 23
|
||||
},
|
||||
"id": 9,
|
||||
"options": {
|
||||
|
@ -413,7 +518,6 @@ data:
|
|||
"type": "table"
|
||||
},
|
||||
{
|
||||
"datasource": null,
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"custom": {
|
||||
|
@ -437,7 +541,7 @@ data:
|
|||
"h": 5,
|
||||
"w": 24,
|
||||
"x": 0,
|
||||
"y": 23
|
||||
"y": 31
|
||||
},
|
||||
"id": 10,
|
||||
"options": {
|
||||
|
@ -476,7 +580,6 @@ data:
|
|||
"type": "table"
|
||||
},
|
||||
{
|
||||
"datasource": null,
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"custom": {
|
||||
|
@ -500,7 +603,7 @@ data:
|
|||
"h": 4,
|
||||
"w": 24,
|
||||
"x": 0,
|
||||
"y": 28
|
||||
"y": 36
|
||||
},
|
||||
"id": 11,
|
||||
"options": {
|
||||
|
@ -548,32 +651,16 @@ data:
|
|||
"list": [
|
||||
{
|
||||
"allValue": null,
|
||||
"current": {
|
||||
"selected": true,
|
||||
"tags": [],
|
||||
"text": [
|
||||
"require-ns-labels"
|
||||
],
|
||||
"value": [
|
||||
"require-ns-labels"
|
||||
]
|
||||
},
|
||||
"datasource": "Prometheus",
|
||||
"current": {},
|
||||
"definition": "label_values(cluster_policy_report_result, policy)",
|
||||
"hide": 0,
|
||||
"includeAll": false,
|
||||
"label": "Policy",
|
||||
"multi": true,
|
||||
"name": "policy",
|
||||
"options": [
|
||||
{
|
||||
"selected": true,
|
||||
"text": "require-ns-labels",
|
||||
"value": "require-ns-labels"
|
||||
}
|
||||
],
|
||||
"options": [],
|
||||
"query": "label_values(cluster_policy_report_result, policy)",
|
||||
"refresh": 0,
|
||||
"refresh": 2,
|
||||
"regex": "",
|
||||
"skipUrlSync": false,
|
||||
"sort": 5,
|
||||
|
@ -605,5 +692,6 @@ data:
|
|||
},
|
||||
"timezone": "",
|
||||
"title": "ClusterPolicyReport Details",
|
||||
"uid": "iyJszGUMk",
|
||||
"version": 1
|
||||
}
|
|
@ -8,29 +8,47 @@ metadata:
|
|||
data:
|
||||
policy-reporter-details-dashboard.json: |
|
||||
{
|
||||
"__inputs": [
|
||||
{
|
||||
"name": "DS_PROMETHEUS",
|
||||
"label": "prometheus",
|
||||
"description": "",
|
||||
"type": "datasource",
|
||||
"pluginId": "prometheus",
|
||||
"pluginName": "Prometheus"
|
||||
}
|
||||
],
|
||||
"__requires": [
|
||||
{
|
||||
"type": "grafana",
|
||||
"id": "grafana",
|
||||
"name": "Grafana",
|
||||
"version": "7.1.5"
|
||||
},
|
||||
{
|
||||
"type": "datasource",
|
||||
"id": "prometheus",
|
||||
"name": "Prometheus",
|
||||
"version": "1.0.0"
|
||||
}
|
||||
"__inputs": [
|
||||
{
|
||||
"name": "DS_PROMETHEUS",
|
||||
"label": "Prometheus",
|
||||
"description": "",
|
||||
"type": "datasource",
|
||||
"pluginId": "prometheus",
|
||||
"pluginName": "Prometheus"
|
||||
}
|
||||
],
|
||||
"__requires": [
|
||||
{
|
||||
"type": "panel",
|
||||
"id": "bargauge",
|
||||
"name": "Bar gauge",
|
||||
"version": ""
|
||||
},
|
||||
{
|
||||
"type": "grafana",
|
||||
"id": "grafana",
|
||||
"name": "Grafana",
|
||||
"version": "7.1.5"
|
||||
},
|
||||
{
|
||||
"type": "panel",
|
||||
"id": "graph",
|
||||
"name": "Graph",
|
||||
"version": ""
|
||||
},
|
||||
{
|
||||
"type": "datasource",
|
||||
"id": "prometheus",
|
||||
"name": "Prometheus",
|
||||
"version": "1.0.0"
|
||||
},
|
||||
{
|
||||
"type": "panel",
|
||||
"id": "table",
|
||||
"name": "Table",
|
||||
"version": ""
|
||||
}
|
||||
],
|
||||
"annotations": {
|
||||
"list": [
|
||||
|
@ -48,12 +66,9 @@ data:
|
|||
"editable": true,
|
||||
"gnetId": null,
|
||||
"graphTooltip": 0,
|
||||
"id": 48,
|
||||
"iteration": 1614703491465,
|
||||
"links": [],
|
||||
"panels": [
|
||||
{
|
||||
"datasource": null,
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"custom": {},
|
||||
|
@ -108,7 +123,6 @@ data:
|
|||
"type": "bargauge"
|
||||
},
|
||||
{
|
||||
"datasource": null,
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"custom": {},
|
||||
|
@ -163,7 +177,6 @@ data:
|
|||
"type": "bargauge"
|
||||
},
|
||||
{
|
||||
"datasource": null,
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"custom": {},
|
||||
|
@ -218,7 +231,6 @@ data:
|
|||
"type": "bargauge"
|
||||
},
|
||||
{
|
||||
"datasource": null,
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"custom": {},
|
||||
|
@ -273,7 +285,101 @@ data:
|
|||
"type": "bargauge"
|
||||
},
|
||||
{
|
||||
"datasource": null,
|
||||
"aliasColors": {},
|
||||
"bars": false,
|
||||
"dashLength": 10,
|
||||
"dashes": false,
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"custom": {}
|
||||
},
|
||||
"overrides": []
|
||||
},
|
||||
"fill": 1,
|
||||
"fillGradient": 0,
|
||||
"gridPos": {
|
||||
"h": 8,
|
||||
"w": 24,
|
||||
"x": 0,
|
||||
"y": 11
|
||||
},
|
||||
"hiddenSeries": false,
|
||||
"id": 13,
|
||||
"legend": {
|
||||
"alignAsTable": true,
|
||||
"avg": false,
|
||||
"current": false,
|
||||
"max": false,
|
||||
"min": false,
|
||||
"rightSide": true,
|
||||
"show": true,
|
||||
"total": false,
|
||||
"values": false
|
||||
},
|
||||
"lines": true,
|
||||
"linewidth": 1,
|
||||
"nullPointMode": "null",
|
||||
"percentage": false,
|
||||
"pluginVersion": "7.1.5",
|
||||
"pointradius": 2,
|
||||
"points": false,
|
||||
"renderer": "flot",
|
||||
"seriesOverrides": [],
|
||||
"spaceLength": 10,
|
||||
"stack": false,
|
||||
"steppedLine": false,
|
||||
"targets": [
|
||||
{
|
||||
"expr": "sum(policy_report_result{policy=~\"$policy\"} > 0) by (status, exported_namespace)",
|
||||
"interval": "",
|
||||
"legendFormat": "{{`{{ exported_namespace }}`}} {{`{{ status }}`}}",
|
||||
"refId": "A"
|
||||
}
|
||||
],
|
||||
"thresholds": [],
|
||||
"timeFrom": null,
|
||||
"timeRegions": [],
|
||||
"timeShift": null,
|
||||
"title": "Status Timeline",
|
||||
"tooltip": {
|
||||
"shared": true,
|
||||
"sort": 0,
|
||||
"value_type": "individual"
|
||||
},
|
||||
"type": "graph",
|
||||
"xaxis": {
|
||||
"buckets": null,
|
||||
"mode": "time",
|
||||
"name": null,
|
||||
"show": true,
|
||||
"values": []
|
||||
},
|
||||
"yaxes": [
|
||||
{
|
||||
"decimals": 0,
|
||||
"format": "none",
|
||||
"label": null,
|
||||
"logBase": 1,
|
||||
"max": null,
|
||||
"min": "0",
|
||||
"show": true
|
||||
},
|
||||
{
|
||||
"decimals": 0,
|
||||
"format": "short",
|
||||
"label": null,
|
||||
"logBase": 1,
|
||||
"max": null,
|
||||
"min": null,
|
||||
"show": true
|
||||
}
|
||||
],
|
||||
"yaxis": {
|
||||
"align": false,
|
||||
"alignLevel": null
|
||||
}
|
||||
},
|
||||
{
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"custom": {
|
||||
|
@ -300,7 +406,7 @@ data:
|
|||
"h": 8,
|
||||
"w": 24,
|
||||
"x": 0,
|
||||
"y": 11
|
||||
"y": 19
|
||||
},
|
||||
"id": 8,
|
||||
"options": {
|
||||
|
@ -339,7 +445,6 @@ data:
|
|||
"type": "table"
|
||||
},
|
||||
{
|
||||
"datasource": null,
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"custom": {
|
||||
|
@ -366,7 +471,7 @@ data:
|
|||
"h": 8,
|
||||
"w": 24,
|
||||
"x": 0,
|
||||
"y": 19
|
||||
"y": 27
|
||||
},
|
||||
"id": 9,
|
||||
"options": {
|
||||
|
@ -405,7 +510,6 @@ data:
|
|||
"type": "table"
|
||||
},
|
||||
{
|
||||
"datasource": null,
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"custom": {
|
||||
|
@ -429,7 +533,7 @@ data:
|
|||
"h": 5,
|
||||
"w": 24,
|
||||
"x": 0,
|
||||
"y": 27
|
||||
"y": 35
|
||||
},
|
||||
"id": 10,
|
||||
"options": {
|
||||
|
@ -468,7 +572,6 @@ data:
|
|||
"type": "table"
|
||||
},
|
||||
{
|
||||
"datasource": null,
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"custom": {
|
||||
|
@ -492,7 +595,7 @@ data:
|
|||
"h": 4,
|
||||
"w": 24,
|
||||
"x": 0,
|
||||
"y": 32
|
||||
"y": 40
|
||||
},
|
||||
"id": 11,
|
||||
"options": {
|
||||
|
@ -540,37 +643,15 @@ data:
|
|||
"list": [
|
||||
{
|
||||
"allValue": null,
|
||||
"current": {
|
||||
"selected": true,
|
||||
"tags": [],
|
||||
"text": [
|
||||
"check-label-app"
|
||||
],
|
||||
"value": [
|
||||
"check-label-app"
|
||||
]
|
||||
},
|
||||
"datasource": "Prometheus",
|
||||
"definition": "label_values(policy_report_result, policy)",
|
||||
"hide": 0,
|
||||
"includeAll": false,
|
||||
"label": "Policy",
|
||||
"multi": true,
|
||||
"name": "policy",
|
||||
"options": [
|
||||
{
|
||||
"selected": true,
|
||||
"text": "check-label-app",
|
||||
"value": "check-label-app"
|
||||
},
|
||||
{
|
||||
"selected": false,
|
||||
"text": "require-requests-and-limits-required",
|
||||
"value": "require-requests-and-limits-required"
|
||||
}
|
||||
],
|
||||
"options": [],
|
||||
"query": "label_values(policy_report_result, policy)",
|
||||
"refresh": 0,
|
||||
"refresh": 2,
|
||||
"regex": "",
|
||||
"skipUrlSync": false,
|
||||
"sort": 5,
|
||||
|
@ -583,7 +664,7 @@ data:
|
|||
]
|
||||
},
|
||||
"time": {
|
||||
"from": "now-6h",
|
||||
"from": "now-5m",
|
||||
"to": "now"
|
||||
},
|
||||
"timepicker": {
|
||||
|
@ -602,5 +683,6 @@ data:
|
|||
},
|
||||
"timezone": "",
|
||||
"title": "PolicyReport Details",
|
||||
"uid": "Tf1skG8Mz",
|
||||
"version": 1
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
image:
|
||||
repository: fjogeleit/policy-reporter
|
||||
pullPolicy: IfNotPresent
|
||||
tag: 0.11.0
|
||||
tag: 0.11.1
|
||||
|
||||
imagePullSecrets: []
|
||||
|
||||
|
|
|
@ -94,30 +94,29 @@ func (c *clusterPolicyReportClient) executeClusterPolicyReportHandler(e watch.Ev
|
|||
opr = c.cache[cpr.GetIdentifier()]
|
||||
}
|
||||
|
||||
if e != watch.Deleted {
|
||||
wg := sync.WaitGroup{}
|
||||
wg.Add(len(c.callbacks))
|
||||
wg := sync.WaitGroup{}
|
||||
wg.Add(len(c.callbacks))
|
||||
|
||||
for _, cb := range c.callbacks {
|
||||
go func(
|
||||
callback report.ClusterPolicyReportCallback,
|
||||
event watch.EventType,
|
||||
creport report.ClusterPolicyReport,
|
||||
oreport report.ClusterPolicyReport,
|
||||
) {
|
||||
callback(event, creport, oreport)
|
||||
wg.Done()
|
||||
}(cb, e, cpr, opr)
|
||||
}
|
||||
for _, cb := range c.callbacks {
|
||||
go func(
|
||||
callback report.ClusterPolicyReportCallback,
|
||||
event watch.EventType,
|
||||
creport report.ClusterPolicyReport,
|
||||
oreport report.ClusterPolicyReport,
|
||||
) {
|
||||
callback(event, creport, oreport)
|
||||
wg.Done()
|
||||
}(cb, e, cpr, opr)
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
|
||||
c.cache[cpr.GetIdentifier()] = cpr
|
||||
wg.Wait()
|
||||
|
||||
if e == watch.Deleted {
|
||||
delete(c.cache, cpr.GetIdentifier())
|
||||
return
|
||||
}
|
||||
|
||||
delete(c.cache, cpr.GetIdentifier())
|
||||
c.cache[cpr.GetIdentifier()] = cpr
|
||||
}
|
||||
|
||||
func (c *clusterPolicyReportClient) RegisterPolicyResultWatcher(skipExisting bool) {
|
||||
|
|
|
@ -94,30 +94,29 @@ func (c *policyReportClient) executePolicyReportHandler(e watch.EventType, pr re
|
|||
opr = c.cache[pr.GetIdentifier()]
|
||||
}
|
||||
|
||||
if e != watch.Deleted {
|
||||
wg := sync.WaitGroup{}
|
||||
wg.Add(len(c.callbacks))
|
||||
wg := sync.WaitGroup{}
|
||||
wg.Add(len(c.callbacks))
|
||||
|
||||
for _, cb := range c.callbacks {
|
||||
go func(
|
||||
callback report.PolicyReportCallback,
|
||||
event watch.EventType,
|
||||
creport report.PolicyReport,
|
||||
oreport report.PolicyReport,
|
||||
) {
|
||||
callback(event, creport, oreport)
|
||||
wg.Done()
|
||||
}(cb, e, pr, opr)
|
||||
}
|
||||
for _, cb := range c.callbacks {
|
||||
go func(
|
||||
callback report.PolicyReportCallback,
|
||||
event watch.EventType,
|
||||
creport report.PolicyReport,
|
||||
oreport report.PolicyReport,
|
||||
) {
|
||||
callback(event, creport, oreport)
|
||||
wg.Done()
|
||||
}(cb, e, pr, opr)
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
|
||||
c.cache[pr.GetIdentifier()] = pr
|
||||
wg.Wait()
|
||||
|
||||
if e == watch.Deleted {
|
||||
delete(c.cache, pr.GetIdentifier())
|
||||
return
|
||||
}
|
||||
|
||||
delete(c.cache, pr.GetIdentifier())
|
||||
c.cache[pr.GetIdentifier()] = pr
|
||||
}
|
||||
|
||||
func (c *policyReportClient) RegisterPolicyResultWatcher(skipExisting bool) {
|
||||
|
|
Loading…
Reference in a new issue