alerting(eval): EvalResult.Batch carries nextEvalState for cursor threading
This commit is contained in:
@@ -64,13 +64,13 @@ public class AgentLifecycleEvaluator implements ConditionEvaluator<AgentLifecycl
|
||||
List<AgentEventRecord> matches = eventRepo.findInWindow(
|
||||
envSlug, appSlug, agentId, typeNames, from, to, MAX_EVENTS_PER_TICK);
|
||||
|
||||
if (matches.isEmpty()) return new EvalResult.Batch(List.of());
|
||||
if (matches.isEmpty()) return new EvalResult.Batch(List.of(), Map.of());
|
||||
|
||||
List<EvalResult.Firing> firings = new ArrayList<>(matches.size());
|
||||
for (AgentEventRecord ev : matches) {
|
||||
firings.add(toFiring(ev));
|
||||
}
|
||||
return new EvalResult.Batch(firings);
|
||||
return new EvalResult.Batch(firings, Map.of());
|
||||
}
|
||||
|
||||
private static EvalResult.Firing toFiring(AgentEventRecord ev) {
|
||||
|
||||
@@ -17,9 +17,14 @@ public sealed interface EvalResult {
|
||||
|
||||
record Error(Throwable cause) implements EvalResult {}
|
||||
|
||||
record Batch(List<Firing> firings) implements EvalResult {
|
||||
record Batch(List<Firing> firings, Map<String, Object> nextEvalState) implements EvalResult {
|
||||
public Batch {
|
||||
firings = firings == null ? List.of() : List.copyOf(firings);
|
||||
nextEvalState = nextEvalState == null ? Map.of() : Map.copyOf(nextEvalState);
|
||||
}
|
||||
/** Convenience: a Batch with no cursor update (first-run empty, or no matches). */
|
||||
public static Batch empty() {
|
||||
return new Batch(List.of(), Map.of());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,7 +116,7 @@ public class ExchangeMatchEvaluator implements ConditionEvaluator<ExchangeMatchC
|
||||
SearchResult<ExecutionSummary> result = searchIndex.search(req);
|
||||
List<ExecutionSummary> matches = result.data();
|
||||
|
||||
if (matches.isEmpty()) return new EvalResult.Batch(List.of());
|
||||
if (matches.isEmpty()) return new EvalResult.Batch(List.of(), Map.of());
|
||||
|
||||
// Find the latest startTime across all matches — becomes the next cursor
|
||||
Instant latestTs = matches.stream()
|
||||
@@ -144,6 +144,6 @@ public class ExchangeMatchEvaluator implements ConditionEvaluator<ExchangeMatchC
|
||||
firings.add(new EvalResult.Firing(1.0, null, ctx2));
|
||||
}
|
||||
|
||||
return new EvalResult.Batch(firings);
|
||||
return new EvalResult.Batch(firings, Map.of());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,7 +157,7 @@ class AlertStateTransitionsTest {
|
||||
|
||||
@Test
|
||||
void batchResultAlwaysEmpty() {
|
||||
var batch = new EvalResult.Batch(List.of(FIRING_RESULT));
|
||||
var batch = new EvalResult.Batch(List.of(FIRING_RESULT), Map.of());
|
||||
var next = AlertStateTransitions.apply(null, batch, ruleWith(0), NOW);
|
||||
assertThat(next).isEmpty();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user