Skip to content

Commit 308623a

Browse files
fix[frontend](rules/custom_rules): changed legacy afterEvents by correlation
1 parent 2bc8106 commit 308623a

11 files changed

Lines changed: 47 additions & 44 deletions

File tree

frontend/src/features/alerting-rules/components/rule-form.tsx

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export interface RuleFormState {
3535
ruleActive: boolean
3636
dataTypes: string[]
3737
definition: string
38-
afterEvents: AfterStep[]
38+
correlation: AfterStep[]
3939
groupBy: string[]
4040
deduplicateBy: string[]
4141
references: string[]
@@ -59,9 +59,9 @@ function parseConditions(w: unknown): Condition[] {
5959
return { field: String(o.field ?? ''), operator: String(o.operator ?? 'filter_term'), value: valueToStr(o.value) }
6060
})
6161
}
62-
function parseSteps(after: unknown): AfterStep[] {
63-
if (!Array.isArray(after)) return []
64-
return after.map((s) => {
62+
function parseSteps(raw: unknown): AfterStep[] {
63+
if (!Array.isArray(raw)) return []
64+
return raw.map((s) => {
6565
const o = (s ?? {}) as Record<string, unknown>
6666
return {
6767
indexPattern: String(o.indexPattern ?? ''),
@@ -86,7 +86,7 @@ export function ruleToForm(r?: CorrelationRule): RuleFormState {
8686
ruleActive: r?.ruleActive ?? true,
8787
dataTypes: (r?.dataTypes ?? []).filter((d) => d.included).map((d) => d.dataType),
8888
definition: r?.definition ?? '',
89-
afterEvents: parseSteps(r?.afterEvents),
89+
correlation: parseSteps(r?.correlation ?? r?.afterEvents),
9090
groupBy: strArray(r?.groupBy),
9191
deduplicateBy: strArray(r?.deduplicateBy),
9292
references: strArray(r?.references),
@@ -122,7 +122,7 @@ export function formToInput(f: RuleFormState, relPath?: string): SaveRuleInput {
122122
description: f.description.trim(),
123123
references: f.references.filter(Boolean),
124124
definition: f.definition,
125-
afterEvents: stepsToJson(f.afterEvents),
125+
correlation: stepsToJson(f.correlation),
126126
groupBy: f.groupBy.filter(Boolean),
127127
deduplicateBy: f.deduplicateBy.filter(Boolean),
128128
ruleActive: f.ruleActive,
@@ -134,7 +134,7 @@ export function formToInput(f: RuleFormState, relPath?: string): SaveRuleInput {
134134

135135
export function RuleForm({ form, setForm, dataTypeOptions, t }: { form: RuleFormState; setForm: Dispatch<SetStateAction<RuleFormState>>; dataTypeOptions: DataTypeOption[]; t: TFunction }) {
136136
const set = <K extends keyof RuleFormState>(k: K, v: RuleFormState[K]) => setForm((f) => ({ ...f, [k]: v }))
137-
const setSteps = (steps: AfterStep[]) => set('afterEvents', steps)
137+
const setSteps = (steps: AfterStep[]) => set('correlation', steps)
138138

139139
// `where` condition: visual builder ⇄ raw CEL. Visual is the source when it
140140
// parses; otherwise we fall back to code for hand-written/advanced CEL.
@@ -221,21 +221,21 @@ export function RuleForm({ form, setForm, dataTypeOptions, t }: { form: RuleForm
221221
)}
222222
</div>
223223

224-
<Section title={t('alertingRules.editor.afterEvents')}>
225-
<p className="mb-3 text-[11px] text-muted-foreground">{t('alertingRules.editor.afterEventsHint')}</p>
224+
<Section title={t('alertingRules.editor.correlationSteps')}>
225+
<p className="mb-3 text-[11px] text-muted-foreground">{t('alertingRules.editor.correlationStepsHint')}</p>
226226
<div className="space-y-3">
227-
{form.afterEvents.map((step, i) => (
227+
{form.correlation.map((step, i) => (
228228
<StepCard
229229
key={i}
230230
step={step}
231231
index={i}
232232
t={t}
233-
onChange={(s) => setSteps(form.afterEvents.map((x, idx) => (idx === i ? s : x)))}
234-
onRemove={() => setSteps(form.afterEvents.filter((_, idx) => idx !== i))}
233+
onChange={(s) => setSteps(form.correlation.map((x, idx) => (idx === i ? s : x)))}
234+
onRemove={() => setSteps(form.correlation.filter((_, idx) => idx !== i))}
235235
/>
236236
))}
237237
<button
238-
onClick={() => setSteps([...form.afterEvents, { indexPattern: 'v11-log-*', within: '2m', count: 1, with: [], or: [] }])}
238+
onClick={() => setSteps([...form.correlation, { indexPattern: 'v11-log-*', within: '2m', count: 1, with: [], or: [] }])}
239239
className="flex w-full items-center justify-center gap-1.5 rounded-md border border-dashed border-border py-2 text-xs text-muted-foreground hover:border-primary/40 hover:text-foreground"
240240
>
241241
<Plus size={13} /> {t('alertingRules.editor.addStep')}
@@ -256,7 +256,7 @@ export function RuleForm({ form, setForm, dataTypeOptions, t }: { form: RuleForm
256256
)
257257
}
258258

259-
/* ─── afterEvents builder pieces ───────────────────────────────────────── */
259+
/* ─── correlation steps builder pieces ────────────────────────────────── */
260260

261261
function StepCard({ step, index, onChange, onRemove, t }: { step: AfterStep; index: number; onChange: (s: AfterStep) => void; onRemove: () => void; t: TFunction }) {
262262
const patch = (p: Partial<AfterStep>) => onChange({ ...step, ...p })

frontend/src/features/alerting-rules/lib/rule-yaml.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export function ruleFormToYaml(f: RuleFormState): string {
7575
if (f.description) doc.description = f.description
7676
doc.where = f.definition
7777

78-
const steps = f.afterEvents
78+
const steps = f.correlation
7979
.filter((s) => s.indexPattern.trim())
8080
.map((s) => {
8181
const step: Record<string, unknown> = {
@@ -88,7 +88,7 @@ export function ruleFormToYaml(f: RuleFormState): string {
8888
if (ors.length) step.or = ors.map((g) => ({ with: condsToYaml(g.with) }))
8989
return step
9090
})
91-
if (steps.length) doc.afterEvents = steps
91+
if (steps.length) doc.correlation = steps
9292
if (f.groupBy.length) doc.groupBy = f.groupBy
9393
if (f.deduplicateBy.length) doc.deduplicateBy = f.deduplicateBy
9494

@@ -126,7 +126,7 @@ export function yamlToRuleForm(content: string): RuleParseResult {
126126
ruleActive: doc.active !== false,
127127
dataTypes: strArray(doc.dataTypes),
128128
definition: str(where),
129-
afterEvents: parseSteps(doc.afterEvents),
129+
correlation: parseSteps(doc.correlation ?? doc.afterEvents),
130130
groupBy: strArray(doc.groupBy),
131131
deduplicateBy: strArray(doc.deduplicateBy),
132132
references: strArray(doc.references),

frontend/src/features/alerting-rules/pages/AlertingRulesPage.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ function RuleDrawer({
529529
}
530530

531531
function RuleView({ rule, df, t }: { rule: CorrelationRule; df: ReturnType<typeof useDateFormat>; t: TFunction }) {
532-
const steps = ruleToForm(rule).afterEvents
532+
const steps = ruleToForm(rule).correlation
533533
return (
534534
<div className="space-y-4">
535535
{rule.description && <Section title={t('alertingRules.view.description')}><RuleDescription text={rule.description} /></Section>}
@@ -547,7 +547,7 @@ function RuleView({ rule, df, t }: { rule: CorrelationRule; df: ReturnType<typeo
547547
<DefinitionView definition={rule.definition} t={t} />
548548
</Section>
549549
{steps.length > 0 && (
550-
<Section title={t('alertingRules.view.afterEvents')}>
550+
<Section title={t('alertingRules.view.correlationSteps')}>
551551
<AfterEventsView steps={steps} t={t} />
552552
</Section>
553553
)}
@@ -607,7 +607,7 @@ function CelNodeView({ node, t, depth }: { node: CelNode; t: TFunction; depth: n
607607
}
608608

609609
/** Read-only cards for the correlation (after-events) steps. */
610-
function AfterEventsView({ steps, t }: { steps: ReturnType<typeof ruleToForm>['afterEvents']; t: TFunction }) {
610+
function AfterEventsView({ steps, t }: { steps: ReturnType<typeof ruleToForm>['correlation']; t: TFunction }) {
611611
return (
612612
<div className="space-y-2">
613613
{steps.map((s, i) => (

frontend/src/features/alerting-rules/services/alerting-rules-http.service.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,10 @@ export interface ImportRulesResponse {
4646

4747
/**
4848
* A correlation (alerting) rule. Identity is `relPath` (YAML-direct). `definition`
49-
* is the CEL `where` condition (a JSON-encoded string); `afterEvents`/`references`/
49+
* is the CEL `where` condition (a JSON-encoded string); `correlation`/`references`/
5050
* `groupBy`/`deduplicateBy` are arbitrary JSON the backend stores verbatim.
51+
* `afterEvents` is the legacy name for `correlation` — still populated by older
52+
* backends/rule files, read as a fallback.
5153
*/
5254
export interface CorrelationRule {
5355
relPath: string
@@ -61,7 +63,8 @@ export interface CorrelationRule {
6163
description: string
6264
references: unknown
6365
definition: string
64-
afterEvents: unknown
66+
correlation?: unknown
67+
afterEvents?: unknown // legacy: pre-rename field name
6568
groupBy: unknown
6669
deduplicateBy: unknown
6770
ruleLastUpdate?: string
@@ -82,7 +85,7 @@ export interface SaveRuleInput {
8285
description: string
8386
references: unknown
8487
definition: string
85-
afterEvents: unknown
88+
correlation: unknown
8689
groupBy: unknown
8790
deduplicateBy: unknown
8891
ruleActive: boolean

frontend/src/shared/i18n/locales/de.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4213,7 +4213,7 @@
42134213
"updated": "Aktualisiert",
42144214
"relPath": "Pfad",
42154215
"definition": "Bedingung (CEL)",
4216-
"afterEvents": "Korrelationsschritte",
4216+
"correlationSteps": "Korrelationsschritte",
42174217
"correlation": "Korrelation",
42184218
"groupBy": "Gruppieren nach",
42194219
"deduplicateBy": "Deduplizieren nach",
@@ -4236,8 +4236,8 @@
42364236
"definitionSection": "Definition",
42374237
"where": "Bedingung (CEL)",
42384238
"whereHint": "CEL-Ausdruck je Ereignis ausgewertet",
4239-
"afterEvents": "Korrelationsschritte (afterEvents)",
4240-
"afterEventsHint": "JSON-Array",
4239+
"correlationSteps": "Korrelationsschritte",
4240+
"correlationStepsHint": "JSON-Array",
42414241
"jsonArray": "JSON-Array",
42424242
"nameRequired": "Name ist erforderlich",
42434243
"definitionRequired": "Die Bedingung ist erforderlich",

frontend/src/shared/i18n/locales/en.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4465,7 +4465,7 @@
44654465
"updated": "Updated",
44664466
"relPath": "Path",
44674467
"definition": "Condition (CEL)",
4468-
"afterEvents": "Correlation steps",
4468+
"correlationSteps": "Correlation steps",
44694469
"correlation": "Correlation",
44704470
"groupBy": "Group by",
44714471
"deduplicateBy": "Deduplicate by",
@@ -4488,8 +4488,8 @@
44884488
"definitionSection": "Definition",
44894489
"where": "Condition (CEL)",
44904490
"whereHint": "CEL expression evaluated per event",
4491-
"afterEvents": "Correlation steps (afterEvents)",
4492-
"afterEventsHint": "JSON array",
4491+
"correlationSteps": "Correlation steps",
4492+
"correlationStepsHint": "JSON array",
44934493
"jsonArray": "JSON array",
44944494
"nameRequired": "Name is required",
44954495
"definitionRequired": "The condition is required",

frontend/src/shared/i18n/locales/es.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4389,7 +4389,7 @@
43894389
"updated": "Actualizada",
43904390
"relPath": "Ruta",
43914391
"definition": "Condición (CEL)",
4392-
"afterEvents": "Pasos de correlación",
4392+
"correlationSteps": "Pasos de correlación",
43934393
"correlation": "Correlación",
43944394
"groupBy": "Agrupar por",
43954395
"deduplicateBy": "Deduplicar por",
@@ -4412,8 +4412,8 @@
44124412
"definitionSection": "Definición",
44134413
"where": "Condición (CEL)",
44144414
"whereHint": "Expresión CEL evaluada por evento",
4415-
"afterEvents": "Pasos de correlación (afterEvents)",
4416-
"afterEventsHint": "array JSON",
4415+
"correlationSteps": "Pasos de correlación",
4416+
"correlationStepsHint": "array JSON",
44174417
"jsonArray": "array JSON",
44184418
"nameRequired": "El nombre es obligatorio",
44194419
"definitionRequired": "La condición es obligatoria",

frontend/src/shared/i18n/locales/fr.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4213,7 +4213,7 @@
42134213
"updated": "Mise à jour",
42144214
"relPath": "Chemin",
42154215
"definition": "Condition (CEL)",
4216-
"afterEvents": "Étapes de corrélation",
4216+
"correlationSteps": "Étapes de corrélation",
42174217
"correlation": "Corrélation",
42184218
"groupBy": "Grouper par",
42194219
"deduplicateBy": "Dédupliquer par",
@@ -4236,8 +4236,8 @@
42364236
"definitionSection": "Définition",
42374237
"where": "Condition (CEL)",
42384238
"whereHint": "Expression CEL évaluée par événement",
4239-
"afterEvents": "Étapes de corrélation (afterEvents)",
4240-
"afterEventsHint": "tableau JSON",
4239+
"correlationSteps": "Étapes de corrélation",
4240+
"correlationStepsHint": "tableau JSON",
42414241
"jsonArray": "tableau JSON",
42424242
"nameRequired": "Le nom est requis",
42434243
"definitionRequired": "La condition est requise",

frontend/src/shared/i18n/locales/it.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4213,7 +4213,7 @@
42134213
"updated": "Aggiornata",
42144214
"relPath": "Percorso",
42154215
"definition": "Condizione (CEL)",
4216-
"afterEvents": "Passi di correlazione",
4216+
"correlationSteps": "Passi di correlazione",
42174217
"correlation": "Correlazione",
42184218
"groupBy": "Raggruppa per",
42194219
"deduplicateBy": "Deduplica per",
@@ -4236,8 +4236,8 @@
42364236
"definitionSection": "Definizione",
42374237
"where": "Condizione (CEL)",
42384238
"whereHint": "Espressione CEL valutata per evento",
4239-
"afterEvents": "Passi di correlazione (afterEvents)",
4240-
"afterEventsHint": "array JSON",
4239+
"correlationSteps": "Passi di correlazione",
4240+
"correlationStepsHint": "array JSON",
42414241
"jsonArray": "array JSON",
42424242
"nameRequired": "Il nome è obbligatorio",
42434243
"definitionRequired": "La condizione è obbligatoria",

frontend/src/shared/i18n/locales/pt.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4389,7 +4389,7 @@
43894389
"updated": "Atualizada",
43904390
"relPath": "Caminho",
43914391
"definition": "Condição (CEL)",
4392-
"afterEvents": "Passos de correlação",
4392+
"correlationSteps": "Passos de correlação",
43934393
"correlation": "Correlação",
43944394
"groupBy": "Agrupar por",
43954395
"deduplicateBy": "Deduplicar por",
@@ -4412,8 +4412,8 @@
44124412
"definitionSection": "Definição",
44134413
"where": "Condição (CEL)",
44144414
"whereHint": "Expressão CEL avaliada por evento",
4415-
"afterEvents": "Passos de correlação (afterEvents)",
4416-
"afterEventsHint": "array JSON",
4415+
"correlationSteps": "Passos de correlação",
4416+
"correlationStepsHint": "array JSON",
44174417
"jsonArray": "array JSON",
44184418
"nameRequired": "O nome é obrigatório",
44194419
"definitionRequired": "A condição é obrigatória",

0 commit comments

Comments
 (0)