o
    bi<                     @   s   d dl Z d dlZd dlZd dlZd dlZd dlmZ d dlmZ d dl	m
Z
 d dlmZ d dlmZ d dlmZ d dlmZ d d	lmZ d d
lmZ e eZdZdefddZdedefddZdddZdS )    N)ray_constants)setup_component_logger)get_node_ip_address)try_to_create_directory)	GcsClient)AutoscalingConfigProducer)Monitor)KubeRayConfigReader)is_autoscaler_v2   returnc                   C   s   t jtjj tjjj	dS )Nlogs)
ospathjoinray_commonutilsget_ray_temp_dir_privater   SESSION_LATEST r   r   b/home/ubuntu/.local/lib/python3.10/site-packages/ray/autoscaler/_private/kuberay/run_autoscaler.py_get_log_dir   s
   
r   cluster_namecluster_namespacec                 C   s   t  }| d}	 ztddd|dg td W n tjy2   tdt d	 t	t Y nw q	t
  t| |}t|}td|d
r\ddlm} ||jt|t |d  dS t|j||dd  dS )zFWait until the Ray head container is ready. Then start the autoscaler.z:6379Tr   zhealth-checkz	--addressz--skip-version-checkz/The Ray head is ready. Starting the autoscaler.z/The Ray head is not ready. Will check again in z	 seconds.)fetch_from_server
gcs_clientr   )AutoscalerMonitor)addressconfig_readerlog_dir
monitor_ipF)r   autoscaling_configr"   retry_on_failureN)r   
subprocess
check_callloggerinfoCalledProcessErrorwarning	BACKOFF_Stimesleep_setup_loggingr   r   r
   ray.autoscaler.v2.monitorr   r   r	   r   runr   )r   r   head_ipray_addressautoscaling_config_producerr   	MonitorV2r   r   r   run_kuberay_autoscaler   sT   

	



r5   c                  C   s|   t  } t|  ttjtj| tjtjtjd t	
tj }t	 }|t	tj || t	j| t	j| dS )zLog to autoscaler log file
    (typically, /tmp/ray/session_latest/logs/monitor.*)

    Also log to pod stdout (logs viewable with `kubectl logs <head-pod> -c autoscaler`).
    )logging_levellogging_formatr!   filename	max_bytesbackup_countN)r   r   r   r   LOGGER_LEVELLOGGER_FORMATMONITOR_LOG_FILE_NAMELOGGING_ROTATE_BYTESLOGGING_ROTATE_BACKUP_COUNTlogginggetLevelNameupper_StderrHandlersetFormatter	FormattersetLevelroot
addHandler)r!   levelstderr_handlerr   r   r   r.   Y   s    
r.   )r   N)r@   r   r%   r,   r   ray._privater   ray._private.ray_loggingr   ray._private.servicesr   ray._common.utilsr   ray._rayletr   2ray.autoscaler._private.kuberay.autoscaling_configr   ray.autoscaler._private.monitorr   )ray.autoscaler.v2.instance_manager.configr	   ray.autoscaler.v2.utilsr
   	getLogger__name__r'   r+   strr   r5   r.   r   r   r   r   <module>   s&    
;