Skip to content

Commit

Permalink
Added PruneByPriority config
Browse files Browse the repository at this point in the history
Signed-off-by: anushkamittal20 <anumittal4641@gmail.com>
  • Loading branch information
anushkamittal20 authored and poiana committed Jan 21, 2022
1 parent 02a37b8 commit a162db9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ func getConfig() *types.Configuration {
v.SetDefault("PolicyReport.MinimumPriority", "")
v.SetDefault("PolicyReport.FailThreshold", 4)
v.SetDefault("PolicyReport.MaxEvents", 10)
v.SetDefault("PolicyReport.PruneByPriority", false)

v.SetDefault("Rabbitmq.URL", "")
v.SetDefault("Rabbitmq.Queue", "")
Expand Down
16 changes: 14 additions & 2 deletions outputs/policyreport.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,13 @@ func forPolicyReports(c *Client, namespace string, r *wgpolicy.PolicyReportResul
updatePolicyReportSummary(n, r)
polreports[n].count++
if polreports[n].count > c.Config.PolicyReport.MaxEvents {
pruningLogicForPolicyReports(n)
if c.Config.PolicyReport.PruneByPriority == true {
pruningLogicForPolicyReports(n)
} else {
polreports[n].report.Results[0] = nil
polreports[n].report.Results = polreports[n].report.Results[1:]
polreports[n].count = polreports[n].count - 1
}
}
polreports[n].report.Results = append(polreports[n].report.Results, r)
_, getErr := policyr.Get(context.Background(), polreports[n].report.Name, metav1.GetOptions{})
Expand Down Expand Up @@ -215,7 +221,13 @@ func forClusterPolicyReport(c *Client, r *wgpolicy.PolicyReportResult) {
repcount++
if repcount > c.Config.PolicyReport.MaxEvents {
//To do for pruning
pruningLogicForClusterReport()
if c.Config.PolicyReport.PruneByPriority == true {
pruningLogicForClusterReport()
} else {
report.Results[0] = nil
report.Results = report.Results[1:]
repcount = repcount - 1
}
}
report.Results = append(report.Results, r)
_, getErr := clusterpr.Get(context.Background(), report.Name, metav1.GetOptions{})
Expand Down
1 change: 1 addition & 0 deletions types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ type PolicyReportConfig struct {
MinimumPriority string
FailThreshold int
MaxEvents int
PruneByPriority bool
}

// RabbitmqConfig represents parameters for rabbitmq
Expand Down

0 comments on commit a162db9

Please sign in to comment.