h)jddlZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl m Z m Z m Z mZddlmZddlmZddlmZdZGddeZGd d eZGd d eZGd deZGddeZdZGddeZGddeZGddeZ gdZ!dS)N)NoReferenceErrorNoSuchColumnErrorNoSuchTableErrorSQLAlchemyError)LveStatsPluginTerminated) PluginContext) ConfigErrorshamanceZdZfdZxZS)PluginExecutionExceptionc:tj|i|dSNsuper__init__selfargskwargs __class__s /builddir/build/BUILDROOT/lve-stats-4.3.2-1.el9.x86_64/opt/cloudlinux/venv/lib/python3.11/site-packages/lvestats/eventloop/plugin_executors.pyrz!PluginExecutionException.__init__"%$)&)))))__name__ __module__ __qualname__r __classcell__rs@rr r !8*********rr ceZdZfdZxZS)DbRecoveredExceptionc:tj|i|dSrrrs rrzDbRecoveredException.__init__'rrrrs@rr"r"&r rr"ceZdZfdZxZS)DbRecoverFailedExceptionc:tj|i|dSrrrs rrz!DbRecoverFailedException.__init__,rrrrs@rr%r%+r rr%ceZdZfdZxZS)PluginTimeoutExceptionc:tj|i|dSrrrs rrzPluginTimeoutException.__init__1rrrrs@rr(r(0r rr(c(eZdZdiiZdZdZdZdS)PluginExecutorstatsc||_tjd|_ddlm}i|dt _dS)Nzmain_loop.plugin_executorr)get_lve_version)r, LVE_VERSION)configlogging getLoggerloglvestats.lib.commons.funcr.r+initial_lve_data)rr0r.s rrzPluginExecutor.__init__8sZ $%@AA      57GXGX*Y*Y'''rct)z Executes given plugin with provided lve_data. Does not modify lve_data. Returns updated lve_data or throws PluginExecutionException or PluginTimeoutException :param plugin_class: object: :return: NotImplementedError)r plugin_classnowtimeouts rexecutezPluginExecutor.executeAs"###rctrr7rs r terminatezPluginExecutor.terminateKs!###rN)rrrr5rr<r?rrr+r+5sN}ZZZ$$$$$$$$rr+c*eZdZfdZdZdZxZS)SameProcessPluginExecutorct|t||_i|_t j|_dSr) rrrplugin_contextlast_execution_timer+r5copylve_data)rr0rs rrz"SameProcessPluginExecutor.__init__SsM    +F33#% &7<<>> rc tjd}|j|}||_d}t |dt |dd}|r||j|dz }|||kr ||j ||j|<dS#tttf$rf}| d |jn"#t$r} t!| | d} ~ wwxYwt#|d}~wt$$r*}| dt'||d}~wt$r}t'||d}~wwxYwdS)Nz&main_loop.plugin_executor.same_processperiodrMDatabase error during executing plugin that leads to need of db recreation dbzkDatabase error during executing plugin that may indicate the need to recreate db. Please check it manually.)r1r2rE get_instancer:getattrrFgetr<rHrrr exception recover_db BaseExceptionr%r"rr ) rr9r:r;r3plugin_instance time_passedrJexexception_during_recovers rr<z!SameProcessPluginExecutor.executeYs HII-::<HH! (GL(TX4Y4YZZ  N 8 < <\1 M MMK >V{22 ;'' 6669<(6%'79IJ 5 5 5 mnnnk'224444$kkk23KLLRjjk+,,"4" ; ; ; :;;;.r22:  ; ; ;.r22: ;%32sT$B''E3>DC.-D. D 8DD  D E3,%E E3E..E3cdSrr@r>s rr?z#SameProcessPluginExecutor.terminatezs r)rrrrr<r?rrs@rrCrCRsW????? ;;;B       rrCceZdZdZdZdS)ProcessContextctj|_|j|_i|j_|j|_|j|_|j|_ |j|_ |j|_ |j|_ dSr) multiprocessingManagermgr NamespacensrFEventplugin_ready_eventplugin_execution_finished_eventplugin_execution_success_eventdb_error_event have_to_exitexitedr>s rrzProcessContext.__init__s"*,,($$&&&(#"&(.."2"2/3x~~/?/?,.2hnn.>.>+"hnn.. HNN,,hnn&& rc8|jdSr)r\shutdownr>s rr?zProcessContext.terminates rN)rrrrr?r@rrrXrX~s2 ' ' 'rrXceZdZdfd ZeddZedZdZedZedZ dZ d Z ed Z d Z d Zd ZdZxZS)SeparateProcessPluginExecutorNctt|||_d|_d|_dSr)rr profiling_logprocess_contextprocess)rr0rkrs rrz&SeparateProcessPluginExecutor.__init__s6    *# rc  tjtjtjtjtjtjtjtj d} t|}tj } |jds%|jr|j|rt)|dd5}|dt-j|| }|d d |d |d d dddn #1swxYwY|jdS|jd%|j|jj} |jj} || } n#t@$r-} |!tE| Yd} ~ d} ~ wtF$rE} |!d| |j_!|jYd} ~  d} ~ wwxYw| | _tI| dtI| dd}|tK|}d}|jj&}|| |'| dz }|||kr tjtj(tj)|*d| tWj+}| ,||*d| tWj+|z | || <||j_&|j-|jtjtj(tj.n#t^t`tbf$r^} |!d| |j_!|j2|jYd} ~ d} ~ wtf$rF} |!d| | |j_!|jYd} ~ :d} ~ wth$r-|5d| tmj7dYntp$r.}|!dtE|Yd}~d}~wtF$rF} |!d| | |j_!|jYd} ~ d} ~ wwxYw|*d| ||z |j-|jH#tF$r} | |j_!n>#tp$r1}|j9dkrtu| tvr Yd}~Yd} ~ dS|d}~wwxYw|!d|jYd} ~ dSd} ~ wwxYw)Nz!main_loop.plugin_executor.processT)r;za+zutf-8)encodingz'Plugin process profile, internal time: )streamtimerAz)Plugin process profile, cumulative time: cumulativez!Error during instantiating pluginrJrzExecuting plugin %szExecuting plugin %s took %f secrKznDatabase error during executing %s plugin that may indicate the need to recreate db. Please check it manually.zPlugin %s was terminated.z IO Error: %sz-Other exception during execution of plugin %sz$plugin %s will be launched in %f sec z.Exception during execution in separate process)<ossetpgrpsignalSIGTERMri_child_process_sigterm_handlerSIGUSR1_sigusr1_handlerr1r2rr+r5rGr`waitrdis_setrasetopenwritepstatsStats sort_stats print_statsreclearr^r9r:rLr rOstr ExceptionrMfloatrFrNSIGUSR2 _stop_plugindebugrrr<rbSIG_IGNrrrrcrrinfosysexitIOErrorerrno isinstanceEOFError)r0rlprofilerrkr3rErHfr,r9r:rRcerTrJrSrFt0ioees r_in_separate_processz2SeparateProcessPluginExecutor._in_separate_processs  fn&C&bccc fn&C&TUUU CDDf B*622N%6;;==HW J)<AA!ALL &3::<< 'GKKMMM#O!%mTG!L!L!LOPQ !(R S S S(. Xa(H(H(H % 0 0 8 8 D DR H H H !(T U U U % 0 0 > > J J2 N N N OOOOOOOOOOOOOOO(.22444*<AA!ALL  288:::.1> %(, &4&A&A,&O&OOO"MM#b''***HHHH MM"EFFF35O&0#CGGIIIHHHH  '*# (GLRZ\`V{%:%:%! fn6S6`aaa "7FFF!Y[['//999 "C\SWS\S^S^acScddd'FJJLLL'GKKMMM fnfnEEEE-/?AQR!!! &uvvv79*4'6::<<<'GKKMMM *!!! 'BCOQQQ8:*4'GKKMMM 3$$$!P$"W1$V ;ARW1 V !;S"W1"7V W1 V $#U W1 V ;VW1V  AW11 Z< X Y; Y X?3Y;=X??Y1Y;;Zcrtj}|tj||||dSr)cProfileProfileruncallrir)r0rlrkrs r_do_profile_in_separate_processz=SeparateProcessPluginExecutor._do_profile_in_separate_processsD#%%6K(!&  ( ( ( ( (rct|_|jr tjn tj}t j|d|j|j|jf|_ |j dS)Nplugin_process)targetnamer) rXrlrkrirrrZProcessr0rmstart)rrs r_make_sub_processz/SeparateProcessPluginExecutor._make_sub_process s-//RVRd?.NN ) > '.f4D59[$BVX\Xj4kmmm  rcptjd}|dt)Nplugin_sigusr2_handlerzShutting down plugin)r1r2rrsignumframer3s rrz*SeparateProcessPluginExecutor._stop_plugins2 899 '(((&(((rctjd}|dtjddS)Nsubprocess_sigterm_handlerzShutting down child processr)r1r2rrrrs rryz  F V^$$$ *+++++rc|jr|jsdS|jd|jj|jjtr)d|_|j d|_dS|jd|jj } |j |j t|j r| |nT#t$rG}|jdt!|| |Yd}~nd}~wwxYwd|_|j d|_dS#d|_|j d|_wxYw)NzTerminating subprocesszKilling subprocessz7Wasn't able to kill subprocess because of the error: %s)rmrlr3rrdr~rer|KILL_PROCESS_TIMEOUTr?rjoinis_aliverrrOr)rrrTs r_terminate_sub_processz4SeparateProcessPluginExecutor._terminate_sub_process*s| 4#7  F /000 )--///   & + +,@ A A DL  * * , , ,#'D F +,,,l ( L " " $ $ $ L  2 3 3 3|$$&& +%%c*** ' ' ' H  XZ]^`ZaZa b b b  ! !# & & & & & & & & ' DL  * * , , ,#'D  DL  * * , , ,#'D ' ' ' 's1=A&D$#F!$ E5.=E0+F!0E55F!!)G c tjd}|dtdt jD}g}t tj D]\}}| d| |dd|dtj |D]Q\}}} } | d|d |d | | r*| d | R|d |dS) Nz stack tracerz>--- Threads stack traces, while plugin is considered stuck ---c*g|]}|j|jfSr@)identr).0ths r zBSeparateProcessPluginExecutor._sigusr1_handler..Ks!LLL27+LLLrz # Thread: ()zFile: "z", line z, in z  )r1r2rdict threading enumeratelistr_current_framesitemsappendrN traceback extract_stackstripr) rrr3id2namecode thread_idstackfilenamelinenorlines rr{z.SeparateProcessPluginExecutor._sigusr1_handlerGsW// QRRRLLi6I6K6KLLLMM $S%8%:%:%@%@%B%B C C 5 5 Iu KKPw{{9b'A'APPIPPP Q Q Q090G0N0N 5 5,&$ KhKKKKTKKLLL5KK 3TZZ\\ 3 3444 5 4!!!!!rc.|dSr)rr>s rr?z'SeparateProcessPluginExecutor.terminateUs ##%%%%%rcV||dSr)rrr>s r_restart_sub_processz2SeparateProcessPluginExecutor._restart_sub_processXs, ##%%%      rcb|jr|js||j|jfSr)rmrlrr>s r_get_process_and_contextz6SeparateProcessPluginExecutor._get_process_and_context\s8| %4#7 %  " " $ $ $|T111rc|jrd}|\}}tj}||j_||j_|j|j|j |j dtj|z |j ||j}|r| t#|j}|n"#t($r} t+| | d} ~ wwxYw|t/|j} | sbt1j|jjt8jtj|dz |tA|j} | s?|jj!} || rtE| tEdS)Nz=Executor (main process) data exchange with plugin took %f secg@)#rkrrrr^r9r:rarrbr`r~r3rr|rcr}rrr0rPrQr%rr"rurrmrrwrzsleeprr(rOr ) rr9r:r;_contextr db_corrupted recreatorrUin_timesuccessrTs rr<z%SeparateProcessPluginExecutor.executeas8   G2244 7 Y[[".  /55777.44666"&&((( VX\XaXcXcfhXhiii/44W===-4466  )  ' ' ) ) ) g)$+66 $$&&&&  g g g./GHHNff g  " " $ $ $&(( (9@@BB + GDL$fn 5 5 5 Jw} % % %  % % ' ' '(** *8??AA 1%B  ' ' ) ) ) 1.r222.000  1 1s(D99 EEEr)NN)rrrr staticmethodrrrrryrrr{r?rrr<rrs@rriris; kBkBkB\kBZ((\())\) \ ,,,(((: " "\ "&&&!!!222 +1+1+1+1+1+1+1rri)r+rCrir r(r"r%)"rr1rZrurrwrrrrrsqlalchemy.excrrrrlvestats.core.pluginrlvestats.core.plugin_contextrlvestats.lib.configr __author__rr r"r%r(objectr+rrCrXri__all__r@rrrsZ  :99999666666++++++  *****y*** *****9*** *****y*** *****Y*** $$$$$V$$$4) ) ) ) ) ) ) ) XV"}1}1}1}1}1N}1}1}1@ ' ' 'r