veg)0dZdZddlZddlZddlZddlmZddlZddl m Z ddl m Z ddl mZmZmZd d lmZd d lmZd d lmZd d lmZmZGdde Zedkr7eejdejeZedSdS)z* This module contains DecisionMaker class z ssa.modulesN)isfile)setup_database)Common)iter_domains_dataiter_urls_dataget_url_durations) load_tunables)ssa_tunables_schema) report_path)previous_day_date sentry_initc \eZdZdZd fd ZdZedefdZe defdZ e de fdZ e de fd Zed Zde fd Zd edefd ZdedefdZdedefdZededededefdZdZde fdZde fdZdedefdZdZdededefdZxZS)! DecisionMakerz, SSA Decision maker implementation. Ncttjd|_|jdt |r|n t|_dS)Ndecision_makerzDecisionMaker enabled: %s) super__init__logging getLoggerloggerinfo __package__rengine)selfr __class__s Q/opt/cloudlinux/venv/lib64/python3.11/site-packages/ssa/modules/decision_maker.pyrzDecisionMaker.__init__&s_ '(899  4kBBB &?AA! !(,(<(<)*:;[=Z)\)\% 4 8 8 I II ( ))*JCP_L`L`aaa 44-o>@@ L 778IJJ L8:wy7I7I4,/-o>-@-@)(,==(!((!0;L-01M-N-N(-1B.H.H(I(I*K*K*KLLL V"11!*d6F$.200 y!(($0C z@DecisionMaker.list_handling_considering_time..s:4441M!D1H*-..444rr)rrrangera)rrArrs `@rlist_handling_considering_timez,DecisionMaker.list_handling_considering_timesU yB44444a]++T22444 4rurl_slow_reqs_by_timec,|D]}||jkrdSdS)z_ This functions will check if any of elements is greater than "request_number" TF)request_number)rrvrqs r$compare_elements_with_request_numberz2DecisionMaker.compare_elements_with_request_numbers2 '  AD'''tt(urr@rTcb|jsdStjtj||S)z} Calculates the correlation coefficient using the "url_total_reqs" and the "domain_total_reqs" lists r)r9rYamincorrcoef)rr@rTs rrSzDecisionMaker.get_correlations1  1wr{>3DEEFFFrrErFrGcT|fdd|r |d|S|S)a Will sort the domain list by "slow_reqs", the goal is to leave only "domains_number" of uppers, also per each domain will sort urls by "reqs_num", the goal is to leave only "urls_number" of uppers. leave_top == 0 allows to keep the full list c|SNr:)dict_rGs rz.DecisionMaker.report_sorting..s E/,BrT)keyreverseN)sortrDs `rr_zDecisionMaker.report_sortingsN BBBB"&  ( ( (    + + rc|j}t|rt|5} tj|}|dddd}n#tj$rd}YnwxYwdddn #1swxYwYd|d}||}tj ||dSdS) z# Rename old report r4z dd.mm.yyyy._unknownNreport__z.json) r2ropenjsonloadrRreplaceJSONDecodeErrorr/r+rename)r old_report json_dataddate_from_reportnew_report_name new_reports rrename_old_reportzDecisionMaker.rename_old_reports@- *   .j!! UYU ),,A()uuV\'B'B'J'J3PS'T'T$$+111'0$$$1 U U U U U U U U U U U U U U UA)9@@@O**?;;J Ij* - - - - - . .s3B A'+B 'A;8B :A;;B  BBr'c|t|jdd5}tj||ddddddS#1swxYwYdS)z# Makes json report wzutf-8)encodingF) ensure_asciiindentN)rrr2rdump)rr'fs rr&zDecisionMaker.add_json_reports    $*C' B B B ?a IfaeA > > > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?sAAAcd} t|j5}tj||}dddn #1swxYwYn##ttjf$r |j}YnwxYw|S)zT Return contents of current report or empty report in case of error N) object_hook)rr2rrOSErrorrr7)r_filtering_hookr' report_dicts rget_json_reportzDecisionMaker.get_json_reports -d.// M6"iOLLL  M M M M M M M M M M M M M M M-. - - -,KKK -s.A; A?A?AA'&A'ric*|jsdS||jkS)a If correlation flag is enabled - we'll compare correlation_coefficient from configuration with calculated correlation coefficient. If the calculated value exceeds the configuration value - we return True otherwise False. At the same time if correlation flag is disabled - we'll also return "True" since in this case the correlation coefficient is not checked and its value is specified as zero in final report. T)r9correlation_coefficient)rris rrXz$DecisionMaker.correlation_conditionss" 4 4#???rcV||}||S)z At least one element from the received list (url_slow_reqs_by_time) must be greater than request_number )rury)rrArvs rrWz%DecisionMaker.request_number_exceededs2 !% C C !!889NOOOrr>ct|t|z dz}|jd|||jddkS)zY Check that percent of throttled requests per URL passes given threshold dzCalculated throttled percent %sallowed_throttling_percentager)r[rr!r$rR)rr>r@throttled_percents rrQz$DecisionMaker.is_throttling_suitablesp !!344s 88"# ;=NOOO D$:$>$> +Q%0%00 0rr)__name__ __module__ __qualname____doc__rr( staticmethodrVr/propertyr2r6r7setr;r#r%rLruboolryrSr]r_rr&rrXrWrQ __classcell__)rs@rrr!s======   /c///\/ 0S000X0 :t:::X: sX>>\>:::::x4D4T4444DHMQGdGtGGGG  T  c  (+  04    \  ..."?d????      @ @ @ @ @ @PPP 0 0/3 08< 0 0 0 0 0 0 0 0rr__main__zdecision_maker_standalone.log)filenamelevel)rrrrr+os.pathrnumpyrYssa.dbrcommonrstoragerrr configurationr configuration.schemesr internal.constantsr internal.utilsrrrr basicConfigINFOdmr:rrrs  !!!!!! *)))))777777,,,,,,;;;;;;;;c0c0c0c0c0Fc0c0c0L zKMMMG!@%l,,,, BBDDDDD r