-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Implement elasticsearch * Update deployment * Add Changelog
- Loading branch information
Showing
20 changed files
with
769 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Changelog | ||
|
||
## 0.7.0 | ||
|
||
* Implement Elasticsearch as Target for PolicyReportResults | ||
* Replace CLI flags with a single `config.yaml` to manage target-configurations as separate `ConfigMap` | ||
* Set `loki.skipExistingOnStartup` default value to `true` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: {{ include "policyreporter.fullname" . }}-targets | ||
labels: | ||
{{- include "policyreporter.labels" . | nindent 4 }} | ||
data: | ||
config.yaml: |- | ||
loki: | ||
host: {{ .Values.loki.host | quote }} | ||
minimumPriority: {{ .Values.loki.minimumPriority | quote }} | ||
skipExistingOnStartup: {{ .Values.loki.skipExistingOnStartup }} | ||
elasticsearch: | ||
host: {{ .Values.elasticsearch.host | quote }} | ||
index: {{ .Values.elasticsearch.index | default "policy-reporter" | quote }} | ||
rotation: {{ .Values.elasticsearch.rotation | default "dayli" | quote }} | ||
minimumPriority: {{ .Values.elasticsearch.minimumPriority | quote }} | ||
skipExistingOnStartup: {{ .Values.elasticsearch.skipExistingOnStartup }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package cmd | ||
|
||
import ( | ||
"flag" | ||
"net/http" | ||
|
||
"github.com/fjogeleit/policy-reporter/pkg/config" | ||
"github.com/fjogeleit/policy-reporter/pkg/report" | ||
"github.com/fjogeleit/policy-reporter/pkg/target" | ||
"github.com/prometheus/client_golang/prometheus/promhttp" | ||
"github.com/spf13/cobra" | ||
"golang.org/x/sync/errgroup" | ||
) | ||
|
||
func newRunCMD() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "run", | ||
Short: "Run PolicyReporter Watcher & HTTP Metrics Server", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
c, err := loadConfig(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
resolver := config.NewResolver(c) | ||
|
||
client, err := resolver.PolicyReportClient() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
policyMetrics, err := resolver.PolicyReportMetrics() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
clusterPolicyMetrics, err := resolver.ClusterPolicyReportMetrics() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
g := new(errgroup.Group) | ||
|
||
g.Go(policyMetrics.GenerateMetrics) | ||
|
||
g.Go(clusterPolicyMetrics.GenerateMetrics) | ||
|
||
g.Go(func() error { | ||
targets := resolver.TargetClients() | ||
|
||
if len(targets) == 0 { | ||
return nil | ||
} | ||
|
||
return client.WatchPolicyReportResults(func(r report.Result, e bool) { | ||
for _, t := range targets { | ||
go func(target target.Client, result report.Result, preExisted bool) { | ||
if preExisted && target.SkipExistingOnStartup() { | ||
return | ||
} | ||
|
||
target.Send(result) | ||
}(t, r, e) | ||
} | ||
}, resolver.SkipExistingOnStartup()) | ||
}) | ||
|
||
g.Go(func() error { | ||
http.Handle("/metrics", promhttp.Handler()) | ||
|
||
return http.ListenAndServe(":2112", nil) | ||
}) | ||
|
||
return g.Wait() | ||
}, | ||
} | ||
|
||
// For local usage | ||
cmd.PersistentFlags().StringP("kubeconfig", "k", "", "absolute path to the kubeconfig file") | ||
cmd.PersistentFlags().StringP("config", "c", "", "target configuration file") | ||
|
||
cmd.PersistentFlags().String("loki", "", "loki host: http://loki:3100") | ||
cmd.PersistentFlags().String("loki-minimum-priority", "", "Minimum Priority to send Results to Loki (info < warning < error)") | ||
cmd.PersistentFlags().Bool("loki-skip-existing-on-startup", false, "Skip Results created before PolicyReporter started. Prevent duplicated sending after new deployment") | ||
|
||
flag.Parse() | ||
|
||
return cmd | ||
} |
Oops, something went wrong.