'eU=ddlmZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl m Z mZmZmZddlmZddlmZddlmZdZGdd eZGd d eZGd d eZGddeZGddeZdZGddeZ GddeZ!GddeZ"gdZ#dS))absolute_importN)NoSuchColumnErrorNoSuchTableErrorNoReferenceErrorSQLAlchemyError) PluginContext)LveStatsPluginTerminated) ConfigErrorshamanceZdZfdZxZS)PluginExecutionExceptioncHtt|j|i|dSN)superr __init__selfargskwargs __class__s /builddir/build/BUILDROOT/lve-stats-4.2.1-1.el7.x86_64/opt/cloudlinux/venv/lib/python3.11/site-packages/lvestats/eventloop/plugin_executors.pyrz!PluginExecutionException.__init__,6&--6GGGGGG__name__ __module__ __qualname__r __classcell__rs@rr r AHHHHHHHHHrr ceZdZfdZxZS)DbRecoveredExceptioncHtt|j|i|dSr)rr"rrs rrzDbRecoveredException.__init__!s,2"D))2DCFCCCCCrrrs@rr"r" sADDDDDDDDDrr"ceZdZfdZxZS)DbRecoverFailedExceptioncHtt|j|i|dSr)rr%rrs rrz!DbRecoverFailedException.__init__&rrrrs@rr%r%%r rr%ceZdZfdZxZS)PluginTimeoutExceptioncHtt|j|i|dSr)rr(rrs rrzPluginTimeoutException.__init__+s,4$d++4dEfEEEEErrrs@rr(r(*sAFFFFFFFFFrr(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__2sL $%@AA======46GXGX*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.execute9s"###rctrr7rs r terminatezPluginExecutor.terminateCs!###rN)rrrr5rr<r?rrr+r+/sN}ZZZ$$$$$$$$rr+c*eZdZfdZdZdZxZS)SameProcessPluginExecutorctt||t||_t |_tj |_ dSr) rrCrrplugin_contextdictlast_execution_timer+r5copylve_data)rr0rs rrz"SameProcessPluginExecutor.__init__KsX '..77???+F33#'66 &7<<>> rc tjd}|j|}||_d}t |dt |dd}|r||j|dz }|||kr ||j ||j|<dS#tttf$r`| d |jn!#t$r}t!|d}~wwxYwt#t$$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:getattrrGgetr<rIrrr exception recover_db BaseExceptionr%r"rr ) rr9r:r;r3plugin_instance time_passedrKexception_during_recoverexs rr<z!SameProcessPluginExecutor.executeQs HII-::<HH! (GL(TX4Y4YZZ  N 8 < <\1 M MMK >V{22 3'' 6669<(6%'79IJ - - - mnnnM'224444$MMM23KLLLM+,,," 3 3 3 :;;;.r222  3 3 3.r222 3%32sH$B'',E+C.-E+. D 8DD  E+&$E  E+E&&E+cdSrr@r>s rr?z#SameProcessPluginExecutor.terminaters r)rrrrr<r?rrs@rrCrCJsW????? 333B       rrCceZdZdZdZdS)ProcessContextc tj|_|j|_t |j_|j|_|j|_ |j|_ |j|_ |j|_ |j|_ dSr)multiprocessingManagermgr NamespacensrFrGEventplugin_ready_eventplugin_execution_finished_eventplugin_execution_success_eventdb_error_event have_to_exitexitedr>s rrzProcessContext.__init__ws"*,,($$&&&*ff#"&(.."2"2/3x~~/?/?,.2hnn.>.>+"hnn.. HNN,,hnn&& rc8|jdSr)r]shutdownr>s rr?zProcessContext.terminates rN)rrrrr?r@rrrYrYvs2 ' ' 'rrYceZdZdfd ZeddZedZdZedZedZ dZ d Z ed Z d Z d Zd ZdZxZS)SeparateProcessPluginExecutorNctt||||_d|_d|_dSr)rrjr profiling_logprocess_contextprocess)rr0rlrs rrz&SeparateProcessPluginExecutor.__init__s= +T22;;FCCC*# rc  tjtjtjtjtjtjtjtj d} t|}tj } |jds#|jr|j|rt)|d5}|dt-j||}|dd |d |d d dddn #1swxYwY|jdS|jd#|j|jj} |jj} || } n#t@$r-} |!tE| Yd} ~ d} ~ wtF$rE} |!d | |j_!|jYd} ~ d} ~ wwxYw| | _tI| d tI| d d}|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} ~ 8d} ~ wth$r-|5d| tmj7dYntp$r.}|!dtE|Yd}~d}~wtF$rF} |!d| | |j_!|jYd} ~ d} ~ wwxYw|*d| ||z |j-|jF#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+z'Plugin process profile, internal time: )streamtimerAz)Plugin process profile, cumulative time: cumulativez!Error during instantiating pluginrKrzExecuting plugin %szExecuting plugin %s took %f secrLznDatabase 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)<ossetpgrpsignalSIGTERMrj_child_process_sigterm_handlerSIGUSR1_sigusr1_handlerr1r2rr+r5rHrawaitreis_setrbsetopenwritepstatsStats sort_stats print_statsrfclearr_r9r:rMr rPstr ExceptionrNfloatrGrOSIGUSR2 _stop_plugindebugrrr<rcSIG_IGNrrrrdrr infosysexitIOErrorerrno isinstanceEOFError)r0rmprofilerrlr3rErIfr,r9r:rScerVrKrTrGt0ioees r_in_separate_processz2SeparateProcessPluginExecutor._in_separate_processs  fn&C&bccc fn&C&TUUU CDDf B*622N%6;;==HW J)<AA!ALL &3::<< 'GKKMMM#O!%mT!:!:Oa !(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^_aSabbb'FJJLLL'GKKMMM fnfnEEEE-/?AQR!!! &uvvv79*4'6::<<<'GKKMMM *!!! 'BCOQQQ8:*4'GKKMMM 3$$$!P" W/"V9AR W/ V;S W/ 7VW/ V"#U W/ V;VW/VAW// Y>: XY9 Y X=1Y9;X==Y1Y99Y>crtj}|tj||||dSr)cProfileProfileruncallrjr)r0rmrlrs 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) rYrmrlrjrrr[Processr0rnstart)rrs r_make_sub_processz/SeparateProcessPluginExecutor._make_sub_processs-//RVRd?.NN ) > '.f4D59[$BVX\Xj4kmmm  rcptjd}|dt)Nplugin_sigusr2_handlerzShutting down plugin)r1r2rr signumframer3s 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)rnrmr3rrer~rfr|KILL_PROCESS_TIMEOUTr?rjoinis_aliverrrPr)rrrVs 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 ctjd}|dtdt jD}g}t tj D]\}}| d| |d|fztj |D]N\}}} } | d||| fz| r*| d| zO|d|dS) Nz stack tracerz>--- Threads stack traces, while plugin is considered stuck ---c*g|]}|j|jfSr@)identr).0ths r zBSeparateProcessPluginExecutor._sigusr1_handler..Cs!LLL27+LLLrz # Thread: %s(%d)zFile: "%s", line %d, in %sz %s )r1r2rrF threading enumeratelistr_current_framesitemsappendrO traceback extract_stackstripr) rrr3id2namecodethreadIdstackfilenamelinenorlines rr{z.SeparateProcessPluginExecutor._sigusr1_handler?s=// QRRRLLi6I6K6KLLLMM#C$7$9$9$?$?$A$ABB 9 9OHe KK, HR0H0H(/SS T T T090G0N0N 9 9,&$ 8Hfd;SSTTT9KK$**,, 7888 9 4!!!!!rc.|dSr)rr>s rr?z'SeparateProcessPluginExecutor.terminateMs ##%%%%%rcV||dSr)rrr>s r_restart_sub_processz2SeparateProcessPluginExecutor._restart_sub_processPs, ##%%%      rcb|jr|js||j|jfSr)rnrmrr>s r_get_process_and_contextz6SeparateProcessPluginExecutor._get_process_and_contextTs8| %4#7 %  " " $ $ $|T111rc|jrd}|\}}tj}||j_||j_|j|j|j |j dtj|z 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@)#rlrrrr_r9r:rbrrcrar~r3rr|rdr}rrr0rQrRr%rr"rurrnrrwrzsleeprr(rPr ) rr9r:r;_contextr db_corrupted recreatorrUin_timesuccessrVs rr<z%SeparateProcessPluginExecutor.executeYs8   G2244 7 Y[[".  /55777.44666"&&((( VZ^ZcZeZehjZjklll/44W===-4466  )  ' ' ) ) ) I)$+66 $$&&&&  I I I./GHHH I  " " $ $ $&(( (9@@BB + GDL$fn 5 5 5 Jw} % % %  % % ' ' '(** *8??AA 1%B  ' ' ) ) ) 1.r222.000  1 1s(D;; EEEr)NN)rrrr staticmethodrrrrryrrr{r?rrr<rrs@rrjrjs; kBkBkB\kBZ((\())\) \ ,,,(((: " "\ "&&&!!!222 +1+1+1+1+1+1+1rrj)r+rCrjr r(r"r%)$ __future__rr1rrwrrrrrrr[rusqlalchemy.excrrrrlvestats.core.plugin_contextrlvestats.core.pluginr lvestats.lib.configr __author__rr r"r%r(objectr+rrCrYrj__all__r@rrrsr'&&&&&    aaaaaaaaaaaa666666999999++++++  HHHHHyHHH DDDDD9DDD HHHHHyHHH FFFFFYFFF $$$$$V$$$0) ) ) ) ) ) ) ) XV"}1}1}1}1}1N}1}1}1@ ' ' 'r