Skip to content

Commit 467ebdf

Browse files
committed
feat: extend control evaluation status with additional states and refine evaluation logic
1 parent 475bd96 commit 467ebdf

2 files changed

Lines changed: 64 additions & 16 deletions

File tree

plugins/compliance-orchestrator/evaluator/evaluator.go

Lines changed: 60 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func (e *Evaluator) evaluateQuery(ctx context.Context, q models.QueryConfig) mod
7777
}
7878
}
7979

80-
const evidenceLimit = 50
80+
const evidenceLimit = 10
8181
rawRows := res.Rows
8282
if len(rawRows) > evidenceLimit {
8383
rawRows = rawRows[:evidenceLimit]
@@ -140,26 +140,72 @@ func evaluateQueryRule(q models.QueryConfig, hits int) (models.QueryEvaluationSt
140140

141141
func computeControlStatus(strategy models.ComplianceStrategy, results []models.QueryEvaluation) models.ControlEvaluationStatus {
142142

143-
switch strategy {
144-
case models.StrategyAll:
145-
for _, r := range results {
146-
if r.Status != models.QueryStatusCompliant {
147-
return models.ControlStatusNonCompliant
148-
}
143+
hasCompliant := false
144+
hasNonCompliant := false
145+
hasError := false
146+
allNotApplicable := true
147+
148+
applicableCount := 0
149+
errorCount := 0
150+
151+
for _, r := range results {
152+
switch r.Status {
153+
case models.QueryStatusCompliant:
154+
hasCompliant = true
155+
allNotApplicable = false
156+
applicableCount++
157+
158+
case models.QueryStatusNonCompliant:
159+
hasNonCompliant = true
160+
allNotApplicable = false
161+
applicableCount++
162+
163+
case models.QueryStatusError:
164+
hasError = true
165+
allNotApplicable = false
166+
applicableCount++
167+
errorCount++
168+
169+
case models.QueryStatusNotApplicable:
149170
}
150-
return models.ControlStatusCompliant
171+
}
172+
173+
if allNotApplicable {
174+
return models.ControlStatusNotApplicable
175+
}
151176

177+
if applicableCount > 0 && errorCount == applicableCount {
178+
return models.ControlStatusNotEvaluated
179+
}
180+
181+
switch strategy {
152182
case models.StrategyAny:
153-
for _, r := range results {
154-
if r.Status == models.QueryStatusCompliant {
155-
return models.ControlStatusCompliant
156-
}
183+
if hasCompliant {
184+
return models.ControlStatusCompliant
185+
}
186+
187+
if hasError {
188+
return models.ControlStatusNonCompliant
157189
}
158-
return models.ControlStatusNonCompliant
159190

160-
default:
161191
return models.ControlStatusNonCompliant
192+
193+
case models.StrategyAll:
194+
195+
if hasNonCompliant {
196+
return models.ControlStatusNonCompliant
197+
}
198+
199+
if hasError {
200+
return models.ControlStatusNonCompliant
201+
}
202+
203+
if hasCompliant {
204+
return models.ControlStatusCompliant
205+
}
162206
}
207+
208+
return models.ControlStatusNonCompliant
163209
}
164210

165211
func patternExists(pattern int, active []models.IndexPattern) bool {

plugins/compliance-orchestrator/models/constant.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ const (
1212
type ControlEvaluationStatus string
1313

1414
const (
15-
ControlStatusCompliant ControlEvaluationStatus = "COMPLIANT"
16-
ControlStatusNonCompliant ControlEvaluationStatus = "NON_COMPLIANT"
15+
ControlStatusCompliant ControlEvaluationStatus = "COMPLIANT"
16+
ControlStatusNonCompliant ControlEvaluationStatus = "NON_COMPLIANT"
17+
ControlStatusNotApplicable ControlEvaluationStatus = "NOT_APPLICABLE"
18+
ControlStatusNotEvaluated ControlEvaluationStatus = "NOT_EVALUATED"
1719
)
1820

1921
type EvaluationRule string

0 commit comments

Comments
 (0)