@@ -14,9 +14,11 @@ import (
1414func (data * Data ) processFixedIssues (inputs * Inputs , finopsIndex , securityIndex policyFailureIndex , taggingIndex taggingFailureIndex ) {
1515 counts := make ([]FixedIssueCount , 0 , len (data .PreviousFinOpsPolicyResults )+ len (data .PreviousSecurityPolicyResults )+ len (data .TaggingPolicyResults ))
1616
17- counts = append (counts , finopsFixedIssueCounts (data .PreviousFinOpsPolicyResults , finopsIndex )... )
18- counts = append (counts , finopsFixedIssueCounts (data .PreviousSecurityPolicyResults , securityIndex )... )
19- counts = append (counts , taggingFixedIssueCounts (data .TaggingPolicyResults , taggingIndex )... )
17+ deleted := data .buildDeletedResources ()
18+
19+ counts = append (counts , finopsFixedIssueCounts (data .PreviousFinOpsPolicyResults , finopsIndex , deleted )... )
20+ counts = append (counts , finopsFixedIssueCounts (data .PreviousSecurityPolicyResults , securityIndex , deleted )... )
21+ counts = append (counts , taggingFixedIssueCounts (data .TaggingPolicyResults , taggingIndex , deleted )... )
2022
2123 // Sort by count descending, then policy name ascending.
2224 sort .Slice (counts , func (i , j int ) bool {
@@ -44,8 +46,11 @@ func (data *Data) processFixedIssues(inputs *Inputs, finopsIndex, securityIndex
4446}
4547
4648// finopsFixedIssueCounts computes fixed issue counts for FinOps/security policies.
47- // A fixed issue is a resource that was failing previously but is no longer failing.
48- func finopsFixedIssueCounts (previousResults []* provider.FinopsPolicyResult , index policyFailureIndex ) []FixedIssueCount {
49+ // A fixed issue is a resource that was failing previously, is no longer failing,
50+ // and still appears in some current policy result. Resources in the deleted set
51+ // (gone from every current policy's scope) are excluded so we don't claim a fix
52+ // for a resource that has disappeared.
53+ func finopsFixedIssueCounts (previousResults []* provider.FinopsPolicyResult , index policyFailureIndex , deleted map [string ]bool ) []FixedIssueCount {
4954 if len (previousResults ) == 0 {
5055 return nil
5156 }
@@ -59,9 +64,13 @@ func finopsFixedIssueCounts(previousResults []*provider.FinopsPolicyResult, inde
5964 currentIDs := index .current [prev .PolicySlug ]
6065 fixed := 0
6166 for _ , r := range prev .FailingResources {
62- if currentIDs == nil || ! currentIDs [r .Id ] {
63- fixed ++
67+ if currentIDs != nil && currentIDs [r .Id ] {
68+ continue
69+ }
70+ if deleted [r .Id ] {
71+ continue
6472 }
73+ fixed ++
6574 }
6675
6776 if fixed > 0 {
@@ -76,8 +85,10 @@ func finopsFixedIssueCounts(previousResults []*provider.FinopsPolicyResult, inde
7685}
7786
7887// taggingFixedIssueCounts computes fixed issue counts for tagging policies.
79- // A fixed issue is an address that was failing previously but is no longer failing.
80- func taggingFixedIssueCounts (results []event.TaggingPolicyResult , index taggingFailureIndex ) []FixedIssueCount {
88+ // A fixed issue is an address that was failing previously, is no longer
89+ // failing, and still appears in some current policy result. Addresses in the
90+ // deleted set are excluded — see finopsFixedIssueCounts for rationale.
91+ func taggingFixedIssueCounts (results []event.TaggingPolicyResult , index taggingFailureIndex , deleted map [string ]bool ) []FixedIssueCount {
8192 var counts []FixedIssueCount
8293
8394 for _ , result := range results {
@@ -93,9 +104,13 @@ func taggingFixedIssueCounts(results []event.TaggingPolicyResult, index taggingF
93104 currentAddrs := index .current [result .TagPolicyID ]
94105 fixed := 0
95106 for addr := range prevAddrs {
96- if currentAddrs == nil || ! currentAddrs [addr ] {
97- fixed ++
107+ if currentAddrs != nil && currentAddrs [addr ] {
108+ continue
109+ }
110+ if deleted [addr ] {
111+ continue
98112 }
113+ fixed ++
99114 }
100115
101116 if fixed > 0 {
0 commit comments