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
…1348)

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 authored Jul 2, 2024
1 parent d577351 commit 4b001a6
Showing 1 changed file with 23 additions and 16 deletions.
39 changes: 23 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,11 @@ func (c *BufferedCollector) run() {
}

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

0 comments on commit 4b001a6

Please sign in to comment.