@@ -12,7 +12,12 @@ import uuid from 'uuid';
1212import { addSpaceIdToPath } from '@kbn/spaces-plugin/server' ;
1313import { KibanaRequest , Logger } from '@kbn/core/server' ;
1414import { ConcreteTaskInstance , throwUnrecoverableError } from '@kbn/task-manager-plugin/server' ;
15- import { IEvent , SAVED_OBJECT_REL_PRIMARY } from '@kbn/event-log-plugin/server' ;
15+ import {
16+ IEvent ,
17+ SAVED_OBJECT_REL_PRIMARY ,
18+ millisToNanos ,
19+ nanosToMillis ,
20+ } from '@kbn/event-log-plugin/server' ;
1621import { TaskRunnerContext } from './task_runner_factory' ;
1722import { createExecutionHandler , ExecutionHandler } from './create_execution_handler' ;
1823import { Alert , createAlertFactory } from '../alert' ;
@@ -803,9 +808,7 @@ export class TaskRunner<
803808
804809 // Copy duration into execution status if available
805810 if ( null != event . event ?. duration ) {
806- executionStatus . lastDuration = Math . round (
807- Number ( BigInt ( event . event ?. duration ) / BigInt ( Millis2Nanos ) )
808- ) ;
811+ executionStatus . lastDuration = nanosToMillis ( event . event ?. duration ) ;
809812 monitoringHistory . duration = executionStatus . lastDuration ;
810813 }
811814
@@ -1066,8 +1069,7 @@ function trackAlertDurations<
10661069 : currentAlerts [ id ] . getState ( ) ;
10671070 const durationInMs =
10681071 new Date ( currentTime ) . valueOf ( ) - new Date ( state . start as string ) . valueOf ( ) ;
1069- const durationInNanoStr = durationInMs !== 0 ? `${ durationInMs } 000000` : '0' ;
1070- const duration = state . start ? durationInNanoStr : undefined ;
1072+ const duration = state . start ? millisToNanos ( durationInMs ) : undefined ;
10711073 currentAlerts [ id ] . replaceState ( {
10721074 ...state ,
10731075 ...( state . start ? { start : state . start } : { } ) ,
@@ -1080,8 +1082,7 @@ function trackAlertDurations<
10801082 const state = recoveredAlerts [ id ] . getState ( ) ;
10811083 const durationInMs =
10821084 new Date ( currentTime ) . valueOf ( ) - new Date ( state . start as string ) . valueOf ( ) ;
1083- const durationInNanoStr = durationInMs !== 0 ? `${ durationInMs } 000000` : '0' ;
1084- const duration = state . start ? durationInNanoStr : undefined ;
1085+ const duration = state . start ? millisToNanos ( durationInMs ) : undefined ;
10851086 recoveredAlerts [ id ] . replaceState ( {
10861087 ...state ,
10871088 ...( duration ? { duration } : { } ) ,
0 commit comments