1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2024-12-15 17:51:20 +00:00

rule to show violation count

This commit is contained in:
shivkumar dudhani 2019-09-03 18:31:57 -07:00
parent 9d81e61002
commit b152cdd004
5 changed files with 19 additions and 8 deletions

View file

@ -136,13 +136,15 @@ type PolicyStatus struct {
//RuleStats provides status per rule
type RuleStats struct {
// Rule name
RuleName string `json:"ruleName"`
Name string `json:"ruleName"`
// average time require to process the rule
ExecutionTime string `json:"averageExecutionTime"`
// Count of rules that were applied
RulesAppliedCount int `json:"rulesAppliedCount"`
// Could of rules that failed
RulesFailedCount int `json:"rulesFailedCount"`
AppliedCount int `json:"appliedCount"`
// Count of rules that failed
ViolationCount int `json:"violationCount"`
// Count of mutations
MutationCount int `json:"mutationsCount"`
}
// PolicyList is a list of Policy resources

View file

@ -39,6 +39,9 @@ func applyPolicy(policy kyverno.ClusterPolicy, resource unstructured.Unstructure
} else {
rs.RulesFailedCount++
}
if rule.Patches != nil {
rs.MutationCount++
}
ps.Stats.Rules = append(ps.Stats.Rules, rs)
}
policyStats = append(policyStats, ps)

View file

@ -958,10 +958,11 @@ func convertRules(rules []RuleStatinfo) []kyverno.RuleStats {
var stats []kyverno.RuleStats
for _, r := range rules {
stat := kyverno.RuleStats{
RuleName: r.RuleName,
ExecutionTime: r.ExecutionTime.String(),
RulesAppliedCount: r.RuleAppliedCount,
RulesFailedCount: r.RulesFailedCount,
Name: r.RuleName,
ExecutionTime: r.ExecutionTime.String(),
AppliedCount: r.RuleAppliedCount,
ViolationCount: r.RulesFailedCount,
MutationCount: r.MutationCount,
}
stats = append(stats, stat)
}

View file

@ -129,6 +129,7 @@ func aggregateRules(old []RuleStatinfo, update []RuleStatinfo) []RuleStatinfo {
rule.ExecutionTime = (rule.ExecutionTime + updateR.ExecutionTime) / 2
rule.RuleAppliedCount = rule.RuleAppliedCount + updateR.RuleAppliedCount
rule.RulesFailedCount = rule.RulesFailedCount + updateR.RulesFailedCount
rule.MutationCount = rule.MutationCount + updateR.MutationCount
newRules = append(newRules, *rule)
} else {
newRules = append(newRules, updateR)
@ -192,6 +193,7 @@ type RuleStatinfo struct {
ExecutionTime time.Duration
RuleAppliedCount int
RulesFailedCount int
MutationCount int
}
//SendStat sends the stat information for aggregation

View file

@ -34,6 +34,9 @@ func (ws *WebhookServer) HandleMutation(request *v1beta1.AdmissionRequest) (bool
} else {
rs.RulesFailedCount++
}
if rule.Patches != nil {
rs.MutationCount++
}
ps.Stats.Rules = append(ps.Stats.Rules, rs)
}
policyStats = append(policyStats, ps)