import { schema , TypeOf } from '@kbn/config-schema' ; export const MAX_WORKERS_LIMIT = 100 ; export const DEFAULT_MAX_WORKERS = 10 ; export const DEFAULT_POLL_INTERVAL = 3000 ; export const DEFAULT_MAX_POLL_INACTIVITY_CYCLES = 10 ; export const DEFAULT_VERSION_CONFLICT_THRESHOLD = 80 ; export const DEFAULT_MAX_EPHEMERAL_REQUEST_CAPACITY = MAX_WORKERS_LIMIT ; export const DEFAULT_MONITORING_REFRESH_RATE = 60 * 1000 ; export const DEFAULT_MONITORING_STATS_RUNNING_AVERGAE_WINDOW = 50 ; export const DEFAULT_MONITORING_STATS_WARN_DELAYED_TASK_START_IN_SECONDS = 60 ; export const taskExecutionFailureThresholdSchema = schema . object ( { error_threshold : schema . number ( { defaultValue : 90 , min : 0 , } ) , warn_threshold : schema . number ( { defaultValue : 80 , min : 0 , } ) , } , { validate ( config ) { if ( config . error_threshold < config . warn_threshold ) { return `warn_threshold (${ config . warn_threshold }) must be less than, or equal to, error_threshold (${ config . error_threshold })` ; } } , } ) ; export const configSchema = schema . object ( { max_attempts : schema . number ( { defaultValue : 3 , min : 1 , } ) , poll_interval : schema . number ( { defaultValue : DEFAULT_POLL_INTERVAL , min : 100 , } ) , max_poll_inactivity_cycles : schema . number ( { defaultValue : DEFAULT_MAX_POLL_INACTIVITY_CYCLES , min : 1 , } ) , request_capacity : schema . number ( { defaultValue : 1000 , min : 1 , } ) , max_workers : schema . number ( { defaultValue : DEFAULT_MAX_WORKERS , min : 1 , } ) , version_conflict_threshold : schema . number ( { defaultValue : DEFAULT_VERSION_CONFLICT_THRESHOLD , min : 50 , max : 100 , } ) , monitored_stats_required_freshness : schema . number ( { defaultValue : ( config ? ) => ( ( config as { poll_interval : number ; } ) ?. poll_interval ?? DEFAULT_POLL_INTERVAL ) + 1000 , min : 100 , } ) , monitored_aggregated_stats_refresh_rate : schema . number ( { defaultValue : DEFAULT_MONITORING_REFRESH_RATE , min : 5000 , } ) , monitored_stats_running_average_window : schema . number ( { defaultValue : DEFAULT_MONITORING_STATS_RUNNING_AVERGAE_WINDOW , max : 100 , min : 10 , } ) , monitored_task_execution_thresholds : schema . object ( { default : taskExecutionFailureThresholdSchema , custom : schema . recordOf ( schema . string ( ) , taskExecutionFailureThresholdSchema , { defaultValue : { } , } ) , } ) , monitored_stats_health_verbose_log : schema . object ( { enabled : schema . boolean ( { defaultValue : false } ) , warn_delayed_task_start_in_seconds : schema . number ( { defaultValue : DEFAULT_MONITORING_STATS_WARN_DELAYED_TASK_START_IN_SECONDS , } ) , } ) , ephemeral_tasks : schema . object ( { enabled : schema . boolean ( { defaultValue : false } ) , request_capacity : schema . number ( { defaultValue : 10 , min : 1 , max : DEFAULT_MAX_EPHEMERAL_REQUEST_CAPACITY , } ) , } ) , unsafe : schema . object ( { exclude_task_types : schema . arrayOf ( schema . string ( ) , { defaultValue : [ ] } ) , } ) , } , { validate : ( config ) => { if ( config . monitored_stats_required_freshness && config . poll_interval && config . monitored_stats_required_freshness < config . poll_interval ) { return `The specified monitored_stats_required_freshness (${ config . monitored_stats_required_freshness }) is invalid, as it is below the poll_interval (${ config . poll_interval })` ; } } , } ) ; export type TaskManagerConfig = TypeOf < typeof configSchema > ; export type TaskExecutionFailureThreshold = TypeOf < typeof taskExecutionFailureThresholdSchema > ;