1
0
Fork 0
mirror of https://github.com/kyverno/policy-reporter.git synced 2024-12-15 17:50:58 +00:00

Add Loki Path config to change deprecated API usage

Signed-off-by: Frank Jogeleit <frank.jogeleit@web.de>
This commit is contained in:
Frank Jogeleit 2022-07-21 19:42:31 +02:00
parent 011dfa830f
commit 7d9f35b294
12 changed files with 28 additions and 13 deletions

View file

@ -1,5 +1,9 @@
# Changelog
# 2.10.3
* Policy Reporter
* Add new config `target.loki.path` to overwrite the deprected prom push API
# 2.10.2
* Policy Reporter UI
* New option `ui.clusters` makes it possible to configure additional external Policy Reporter APIs (<a href="https://kyverno.github.io/policy-reporter/guide/helm-chart-core#external-clusters" target="_blank">details</a>)

View file

@ -5,8 +5,8 @@ description: |
It creates Prometheus Metrics and can send rule validation events to different targets like Loki, Elasticsearch, Slack or Discord
type: application
version: 2.10.2
appVersion: 2.7.0
version: 2.10.3
appVersion: 2.7.1
icon: https://github.com/kyverno/kyverno/raw/main/img/logo.png
home: https://kyverno.github.io/policy-reporter

View file

@ -1,5 +1,6 @@
loki:
host: {{ .Values.target.loki.host | quote }}
path: {{ .Values.target.loki.path | quote }}
minimumPriority: {{ .Values.target.loki.minimumPriority | quote }}
skipExistingOnStartup: {{ .Values.target.loki.skipExistingOnStartup }}
{{- with .Values.target.loki.customLabels }}

View file

@ -2,7 +2,7 @@ image:
registry: ghcr.io
repository: kyverno/policy-reporter
pullPolicy: IfNotPresent
tag: 2.7.0
tag: 2.7.1
imagePullSecrets: []
@ -232,6 +232,8 @@ target:
loki:
# loki host address
host: ""
# loki api path, defaults to "/api/prom/push" (deprecated)
path: ""
# minimum priority "" < info < warning < critical < error
minimumPriority: ""
# list of sources which should send to loki

View file

@ -147,7 +147,7 @@ spec:
fsGroup: 1234
containers:
- name: policy-reporter
image: "ghcr.io/kyverno/policy-reporter:2.7.0"
image: "ghcr.io/kyverno/policy-reporter:2.7.1"
imagePullPolicy: IfNotPresent
securityContext:
allowPrivilegeEscalation: false

View file

@ -259,7 +259,7 @@ spec:
fsGroup: 1234
containers:
- name: policy-reporter
image: "ghcr.io/kyverno/policy-reporter:2.7.0"
image: "ghcr.io/kyverno/policy-reporter:2.7.1"
imagePullPolicy: IfNotPresent
securityContext:
allowPrivilegeEscalation: false

View file

@ -85,7 +85,7 @@ spec:
automountServiceAccountToken: true
containers:
- name: policy-reporter
image: "ghcr.io/kyverno/policy-reporter:2.7.0"
image: "ghcr.io/kyverno/policy-reporter:2.7.1"
imagePullPolicy: IfNotPresent
securityContext:
allowPrivilegeEscalation: false

View file

@ -26,7 +26,7 @@ spec:
restartPolicy: Never
containers:
- name: policy-reporter
image: "ghcr.io/kyverno/policy-reporter:2.7.0"
image: "ghcr.io/kyverno/policy-reporter:2.7.1"
imagePullPolicy: IfNotPresent
securityContext:
allowPrivilegeEscalation: false

View file

@ -29,6 +29,7 @@ type MetricsFilter struct {
type Loki struct {
Name string `mapstructure:"name"`
Host string `mapstructure:"host"`
Path string `mapstructure:"path"`
CustomLabels map[string]string `mapstructure:"customLabels"`
SkipExisting bool `mapstructure:"skipExistingOnStartup"`
MinimumPriority string `mapstructure:"minimumPriority"`

View file

@ -143,6 +143,9 @@ func (r *Resolver) LokiClients() []target.Client {
if r.config.Loki.Name == "" {
r.config.Loki.Name = "Loki"
}
if r.config.Loki.Path == "" {
r.config.Loki.Path = "/api/prom/push"
}
if loki := createLokiClient(r.config.Loki, Loki{}); loki != nil {
clients = append(clients, loki)
@ -534,11 +537,15 @@ func createLokiClient(config Loki, parent Loki) target.Client {
config.MinimumPriority = parent.MinimumPriority
}
if config.Path == "" {
config.Path = parent.Path
}
log.Printf("[INFO] %s configured", config.Name)
return loki.NewClient(
config.Name,
config.Host,
config.Host+config.Path,
config.SkipExisting,
createTargetFilter(config.Filter, config.MinimumPriority, config.Sources),
config.CustomLabels,

View file

@ -98,10 +98,10 @@ func (l *client) Send(result report.Result) {
}
// NewClient creates a new loki.client to send Results to Loki
func NewClient(name, host string, skipExistingOnStartup bool, filter *report.ResultFilter, customLabels map[string]string, httpClient http.Client) target.Client {
func NewClient(name, api string, skipExistingOnStartup bool, filter *report.ResultFilter, customLabels map[string]string, httpClient http.Client) target.Client {
return &client{
target.NewBaseClient(name, skipExistingOnStartup, filter),
host + "/api/prom/push",
api,
httpClient,
customLabels,
}

View file

@ -117,7 +117,7 @@ func Test_LokiTarget(t *testing.T) {
}
}
loki := loki.NewClient("Loki", "http://localhost:3100", false, &report.ResultFilter{}, map[string]string{"custom": "label"}, testClient{callback, 200})
loki := loki.NewClient("Loki", "http://localhost:3100/api/prom/push", false, &report.ResultFilter{}, map[string]string{"custom": "label"}, testClient{callback, 200})
loki.Send(completeResult)
})
@ -175,11 +175,11 @@ func Test_LokiTarget(t *testing.T) {
}
}
loki := loki.NewClient("Loki", "http://localhost:3100", false, &report.ResultFilter{}, make(map[string]string), testClient{callback, 200})
loki := loki.NewClient("Loki", "http://localhost:3100/api/prom/push", false, &report.ResultFilter{}, make(map[string]string), testClient{callback, 200})
loki.Send(minimalResult)
})
t.Run("Name", func(t *testing.T) {
client := loki.NewClient("Loki", "http://localhost:9200", true, &report.ResultFilter{}, make(map[string]string), testClient{})
client := loki.NewClient("Loki", "http://localhost:9200/api/prom/push", true, &report.ResultFilter{}, make(map[string]string), testClient{})
if client.Name() != "Loki" {
t.Errorf("Unexpected Name %s", client.Name())