Skip to content

Commit 7d8b321

Browse files
authored
🐛 Do not add insight for tagging rule with effort (#890)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Findings with non-zero effort are now routed to Violations; zero/unspecified effort findings go to Insights. Tags are now attached both to rule metadata and to final findings for improved filtering and reporting. * **Bug Fixes** * Preserves reported effort on findings instead of clearing it, ensuring accurate severity and classification. <!-- end of auto-generated comment: release notes by coderabbit.ai --> Fixes #889 --------- Signed-off-by: Emily McMullan <[email protected]>
1 parent 929f779 commit 7d8b321

1 file changed

Lines changed: 16 additions & 10 deletions

File tree

engine/engine.go

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -341,14 +341,15 @@ func (r *ruleEngine) filterRules(ruleSets []RuleSet, selectors ...RuleSelector)
341341
// if both message and tag are set, split message part into a new rule if effort is non-zero
342342
// if effort is zero, we do not want to create a violation but only tag and an insight
343343
if rule.Perform.Message.Text != nil && rule.Effort != nil && *rule.Effort != 0 {
344+
// because split rules will share ruleID, we need to add the tags to the labels here
345+
for _, tag := range rule.Perform.Tag {
346+
rule.Labels = append(rule.Labels, fmt.Sprintf("tag=%s", tag))
347+
}
344348
rule.Perform.Tag = nil
345-
otherRules = append(
346-
otherRules,
347-
ruleMessage{
348-
rule: rule,
349-
ruleSetName: ruleSet.Name,
350-
},
351-
)
349+
otherRules = append(otherRules, ruleMessage{
350+
rule: rule,
351+
ruleSetName: ruleSet.Name,
352+
})
352353
}
353354
}
354355
}
@@ -435,13 +436,18 @@ func (r *ruleEngine) runTaggingRules(ctx context.Context, infoRules []ruleMessag
435436
mapRuleSets[ruleMessage.ruleSetName] = rs
436437
}
437438
if rs, ok := mapRuleSets[ruleMessage.ruleSetName]; ok {
438-
violation.Effort = nil
439439
violation.Category = nil
440-
// we need to tie these incidents back to tags that created them
440+
// Add all tags to violation labels
441441
for tag := range tags {
442442
violation.Labels = append(violation.Labels, fmt.Sprintf("tag=%s", tag))
443443
}
444-
rs.Insights[rule.RuleID] = violation
444+
if violation.Effort != nil && *violation.Effort > 0 {
445+
// we need to tie these incidents back to tags that created them
446+
// don't create insight for effort > 0
447+
rs.Violations[rule.RuleID] = violation
448+
} else {
449+
rs.Insights[rule.RuleID] = violation
450+
}
445451
}
446452
} else {
447453
r.logger.Info("info rule not matched", "rule", rule.RuleID)

0 commit comments

Comments
 (0)