From 7d9f35b294c6ef019755d66fe10be8231220e98b Mon Sep 17 00:00:00 2001 From: Frank Jogeleit Date: Thu, 21 Jul 2022 19:42:31 +0200 Subject: [PATCH] Add Loki Path config to change deprecated API usage Signed-off-by: Frank Jogeleit --- CHANGELOG.md | 4 ++++ charts/policy-reporter/Chart.yaml | 4 ++-- charts/policy-reporter/config.yaml | 1 + charts/policy-reporter/values.yaml | 4 +++- manifest/default-policy-reporter-ui/install.yaml | 2 +- manifest/kyverno-policy-reporter-ui/install.yaml | 2 +- manifest/policy-reporter/install.yaml | 2 +- manifest/violations-email-report/cronjob.yaml | 2 +- pkg/config/config.go | 1 + pkg/config/resolver.go | 9 ++++++++- pkg/target/loki/loki.go | 4 ++-- pkg/target/loki/loki_test.go | 6 +++--- 12 files changed, 28 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f6aeec2d..e1e196f5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 (details) diff --git a/charts/policy-reporter/Chart.yaml b/charts/policy-reporter/Chart.yaml index 19cfad43..a6da5da9 100644 --- a/charts/policy-reporter/Chart.yaml +++ b/charts/policy-reporter/Chart.yaml @@ -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 diff --git a/charts/policy-reporter/config.yaml b/charts/policy-reporter/config.yaml index 3c038371..a1efac4b 100644 --- a/charts/policy-reporter/config.yaml +++ b/charts/policy-reporter/config.yaml @@ -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 }} diff --git a/charts/policy-reporter/values.yaml b/charts/policy-reporter/values.yaml index 55e562ed..a549d811 100644 --- a/charts/policy-reporter/values.yaml +++ b/charts/policy-reporter/values.yaml @@ -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 diff --git a/manifest/default-policy-reporter-ui/install.yaml b/manifest/default-policy-reporter-ui/install.yaml index 3d6efe2c..ca321f64 100644 --- a/manifest/default-policy-reporter-ui/install.yaml +++ b/manifest/default-policy-reporter-ui/install.yaml @@ -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 diff --git a/manifest/kyverno-policy-reporter-ui/install.yaml b/manifest/kyverno-policy-reporter-ui/install.yaml index 6c691af4..a4db3331 100644 --- a/manifest/kyverno-policy-reporter-ui/install.yaml +++ b/manifest/kyverno-policy-reporter-ui/install.yaml @@ -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 diff --git a/manifest/policy-reporter/install.yaml b/manifest/policy-reporter/install.yaml index a3b5eafd..37914411 100644 --- a/manifest/policy-reporter/install.yaml +++ b/manifest/policy-reporter/install.yaml @@ -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 diff --git a/manifest/violations-email-report/cronjob.yaml b/manifest/violations-email-report/cronjob.yaml index 2774a4bc..c829ec05 100644 --- a/manifest/violations-email-report/cronjob.yaml +++ b/manifest/violations-email-report/cronjob.yaml @@ -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 diff --git a/pkg/config/config.go b/pkg/config/config.go index 03c4f1e4..e1f5b5fc 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -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"` diff --git a/pkg/config/resolver.go b/pkg/config/resolver.go index b2ab1824..767a16ae 100644 --- a/pkg/config/resolver.go +++ b/pkg/config/resolver.go @@ -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, diff --git a/pkg/target/loki/loki.go b/pkg/target/loki/loki.go index 21c11fbf..c28bc7da 100644 --- a/pkg/target/loki/loki.go +++ b/pkg/target/loki/loki.go @@ -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, } diff --git a/pkg/target/loki/loki_test.go b/pkg/target/loki/loki_test.go index 9fe1f806..d5d650a7 100644 --- a/pkg/target/loki/loki_test.go +++ b/pkg/target/loki/loki_test.go @@ -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())