Skip to content

Commit

Permalink
🐛 Don't filter out scores of queries used for risk factors and not
Browse files Browse the repository at this point in the history
If a query was used for a risk factor, its score was always being
filtered out, regardless of if it might have been used outside of risk
factors
  • Loading branch information
jaym committed Jul 1, 2024
1 parent bf039a2 commit 68a05a1
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions policy/executor/internal/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type BufferedCollector struct {
collector *PolicyServiceCollector
resolvedPolicy *policy.ResolvedPolicy
riskMRNs map[string][]string
keepQrIds map[string]bool
duration time.Duration
stopChan chan struct{}
wg sync.WaitGroup
Expand All @@ -55,29 +56,34 @@ func WithResolvedPolicy(resolved *policy.ResolvedPolicy) (BufferedCollectorOpt,
// TODO: need a more native way to integrate this part. We don't want to
// introduce a score type.
riskMRNs := map[string][]string{}
keepQrIds := map[string]bool{}
for _, rj := range resolved.CollectorJob.ReportingJobs {
if rj.Type != policy.ReportingJob_RISK_FACTOR {
continue
}
if rj.Type == policy.ReportingJob_RISK_FACTOR {
for k := range rj.ChildJobs {
cjob := resolved.CollectorJob.ReportingJobs[k]
if resolved.CollectorJob.RiskMrns == nil {
return nil, errors.New("missing query MRNs in resolved policy")
}

for k := range rj.ChildJobs {
cjob := resolved.CollectorJob.ReportingJobs[k]
if resolved.CollectorJob.RiskMrns == nil {
return nil, errors.New("missing query MRNs in resolved policy")
}
mrns := resolved.CollectorJob.RiskMrns[cjob.Uuid]
if mrns == nil {
return nil, errors.New("missing query MRNs for job uuid=" + cjob.Uuid + " checksum=" + cjob.Checksum)
}

mrns := resolved.CollectorJob.RiskMrns[cjob.Uuid]
if mrns == nil {
return nil, errors.New("missing query MRNs for job uuid=" + cjob.Uuid + " checksum=" + cjob.Checksum)
riskMRNs[cjob.QrId] = append(riskMRNs[cjob.QrId], mrns.Items...)
}
} else {
for k := range rj.ChildJobs {
cjob := resolved.CollectorJob.ReportingJobs[k]
keepQrIds[cjob.QrId] = true
}

riskMRNs[cjob.QrId] = append(riskMRNs[cjob.QrId], mrns.Items...)
}
}

return func(b *BufferedCollector) {
b.resolvedPolicy = resolved
b.riskMRNs = riskMRNs
b.keepQrIds = keepQrIds
}, nil
}

Expand Down Expand Up @@ -132,10 +138,10 @@ func (c *BufferedCollector) run() {
}

for _, s := range c.scores {
if c.consumeRisk(s, risksIdx) {
continue
c.consumeRisk(s, risksIdx)
if c.keepQrIds[s.QrId] {
scores = append(scores, s)
}
scores = append(scores, s)
}
for k := range c.scores {
delete(c.scores, k)
Expand Down

0 comments on commit 68a05a1

Please sign in to comment.