fix(alerting/B-1): AlertStateTransitions.newInstance() propagates rule targets to AlertInstance
newInstance() now maps rule.targets() into targetUserIds/targetGroupIds/targetRoleNames so newly created AlertInstance rows carry the correct target arrays. Previously these were always empty List.of(), making the inbox query return nothing. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -2,8 +2,10 @@ package com.cameleer.server.app.alerting.eval;
|
||||
|
||||
import com.cameleer.server.core.alerting.AlertInstance;
|
||||
import com.cameleer.server.core.alerting.AlertRule;
|
||||
import com.cameleer.server.core.alerting.AlertRuleTarget;
|
||||
import com.cameleer.server.core.alerting.AlertSeverity;
|
||||
import com.cameleer.server.core.alerting.AlertState;
|
||||
import com.cameleer.server.core.alerting.TargetKind;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.List;
|
||||
@@ -98,6 +100,20 @@ public final class AlertStateTransitions {
|
||||
* title/message are left empty here; the job enriches them via MustacheRenderer after.
|
||||
*/
|
||||
static AlertInstance newInstance(AlertRule rule, EvalResult.Firing f, AlertState state, Instant now) {
|
||||
List<AlertRuleTarget> targets = rule.targets() != null ? rule.targets() : List.of();
|
||||
List<String> targetUserIds = targets.stream()
|
||||
.filter(t -> t.kind() == TargetKind.USER)
|
||||
.map(AlertRuleTarget::targetId)
|
||||
.toList();
|
||||
List<UUID> targetGroupIds = targets.stream()
|
||||
.filter(t -> t.kind() == TargetKind.GROUP)
|
||||
.map(t -> UUID.fromString(t.targetId()))
|
||||
.toList();
|
||||
List<String> targetRoleNames = targets.stream()
|
||||
.filter(t -> t.kind() == TargetKind.ROLE)
|
||||
.map(AlertRuleTarget::targetId)
|
||||
.toList();
|
||||
|
||||
return new AlertInstance(
|
||||
UUID.randomUUID(),
|
||||
rule.id(),
|
||||
@@ -116,8 +132,8 @@ public final class AlertStateTransitions {
|
||||
f.context() != null ? f.context() : Map.of(),
|
||||
"", // title — rendered by job
|
||||
"", // message — rendered by job
|
||||
List.of(),
|
||||
List.of(),
|
||||
List.of());
|
||||
targetUserIds,
|
||||
targetGroupIds,
|
||||
targetRoleNames);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user