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(
|
List<AgentEventRecord> matches = eventRepo.findInWindow(
|
||||||
envSlug, appSlug, agentId, typeNames, from, to, MAX_EVENTS_PER_TICK);
|
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());
|
List<EvalResult.Firing> firings = new ArrayList<>(matches.size());
|
||||||
for (AgentEventRecord ev : matches) {
|
for (AgentEventRecord ev : matches) {
|
||||||
firings.add(toFiring(ev));
|
firings.add(toFiring(ev));
|
||||||
}
|
}
|
||||||
return new EvalResult.Batch(firings);
|
return new EvalResult.Batch(firings, Map.of());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static EvalResult.Firing toFiring(AgentEventRecord ev) {
|
private static EvalResult.Firing toFiring(AgentEventRecord ev) {
|
||||||
|
|||||||
@@ -17,9 +17,14 @@ public sealed interface EvalResult {
|
|||||||
|
|
||||||
record Error(Throwable cause) implements 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 {
|
public Batch {
|
||||||
firings = firings == null ? List.of() : List.copyOf(firings);
|
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);
|
SearchResult<ExecutionSummary> result = searchIndex.search(req);
|
||||||
List<ExecutionSummary> matches = result.data();
|
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
|
// Find the latest startTime across all matches — becomes the next cursor
|
||||||
Instant latestTs = matches.stream()
|
Instant latestTs = matches.stream()
|
||||||
@@ -144,6 +144,6 @@ public class ExchangeMatchEvaluator implements ConditionEvaluator<ExchangeMatchC
|
|||||||
firings.add(new EvalResult.Firing(1.0, null, ctx2));
|
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
|
@Test
|
||||||
void batchResultAlwaysEmpty() {
|
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);
|
var next = AlertStateTransitions.apply(null, batch, ruleWith(0), NOW);
|
||||||
assertThat(next).isEmpty();
|
assertThat(next).isEmpty();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user