
    &`i                         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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 d dlmZ  e j        e          ZdZde fdZ!de de fdZ"ddZ#dS )    N)build_address)LOGGING_ROTATE_BACKUP_COUNTLOGGING_ROTATE_BYTES)try_to_create_directory)ray_constants)setup_component_logger)get_node_ip_address)	GcsClient)AutoscalingConfigProducer)Monitor)KubeRayConfigReader)is_autoscaler_v2   returnc                      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     /home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/ray/autoscaler/_private/kuberay/run_autoscaler.py_get_log_dirr      s<    7<<**,,"1  r   cluster_namecluster_namespacec                    t                      }t          |d          }	 	 t          j        ddd|dg           t                              d           nR# t          j        $ r? t                              dt           d	           t          j
        t                     Y nw xY wt                       t          | |          }t          |          }t          d|
          rGddlm}  ||j        t%          |          t'                      |                                           dS t+          |j        ||d                                           dS )zFWait until the Ray head container is ready. Then start the autoscaler.i  Tr   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	   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$   	MonitorV2s          r   run_kuberay_autoscalerr<   #   s   !##G..K"	" !"*   KKIJJJ, 	" 	" 	"NNV)VVV   Jy!!!!!		"".  #<'# # ;''J$:FFF LLLLLL	&-.IJJ NN		
 	
 	

 #%%%%%&  ; #
	
 
	
 
	
 #%%%%%s   3A AB#"B#c                  H   t                      } t          |            t          t          j        t          j        | t          j        t          t                     t          j
        t          j                                                  }t          j                    }|                    t          j        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_NAMEr   r   logginggetLevelNameupper_StderrHandlersetFormatter	FormattersetLevelroot
addHandler)r(   levelstderr_handlers      r   r5   r5   ^   s     nnGG$$$ #0$24&0     !;!A!A!C!CDDE+--N 1-2M N NOOOE"""L%   LN+++++r   )r   N)$rF   r   r,   r3   r   ray._common.network_utilsr   ray._common.ray_constantsr   r   ray._common.utilsr   ray._privater   ray._private.ray_loggingr   ray._private.servicesr	   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.   r2   strr   r<   r5   r   r   r   <module>r_      s    				      



 3 3 3 3 3 3        6 5 5 5 5 5 & & & & & & ; ; ; ; ; ; 5 5 5 5 5 5 ! ! ! ! ! ! X X X X X X 3 3 3 3 3 3 I I I I I I 4 4 4 4 4 4		8	$	$	c    8 8 8 8 8 8v, , , , , ,r   