Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Don't filter out scores of queries used for risk factors and not #1348

Merged
merged 1 commit into from
Jul 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading