@@ -31,12 +31,15 @@ import {
3131 ALERT_RULE_EXECUTION_TIMESTAMP ,
3232 ALERT_PREVIOUS_ACTION_GROUP ,
3333 ALERT_SEVERITY_IMPROVING ,
34+ ALERT_RULE_EXECUTION_UUID ,
3435} from '@kbn/rule-data-utils' ;
3536import {
3637 alertRule ,
3738 existingFlattenedActiveAlert ,
3839 existingExpandedActiveAlert ,
40+ rule ,
3941} from './test_fixtures' ;
42+ import { omit } from 'lodash' ;
4043
4144for ( const flattened of [ true , false ] ) {
4245 const existingAlert = flattened ? existingFlattenedActiveAlert : existingExpandedActiveAlert ;
@@ -63,9 +66,10 @@ for (const flattened of [true, false]) {
6366 kibanaVersion : '8.9.0' ,
6467 } )
6568 ) . toEqual ( {
66- ...alertRule ,
6769 [ TIMESTAMP ] : '2023-03-29T12:27:28.159Z' ,
6870 [ ALERT_RULE_EXECUTION_TIMESTAMP ] : '2023-03-29T12:27:28.159Z' ,
71+ // @ts -ignore
72+ [ ALERT_RULE_EXECUTION_UUID ] : '5f6aa57d-3e22-484e-bae8-cbed868f4d28' ,
6973 [ EVENT_ACTION ] : 'close' ,
7074 [ ALERT_ACTION_GROUP ] : 'recovered' ,
7175 [ ALERT_CONSECUTIVE_MATCHES ] : 0 ,
@@ -80,11 +84,13 @@ for (const flattened of [true, false]) {
8084 [ ALERT_START ] : '2023-03-28T12:27:28.159Z' ,
8185 [ ALERT_END ] : '2023-03-30T12:27:28.159Z' ,
8286 [ ALERT_TIME_RANGE ] : { gte : '2023-03-28T12:27:28.159Z' , lte : '2023-03-30T12:27:28.159Z' } ,
87+ // @ts -ignore
8388 [ SPACE_IDS ] : [ 'default' ] ,
8489 [ VERSION ] : '8.9.0' ,
8590 [ TAGS ] : [ 'rule-' , '-tags' ] ,
8691 ...( flattened
8792 ? {
93+ ...alertRule ,
8894 [ EVENT_KIND ] : 'signal' ,
8995 [ ALERT_INSTANCE_ID ] : 'alert-A' ,
9096 [ ALERT_UUID ] : 'abcdefg' ,
@@ -96,14 +102,15 @@ for (const flattened of [true, false]) {
96102 kibana : {
97103 alert : {
98104 instance : { id : 'alert-A' } ,
105+ rule : omit ( rule , 'execution' ) ,
99106 uuid : 'abcdefg' ,
100107 } ,
101108 } ,
102109 } ) ,
103110 } ) ;
104111 } ) ;
105112
106- test ( 'should return alert document with recovery status and updated rule data if rule definition has changed' , ( ) => {
113+ test ( 'should return alert document with recovery status and but not update rule data if rule definition has changed' , ( ) => {
107114 const legacyAlert = new LegacyAlert < { } , { } , 'default' > ( 'alert-A' , {
108115 meta : { uuid : 'abcdefg' } ,
109116 } ) ;
@@ -131,9 +138,10 @@ for (const flattened of [true, false]) {
131138 kibanaVersion : '8.9.0' ,
132139 } )
133140 ) . toEqual ( {
134- ...updatedRule ,
135141 [ TIMESTAMP ] : '2023-03-29T12:27:28.159Z' ,
136142 [ ALERT_RULE_EXECUTION_TIMESTAMP ] : '2023-03-29T12:27:28.159Z' ,
143+ // @ts -ignore
144+ [ ALERT_RULE_EXECUTION_UUID ] : '5f6aa57d-3e22-484e-bae8-cbed868f4d28' ,
137145 [ EVENT_ACTION ] : 'close' ,
138146 [ ALERT_ACTION_GROUP ] : 'NoLongerActive' ,
139147 [ ALERT_CONSECUTIVE_MATCHES ] : 0 ,
@@ -148,11 +156,13 @@ for (const flattened of [true, false]) {
148156 [ ALERT_START ] : '2023-03-28T12:27:28.159Z' ,
149157 [ ALERT_END ] : '2023-03-30T12:27:28.159Z' ,
150158 [ ALERT_TIME_RANGE ] : { gte : '2023-03-28T12:27:28.159Z' , lte : '2023-03-30T12:27:28.159Z' } ,
159+ // @ts -ignore
151160 [ SPACE_IDS ] : [ 'default' ] ,
152161 [ VERSION ] : '8.9.0' ,
153162 [ TAGS ] : [ 'rule-' , '-tags' ] ,
154163 ...( flattened
155164 ? {
165+ ...alertRule ,
156166 [ EVENT_KIND ] : 'signal' ,
157167 [ ALERT_INSTANCE_ID ] : 'alert-A' ,
158168 [ ALERT_UUID ] : 'abcdefg' ,
@@ -164,6 +174,7 @@ for (const flattened of [true, false]) {
164174 kibana : {
165175 alert : {
166176 instance : { id : 'alert-A' } ,
177+ rule : omit ( rule , 'execution' ) ,
167178 uuid : 'abcdefg' ,
168179 } ,
169180 } ,
@@ -226,12 +237,13 @@ for (const flattened of [true, false]) {
226237 kibanaVersion : '8.9.0' ,
227238 } )
228239 ) . toEqual ( {
229- ...alertRule ,
230240 count : 2 ,
231241 url : `https://url2` ,
232242 'kibana.alert.nested_field' : 2 ,
233243 [ TIMESTAMP ] : '2023-03-29T12:27:28.159Z' ,
234244 [ ALERT_RULE_EXECUTION_TIMESTAMP ] : '2023-03-29T12:27:28.159Z' ,
245+ // @ts -ignore
246+ [ ALERT_RULE_EXECUTION_UUID ] : '5f6aa57d-3e22-484e-bae8-cbed868f4d28' ,
235247 [ EVENT_ACTION ] : 'close' ,
236248 [ ALERT_ACTION_GROUP ] : 'NoLongerActive' ,
237249 [ ALERT_CONSECUTIVE_MATCHES ] : 0 ,
@@ -246,11 +258,13 @@ for (const flattened of [true, false]) {
246258 [ ALERT_START ] : '2023-03-28T12:27:28.159Z' ,
247259 [ ALERT_END ] : '2023-03-30T12:27:28.159Z' ,
248260 [ ALERT_TIME_RANGE ] : { gte : '2023-03-28T12:27:28.159Z' , lte : '2023-03-30T12:27:28.159Z' } ,
261+ // @ts -ignore
249262 [ SPACE_IDS ] : [ 'default' ] ,
250263 [ VERSION ] : '8.9.0' ,
251264 [ TAGS ] : [ 'rule-' , '-tags' ] ,
252265 ...( flattened
253266 ? {
267+ ...alertRule ,
254268 [ EVENT_KIND ] : 'signal' ,
255269 [ ALERT_INSTANCE_ID ] : 'alert-A' ,
256270 [ ALERT_UUID ] : 'abcdefg' ,
@@ -262,6 +276,7 @@ for (const flattened of [true, false]) {
262276 kibana : {
263277 alert : {
264278 instance : { id : 'alert-A' } ,
279+ rule : omit ( rule , 'execution' ) ,
265280 uuid : 'abcdefg' ,
266281 } ,
267282 } ,
@@ -291,9 +306,10 @@ for (const flattened of [true, false]) {
291306 kibanaVersion : '8.9.0' ,
292307 } )
293308 ) . toEqual ( {
294- ...alertRule ,
295309 [ TIMESTAMP ] : '2023-03-29T12:27:28.159Z' ,
296310 [ ALERT_RULE_EXECUTION_TIMESTAMP ] : '2030-12-15T02:44:13.124Z' ,
311+ // @ts -ignore
312+ [ ALERT_RULE_EXECUTION_UUID ] : '5f6aa57d-3e22-484e-bae8-cbed868f4d28' ,
297313 [ EVENT_ACTION ] : 'close' ,
298314 [ ALERT_ACTION_GROUP ] : 'recovered' ,
299315 [ ALERT_CONSECUTIVE_MATCHES ] : 0 ,
@@ -308,11 +324,13 @@ for (const flattened of [true, false]) {
308324 [ ALERT_START ] : '2023-03-28T12:27:28.159Z' ,
309325 [ ALERT_END ] : '2023-03-30T12:27:28.159Z' ,
310326 [ ALERT_TIME_RANGE ] : { gte : '2023-03-28T12:27:28.159Z' , lte : '2023-03-30T12:27:28.159Z' } ,
327+ // @ts -ignore
311328 [ SPACE_IDS ] : [ 'default' ] ,
312329 [ VERSION ] : '8.9.0' ,
313330 [ TAGS ] : [ 'rule-' , '-tags' ] ,
314331 ...( flattened
315332 ? {
333+ ...alertRule ,
316334 [ EVENT_KIND ] : 'signal' ,
317335 [ ALERT_INSTANCE_ID ] : 'alert-A' ,
318336 [ ALERT_UUID ] : 'abcdefg' ,
@@ -324,6 +342,7 @@ for (const flattened of [true, false]) {
324342 kibana : {
325343 alert : {
326344 instance : { id : 'alert-A' } ,
345+ rule : omit ( rule , 'execution' ) ,
327346 uuid : 'abcdefg' ,
328347 } ,
329348 } ,
@@ -394,12 +413,13 @@ for (const flattened of [true, false]) {
394413 kibanaVersion : '8.9.0' ,
395414 } )
396415 ) . toEqual ( {
397- ...alertRule ,
398416 count : 2 ,
399417 url : `https://url2` ,
400418 'kibana.alert.nested_field' : 2 ,
401419 [ TIMESTAMP ] : '2023-03-29T12:27:28.159Z' ,
402420 [ ALERT_RULE_EXECUTION_TIMESTAMP ] : '2023-03-29T12:27:28.159Z' ,
421+ // @ts -ignore
422+ [ ALERT_RULE_EXECUTION_UUID ] : '5f6aa57d-3e22-484e-bae8-cbed868f4d28' ,
403423 [ EVENT_ACTION ] : 'close' ,
404424 [ ALERT_ACTION_GROUP ] : 'NoLongerActive' ,
405425 [ ALERT_CONSECUTIVE_MATCHES ] : 0 ,
@@ -414,11 +434,13 @@ for (const flattened of [true, false]) {
414434 [ ALERT_START ] : '2023-03-28T12:27:28.159Z' ,
415435 [ ALERT_END ] : '2023-03-30T12:27:28.159Z' ,
416436 [ ALERT_TIME_RANGE ] : { gte : '2023-03-28T12:27:28.159Z' , lte : '2023-03-30T12:27:28.159Z' } ,
437+ // @ts -ignore
417438 [ SPACE_IDS ] : [ 'default' ] ,
418439 [ VERSION ] : '8.9.0' ,
419440 [ TAGS ] : [ '-tags' , 'reported-recovery-tag' , 'active-alert-tag' , 'rule-' ] ,
420441 ...( flattened
421442 ? {
443+ ...alertRule ,
422444 [ EVENT_KIND ] : 'signal' ,
423445 [ ALERT_INSTANCE_ID ] : 'alert-A' ,
424446 [ ALERT_UUID ] : 'abcdefg' ,
@@ -430,6 +452,7 @@ for (const flattened of [true, false]) {
430452 kibana : {
431453 alert : {
432454 instance : { id : 'alert-A' } ,
455+ rule : omit ( rule , 'execution' ) ,
433456 uuid : 'abcdefg' ,
434457 } ,
435458 } ,
@@ -498,12 +521,13 @@ for (const flattened of [true, false]) {
498521 kibanaVersion : '8.9.0' ,
499522 } )
500523 ) . toEqual ( {
501- ...alertRule ,
502524 count : 2 ,
503525 url : `https://url2` ,
504526 'kibana.alert.nested_field' : 2 ,
505527 [ TIMESTAMP ] : '2023-03-29T12:27:28.159Z' ,
506528 [ ALERT_RULE_EXECUTION_TIMESTAMP ] : '2023-03-29T12:27:28.159Z' ,
529+ // @ts -ignore
530+ [ ALERT_RULE_EXECUTION_UUID ] : '5f6aa57d-3e22-484e-bae8-cbed868f4d28' ,
507531 [ EVENT_ACTION ] : 'close' ,
508532 [ ALERT_ACTION_GROUP ] : 'NoLongerActive' ,
509533 [ ALERT_CONSECUTIVE_MATCHES ] : 0 ,
@@ -518,11 +542,13 @@ for (const flattened of [true, false]) {
518542 [ ALERT_START ] : '2023-03-28T12:27:28.159Z' ,
519543 [ ALERT_END ] : '2023-03-30T12:27:28.159Z' ,
520544 [ ALERT_TIME_RANGE ] : { gte : '2023-03-28T12:27:28.159Z' , lte : '2023-03-30T12:27:28.159Z' } ,
545+ // @ts -ignore
521546 [ SPACE_IDS ] : [ 'default' ] ,
522547 [ VERSION ] : '8.9.0' ,
523548 [ TAGS ] : [ 'rule-' , '-tags' ] ,
524549 ...( flattened
525550 ? {
551+ ...alertRule ,
526552 [ EVENT_KIND ] : 'signal' ,
527553 [ ALERT_INSTANCE_ID ] : 'alert-A' ,
528554 [ ALERT_UUID ] : 'abcdefg' ,
@@ -534,6 +560,7 @@ for (const flattened of [true, false]) {
534560 kibana : {
535561 alert : {
536562 instance : { id : 'alert-A' } ,
563+ rule : omit ( rule , 'execution' ) ,
537564 uuid : 'abcdefg' ,
538565 } ,
539566 } ,
@@ -601,12 +628,13 @@ for (const flattened of [true, false]) {
601628 } ,
602629 } )
603630 ) . toEqual ( {
604- ...alertRule ,
605631 count : 2 ,
606632 url : `https://url2` ,
607633 'kibana.alert.deeply.nested_field' : 2 ,
608634 [ TIMESTAMP ] : '2023-03-29T12:27:28.159Z' ,
609635 [ ALERT_RULE_EXECUTION_TIMESTAMP ] : '2023-03-29T12:27:28.159Z' ,
636+ // @ts -ignore
637+ [ ALERT_RULE_EXECUTION_UUID ] : '5f6aa57d-3e22-484e-bae8-cbed868f4d28' ,
610638 [ EVENT_ACTION ] : 'close' ,
611639 [ ALERT_ACTION_GROUP ] : 'NoLongerActive' ,
612640 [ ALERT_CONSECUTIVE_MATCHES ] : 0 ,
@@ -621,11 +649,13 @@ for (const flattened of [true, false]) {
621649 [ ALERT_START ] : '2023-03-28T12:27:28.159Z' ,
622650 [ ALERT_END ] : '2023-03-30T12:27:28.159Z' ,
623651 [ ALERT_TIME_RANGE ] : { gte : '2023-03-28T12:27:28.159Z' , lte : '2023-03-30T12:27:28.159Z' } ,
652+ // @ts -ignore
624653 [ SPACE_IDS ] : [ 'default' ] ,
625654 [ VERSION ] : '8.9.0' ,
626655 [ TAGS ] : [ 'rule-' , '-tags' ] ,
627656 ...( flattened
628657 ? {
658+ ...alertRule ,
629659 [ EVENT_KIND ] : 'signal' ,
630660 [ ALERT_INSTANCE_ID ] : 'alert-A' ,
631661 [ ALERT_UUID ] : 'abcdefg' ,
@@ -637,6 +667,7 @@ for (const flattened of [true, false]) {
637667 kibana : {
638668 alert : {
639669 instance : { id : 'alert-A' } ,
670+ rule : omit ( rule , 'execution' ) ,
640671 uuid : 'abcdefg' ,
641672 } ,
642673 } ,
0 commit comments