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.AlertInstance;
|
||||||
import com.cameleer.server.core.alerting.AlertRule;
|
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.AlertSeverity;
|
||||||
import com.cameleer.server.core.alerting.AlertState;
|
import com.cameleer.server.core.alerting.AlertState;
|
||||||
|
import com.cameleer.server.core.alerting.TargetKind;
|
||||||
|
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.List;
|
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.
|
* 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) {
|
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(
|
return new AlertInstance(
|
||||||
UUID.randomUUID(),
|
UUID.randomUUID(),
|
||||||
rule.id(),
|
rule.id(),
|
||||||
@@ -116,8 +132,8 @@ public final class AlertStateTransitions {
|
|||||||
f.context() != null ? f.context() : Map.of(),
|
f.context() != null ? f.context() : Map.of(),
|
||||||
"", // title — rendered by job
|
"", // title — rendered by job
|
||||||
"", // message — rendered by job
|
"", // message — rendered by job
|
||||||
List.of(),
|
targetUserIds,
|
||||||
List.of(),
|
targetGroupIds,
|
||||||
List.of());
|
targetRoleNames);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user