Best Python code snippet using localstack_python
task.py
Source:task.py
1from datetime import datetime2from flask import render_template, session3from watch import app, lock, task_pool4from watch.utils.decorate_view import *5from watch.utils.manage_message import t_link6from watch.utils.oracle import execute, get_tab_columns, ping7from watch.utils.parse_args import dlm_str_to_list, get_num_str, get_offset, upper_values8@app.route('/<target>/task')9@title('Tasks')10def get_task(target):11 with lock:12 task_count = tuple(v.user_name for v in task_pool.values() if v.target == target).count(session['user_name'])13 t = render_template('layout.html', text=f'{task_count} active tasks for {target}.')14 return t15@app.route('/<target>/wait_for_execution')16@title('SQL execution')17@template('task')18@parameters({'sql_id': ' = str'})19@period('1m')20@command('/wait')21def wait_for_execution(t):22 """Note that a query started manually from IDE will stay "executing" until you fetch all it's rows.""" \23 """ In such case "Wait for session" can be helpful."""24 if not t.data:25 r = execute(t.target, "select min(sql_exec_start) from v$sql_monitor"26 " where sql_id = :sql_id and status = 'EXECUTING'"27 , t.parameters28 , 'one'29 , False)30 if not r[0]:31 return t.abort(f"SQL {t.parameters['sql_id']} Not found")32 else:33 t.data = r[0]34 return35 r = execute(t.target36 , "select nvl(sum(case when status = 'EXECUTING' then 1 else 0 end), 0) e"37 ", nvl(sum(case when status like 'DONE%' then 1 else 0 end), 0) d"38 ", max(status) s"39 " from v$sql_monitor where sql_id = :sql_id and sql_exec_start >= :start_time"40 , {'sql_id': t.parameters['sql_id'], 'start_time': t.data}41 , 'one'42 , False)43 if r[0] + r[1] == 0:44 return t.abort(f"SQL {t.parameters['sql_id']} Not found")45 if r[0] > 0:46 return47 if t.reply_to_message_id:48 return t.finish(r[2].lower())49 return t.finish('{} on {} is {}.'.format(t_link(f"{t.target}/Q/{t.parameters['sql_id']}", t.parameters['sql_id'])50 , t.target51 , r[2].lower()))52@app.route('/<target>/wait_for_status')53@title('Watch status')54@template('task')55@message_type('list')56@parameters({"owner": ' = str'57 , "table": ' = str'58 , "date_column": ' = str'59 , "status_column": ' = str'60 , "status_values": ' = s1;s2;sN str'61 , "info_column": ' = i1;i2;iN str'})62@optional({"filter_column": ' = str'63 , "filter_value": ' = str'})64@period('30m')65def wait_for_status(t):66 if not t.data:67 t.parameters = upper_values(t.parameters)68 t.parameters['status_values'] = dlm_str_to_list(t.parameters['status_values'])69 t.parameters['info_column'] = dlm_str_to_list(t.parameters['info_column'])70 table_columns = get_tab_columns(t.target, t.parameters['owner'], t.parameters['table'])71 for item in [t.parameters['date_column'], t.parameters['status_column']] + t.parameters['info_column']:72 if item not in table_columns.keys():73 return t.abort(f'{t.parameters["owner"]}.{t.parameters["table"]}.{item} not found.')74 if 'DATE' not in table_columns[t.parameters['date_column']]:75 return t.abort(f'{t.parameters["date_column"]} must be a date type.')76 status_type = table_columns[t.parameters['status_column']]77 if status_type != 'NUMBER' and 'CHAR' not in status_type:78 return t.abort(f'Unsupported type of {t.parameters["status_column"]} (neither number nor char).')79 if status_type == 'NUMBER':80 try:81 t.parameters['status_values'] = [int(v) for v in t.parameters['status_values']]82 except ValueError:83 return t.abort(f'All of status values ({t.parameters["status_values"]}) must be numbers.')84 t.parameters['info_column'] = {k: table_columns[k] for k in t.parameters['info_column']}85 filter_column_type = ''86 if t.optional.get('filter_column', False):87 if t.optional['filter_column'] not in table_columns.keys():88 return t.abort(f'{t.parameters["owner"]}.{t.parameters["table"]}'89 f'.{t.optional["filter_column"]} not found.')90 filter_column_type = table_columns[t.optional['filter_column']]91 if filter_column_type != 'NUMBER' and 'CHAR' not in filter_column_type:92 return t.abort(f'Unsupported type of {t.optional["filter_column"]} (neither number nor char).')93 if not t.optional.get('filter_value', False):94 return t.abort('Filter value is not set.')95 if filter_column_type == 'NUMBER':96 try:97 t.optional['filter_value'] = int(t.optional['filter_value'])98 except ValueError:99 return t.abort(f'Filter value must be a number.')100 t.data = {'status_values': t.parameters['status_values']101 , 'status_type': status_type102 , 'start_date': t.create_date103 , 'filter_column_type': filter_column_type}104 end_date = datetime.now()105 p = {str(k): v for k, v in enumerate(t.data['status_values'], start=1)}106 p['start_date'] = t.data['start_date']107 p['end_date'] = end_date108 p['filter_value'] = t.optional.get('filter_value', '1')109 info_column_list = []110 for c, ct in t.parameters['info_column'].items():111 if ct == 'CLOB':112 info_column_list.append(f"cast(dbms_lob.substr({c}, 255) as varchar2(255))")113 elif 'CHAR' in ct:114 info_column_list.append(f"substr(to_char({c}), 0, 255)")115 else:116 info_column_list.append(f"to_char({c})")117 info_column_sql_text = ' || \' \' || '.join(info_column_list)118 filter_column = t.optional.get('filter_column', '\'1\'')119 r = execute(t.target120 , f"select to_char({t.parameters['date_column']}, 'hh24:mi:ss')"121 f", {info_column_sql_text}"122 f", {t.parameters['status_column']}"123 f" from {t.parameters['owner']}.{t.parameters['table']}"124 f" where {t.parameters['date_column']} >= :start_date"125 f" and {t.parameters['date_column']} < :end_date"126 f" and {'upper' if t.data['status_type'] != 'NUMBER' else ''}"127 f"({t.parameters['status_column']})"128 f" in ({':' + ', :'.join(str(i) for i in range(1, len(t.data['status_values']) + 1))})"129 f" and {filter_column} = :filter_value"130 , p131 , 'many'132 , False)133 t.data['start_date'] = end_date134 return t.get_message(r135 , lambda o, i: f'{i[0]} {i[1]}'.replace('<', '<').replace('>', '>')136 , lambda o: f'{o.parameters["table"]} ({o.target})')137@app.route('/<target>/wait_for_heavy')138@title('Heavy SQL')139@template('task')140@message_type('outstanding')141@parameters({'exec_time_min': ' >= int'142 , 'temp_usage_gb': ' >= int'})143@optional({'user_name': ' like str'144 , 'ignore_user': ' like str'})145@period('5m')146@command('/heavy')147def wait_for_heavy(t):148 r = execute(t.target149 , "select username, sql_id, exec_time_min, temp_usage_gb, exec_id, sid from"150 " (select s.username, m.sql_id, to_char(round(elapsed_time / 60000000)) exec_time_min, s.sid,"151 " m.sql_id || to_char(m.sql_exec_id) || to_char(m.sql_exec_start, 'yyyymmddhh24miss') exec_id,"152 " rtrim(to_char(((nvl(sum(u.blocks), 0) * min(p.value)) / 1024 / 1024 / 1024), 'fm999990d99')"153 ", to_char(0,'fmd')) temp_usage_gb"154 " from v$session s"155 " left join v$sort_usage u on s.saddr = u.session_addr"156 " join v$parameter p on p.name = 'db_block_size'"157 " join v$sql_monitor m on m.sid = s.sid and m.session_serial# = s.serial#"158 " where m.status = 'EXECUTING'{}{}"159 " group by s.username, m.sql_id, round(elapsed_time / 60000000), s.sid,"160 " m.sql_id || to_char(m.sql_exec_id) || to_char(m.sql_exec_start, 'yyyymmddhh24miss'))"161 " where exec_time_min >= :exec_time_min or temp_usage_gb >= :temp_usage_gb"162 .format(' and s.username like :user_name' if t.optional.get('user_name', None) else ''163 , ' and s.username not like :ignore_user' if t.optional.get('ignore_user', None) else '')164 , {**t.parameters, **t.optional}165 , 'many'166 , False)167 return t.get_message(r, lambda o, i: '{} ({}, {}) on {} is executing {} minutes and consumes {} Gb of temp space.'168 .format(t_link(f'{o.target}/Q/{i[1]}', i[1]), i[5], i[0], o.target, i[2], i[3]), None, 4)169@app.route('/<target>/wait_for_temp')170@title('Temp usage')171@template('task')172@message_type('outstanding')173@parameters({'pct_used': ' >= int'})174@period('10m')175@command('/temp')176def wait_for_temp(t):177 """Notification will be sent again only when the threshold be crossed."""178 r = execute(t.target179 , "select tablespace_name, to_char(round((used_blocks / total_blocks) * 100)) pct_used"180 " from v$sort_segment"181 " where round((used_blocks / total_blocks) * 100) >= :pct_used"182 , t.parameters183 , 'many'184 , False)185 return t.get_message(r, lambda o, i: f'Tablespace {i[0]} on {o.target} is {i[1]}% used.', None, 0)186@app.route('/<target>/wait_for_expiry')187@title('Expired users')188@template('task')189@message_type('outstanding')190@parameters({'expires_in_days': ' >= int'})191@period('1d')192@command('/exp')193def wait_for_expiry(t):194 r = execute(t.target195 , "select username, to_char(expiry_date, 'dd.mm.yyyy hh24:mi:ss') exp"196 " from dba_users"197 " where expiry_date between sysdate and sysdate + :expires_in_days"198 , t.parameters199 , 'many'200 , False)201 return t.get_message(r, lambda o, i: f'User account {i[0]} on {o.target} expires at {i[1]}.', None, 0)202@app.route('/<target>/wait_for_uncommitted')203@title('Uncommitted trans')204@template('task')205@message_type('outstanding')206@parameters({'idle_time_minutes': ' >= int'})207@optional({'ignore_tables': ' like str'})208@period('1h')209@command('/uncommitted')210def wait_for_uncommitted(t):211 r = execute(t.target212 , "select distinct s.osuser, s.machine, l.name"213 " from dba_dml_locks l"214 " inner join v$session s on s.sid = l.session_id"215 " where s.status != 'ACTIVE'"216 " and l.name not like :ignore_tables"217 " and round(last_call_et / 60) >= :idle_time_minutes"218 , {'idle_time_minutes': t.parameters['idle_time_minutes']219 , 'ignore_tables': t.optional.get('ignore_tables', '-')}220 , 'many'221 , False)222 return t.get_message(r, lambda o, i: f'It seems {i[0]} ({i[1]})'223 f' forgot to commit a transaction on {o.target} ({i[2]}).', None, 0)224@app.route('/<target>/wait_for_ts')225@title('Tabspace usage')226@template('task')227@message_type('outstanding')228@parameters({'pct_used': ' >= int'})229@optional({'tablespace_name': ' like str'})230@period('6h')231@command('/ts')232@snail()233def wait_for_ts(t):234 """Notification will be sent again only when the threshold be crossed."""235 p = {'pct_used': t.parameters['pct_used'], 'tablespace_name': t.optional.get('tablespace_name')}236 if not p['tablespace_name']:237 p.pop('tablespace_name')238 r = execute(t.target239 , "select * from (select t.tablespace_name,"240 " round((max_files_size - (files.free_files_space + free.free_space)) / 1024 / 1024 / 1024) used_gb,"241 " round(files.max_files_size / 1024 / 1024 / 1024) allocated_gb,"242 " round(((max_files_size - (files.free_files_space + free.free_space))"243 " / max_files_size) * 100) pct_used"244 " from dba_tablespaces t"245 " left join (select tablespace_name,"246 " sum(nvl(bytes,0)) free_space"247 " from dba_free_space"248 " group by tablespace_name) free on free.tablespace_name = t.tablespace_name"249 " left join (select tablespace_name,"250 " sum(decode(maxbytes, 0, bytes, maxbytes)) max_files_size,"251 " sum(decode(maxbytes, 0, bytes, maxbytes)) - sum(bytes) free_files_space"252 " from dba_data_files group by tablespace_name) files on t.tablespace_name = files.tablespace_name)"253 " where pct_used >= :pct_used{}".format(' and tablespace_name like :tablespace_name' if t.optional.get('tablespace_name') else '')254 , p255 , 'many'256 , False)257 return t.get_message(r, lambda o, i: f'Tablespace {i[0]} on {o.target} is {i[3]}%'258 f' used ({i[1]} of {i[2]} Gb).', None, 0)259@app.route('/<target>/wait_for_session')260@title('Session activity')261@template('task')262@parameters({'sid': ' = int'})263@period('1m')264@command('/waits')265def wait_for_session(t):266 """Be sure to choose the main session if your query started in parallel mode."""267 if not t.data:268 e = execute(t.target269 , "select sid, status from v$session where sid = :sid"270 , t.parameters271 , 'one'272 , False)273 if not e:274 return t.abort('Not found')275 t.data = {'sid': e[0]}276 r = execute(t.target277 , "select sid, status from v$session where sid = :sid"278 , t.data279 , 'one'280 , False)281 if not r:282 return t.finish(f"Session {t.data['sid']} is not found on {t.target}.")283 if r[1] != 'INACTIVE':284 return285 return t.finish(f'Session {r[0]} on {t.target} is {r[1].lower()}.')286@app.route('/<target>/wait_for_queued')287@title('Queued SQL')288@template('task')289@message_type('outstanding')290@parameters({'queued_time_sec': ' >= int'})291@optional({'ignore_event': ' like str'})292@period('5m')293def wait_for_queued(t):294 pt = t.period[-1:]295 pv = t.period[:-1]296 t.parameters['start_date'] = datetime.now() - get_offset(pv, pt)297 r = execute(t.target298 , "select nvl(sql_id, 'Unknown sql') || ' ' || event || ' ' || to_char(session_id), "299 " nvl(sql_id, 'Unknown sql'), event, session_id, machine, count(1) waits"300 " from v$active_session_history"301 " where event like 'enq:%' and sample_time > :start_date"302 " and event not like :ignore_event"303 " group by nvl(sql_id, 'Unknown sql') || ' ' || event || ' ' || to_char(session_id),"304 " sql_id, event, session_id, machine"305 " having count(1) > :queued_time_sec"306 , {'start_date': t.parameters['start_date']307 , 'queued_time_sec': t.parameters['queued_time_sec']308 , 'ignore_event': t.optional.get('ignore_event', '---')}309 , 'many'310 , False)311 return t.get_message(r, lambda o, i: '{} ({}, {}) on {} has been queued for {} seconds ({}).'312 .format(t_link(f'{t.target}/Q/{i[1]}', i[1]), i[4], i[3], t.target, i[5], i[2]), None, 0)313@app.route('/<target>/wait_recycled')314@title('Recycled space')315@template('task')316@message_type('threshold')317@parameters({'space_gb': ' >= int'})318@period('1d')319def wait_for_recycled(t):320 r = execute(t.target321 , "select nvl(round(sum(r.space * p.value) / 1024 / 1024 / 1024), 0) space_gb"322 " from dba_recyclebin r join v$parameter p on p.name = 'db_block_size'"323 " where r.can_purge = 'YES' and nvl(r.space, 0) <> 0"324 , {}325 , 'one'326 , False)327 return t.get_message(r328 , lambda o, i: f'{i} Gb can be purged from recycle bin on {o.target}.'329 , None, t.parameters['space_gb'], 2)330@app.route('/<target>/check_size')331@title('Segment size')332@template('task')333@message_type('threshold')334@parameters({'owner': ' = str'335 , 'segment_name': ' = str'336 , 'size_mb': ' >= int'})337@period('1d')338def check_size(t):339 """Each occurrence increases the threshold to 2x."""340 r = execute(t.target341 , "select round(nvl(sum(bytes) / 1024 / 1024, 0)) size_mb"342 " from dba_segments"343 " where owner = :owner and segment_name = :segment_name"344 , {'owner': t.parameters['owner'], 'segment_name': t.parameters['segment_name']}345 , 'one'346 , False)347 if not r:348 return t.abort(f'Segment {t.parameters["owner"]}.{t.parameters["segment_name"]} not found.')349 return t.get_message(r350 , lambda o, i: f'{o.parameters["owner"]}.{o.parameters["segment_name"]}'351 f' size reached {i} mb on {o.target}.', None, t.parameters['size_mb'], 2)352@app.route('/<target>/check_resource_usage')353@title('Resource usage')354@template('task')355@parameters({'pct_used': ' 0..100% >= int'})356@period('1h')357def check_resource_usage(t):358 r = execute(t.target359 , "select resource_name, to_char(current_utilization), trim(limit_value)"360 ", round((current_utilization / to_number(limit_value)) * 100)"361 " from v$resource_limit"362 " where trim(limit_value) not in ('0', 'UNLIMITED')"363 " and round((current_utilization / to_number(limit_value)) * 100) >= :pct_used"364 , t.parameters365 , 'many'366 , False)367 return '\n'.join(f'The resource {t.target}.{item[0]}'368 f' is {item[3]}% used ({item[1]} of {item[2]}).' for item in r)369@app.route('/<target>/wait_for_sql_error')370@title('SQL error')371@template('task')372@message_type('list')373@optional({'ignore_user': ' like str'})374@period('5m')375def wait_for_sql_error(t):376 """This task shows sql errors, stored in sql_monitor cache. Errors, displaced from the cache, will be lost.""" \377 """ A good approach is creating a trigger "after servererror"."""378 if not t.data:379 t.data = {'start_date': t.create_date}380 end_date = datetime.now()381 r = execute(t.target382 , "select username, sql_id, sid, error_message"383 " from v$sql_monitor"384 " where status = 'DONE (ERROR)'"385 " and error_number not in (1013, 28, 604, 24381)" # cancel, kill, recursive, DML array386 " and last_refresh_time between :start_date and :end_date"387 " and (username not like :user_name or username is null)"388 , {'start_date': t.data['start_date']389 , 'end_date': end_date390 , 'user_name': t.optional.get('ignore_user', '---')}391 , 'many'392 , False)393 t.data['start_date'] = end_date394 return t.get_message(r, lambda o, i: '{} ({}, {}) on {} is failed ({}).'395 .format(t_link(f'{o.target}/Q/{i[1]}'396 , i[1]), i[2], i[0], o.target, i[3].replace('\n', ' ')))397@app.route('/<target>/ping_target')398@title('Ping target')399@template('task')400@period('10m')401def ping_target(t):402 if ping(t.target) == -1 and t.data != -1:403 t.data = -1404 return f'Target {t.target} did not respond properly.'405 else:406 t.data = 0407@app.route('/<target>/check_redo_switches')408@title('Redo switches')409@template('task')410@parameters({'switches_per_interval': ' >= int'})411@period('1h')412def check_redo_switches(t):413 pt = t.period[-1:]414 pv = t.period[:-1]415 t.parameters['start_date'] = datetime.now() - get_offset(pv, pt)416 r = execute(t.target417 , "select count(1) switches_count from v$log_history"418 " where first_time > :start_date having count(1) >= :switches_per_interval"419 , {'start_date': t.parameters['start_date']420 , 'switches_per_interval': t.parameters['switches_per_interval']}421 , 'one'422 , False)423 return f'Redo logs on {t.target} have been switched {str(r[0])} times in the last {t.period}.' if r else None424@app.route('/<target>/check_logs_deletion')425@title('Logs moving')426@template('task')427@message_type('threshold')428@parameters({'size_gb': ' >= int'})429@period('1h')430def check_logs_deletion(t):431 """Each occurrence increases the threshold to 2x."""432 r = execute(t.target433 , "select round(nvl(sum(blocks * block_size) / 1024 / 1024 / 1024, 0)) size_gb"434 " from v$archived_log where deleted = 'NO'"435 , {}436 , 'one'437 , False)438 return t.get_message(r, lambda o, i: f'{i} gb of archived logs on {o.target} are waiting to be deleted.'439 , None, t.parameters['size_gb'], 2)440@app.route('/<target>/wait_for_zombie')441@title('Zombie sessions')442@template('task')443@message_type('outstanding')444@parameters({'last_call_minutes': ' >= int'})445@period('1h')446def wait_for_zombie(t):447 """User sessions could stay active and being waiting for an event that never comes.""" \448 """ They must be killed to free locked resources."""449 r = execute(t.target450 , "select sid, username from v$session where type = 'USER' and ("451 "(sysdate - last_call_et / 86400 < sysdate - :last_call_minutes * 1 / 24 / 60 and status = 'ACTIVE')"452 " or (event = 'SQL*Net break/reset to client' and status = 'INACTIVE'))"453 , {**t.parameters}454 , 'many'455 , False)456 return t.get_message(r457 , lambda o, i: 'Session {} ({}) on {} seems to be a zombie.'458 .format(t_link(f'{o.target}/S/{str(i[0])}', str(i[0])), i[1], t.target), None, 0)459@app.route('/<target>/check_job_status')460@title('Job health')461@template('task')462@message_type('outstanding')463@period('6h')464def check_job_status(t):465 r = execute(t.target466 , "select job, log_user, nvl(failures, 0) fails from dba_jobs where broken = 'Y'"467 , {}468 , 'many'469 , False)470 return t.get_message(r, lambda o, i: f'Job {i[0]} ({i[1]}) on {o.target} is broken, {i[2]} failures.', None, 0)471@app.route('/<target>/check_src_structure')472@title('Compare structure')473@template('task')474@message_type('outstanding')475@parameters({'destination_schema': ' = str'476 , 'source_db': ' = str'477 , 'source_schema': ' = str'})478@optional({'by_target_prefix': ' = str'479 , 'by_target_postfix': ' = str'})480@period('3h')481def check_src_structure(t):482 """This task compares destination and source column types for all existing tables in specified schema."""483 if t.parameters['source_db'] not in app.config['USERS'][t.user_name][2]:484 return t.abort(f"Source target {t.parameters['source_db']} not exists or not allowed.")485 target_columns = execute(t.target486 , "select c.table_name || '.' || c.column_name, c.data_type, c.data_length"487 " from all_tab_columns c"488 " join all_tables t on t.owner = c.owner and t.table_name = c.table_name"489 " where c.owner = :destination_schema"490 " and c.table_name like :by_target_prefix and c.table_name like :by_target_postfix"491 " order by 1, 2"492 , {'destination_schema': t.parameters['destination_schema']493 , 'by_target_prefix': t.optional.get('by_target_prefix', '') + '%'494 , 'by_target_postfix': '%' + t.optional.get('by_target_postfix', '')495 }496 , 'many'497 , False)498 src_columns = execute(t.parameters['source_db']499 , "select :prefix || c.table_name || :postfix || '.' || c.column_name,"500 " c.data_type, c.data_length from all_tab_columns c"501 " join all_tables t on t.owner = c.owner and t.table_name = c.table_name"502 " where c.owner = :source_schema order by 1, 2"503 , {'source_schema': t.parameters['source_schema']504 , 'prefix': t.optional.get('by_target_prefix', '')505 , 'postfix': t.optional.get('by_target_postfix', '')506 }507 , 'many'508 , False)509 comparison_result = []510 src_columns = {item[0]: (item[1], item[2]) for item in src_columns}511 for target_column in target_columns:512 c = src_columns.get(target_column[0])513 if not c:514 continue515 if target_column[1] != c[0] or target_column[2] != c[1]:516 comparison_result.append((f'{target_column[0]}'517 f'\n {target_column[1]}({target_column[2]}) â {c[0]}({c[1]})',))518 return t.get_message(comparison_result519 , lambda o, i: i[0]520 , lambda o: f"Some source tables"521 f" for {o.target}.{o.parameters['destination_schema']} has been changed", 0)522@app.route('/<target>/check_session_stats')523@title('Session stats')524@template('task')525@message_type('outstanding')526@parameters({'statistic_name': ' = str'527 , 'value': ' >= int'})528@period('30m')529def check_session_stats(t):530 """Please see "Activity -> Session monitor -> Session -> Session stats" to find all available statistic names."""531 r = execute(t.target532 , "select s.sid, n.name, s.value from v$sesstat s join v$statname n on s.statistic# = n.statistic#"533 " where n.name = :statistic_name and s.value >= :value order by s.value desc"534 , {**t.parameters}535 , 'many'536 , False)537 return t.get_message(r538 , lambda o, i: 'Session {} on {} has {} = {}.'539 .format(t_link(f'{o.target}/S/{str(i[0])}', str(i[0])), o.target, i[1], get_num_str(i[2]))540 , None, 0)541@app.route('/<target>/check_concurrency')542@title('SQL concurrency')543@template('task')544@message_type('threshold')545@parameters({'concurrency_pct': ' >= int'})546@period('1h')547def check_concurrency(t):548 """Each occurrence increases the threshold to 2x."""549 r = execute(t.target550 , "select nvl(round((sum(concurrency_wait_time) / nullif(sum(elapsed_time), 0)) * 100), 0) ct"551 " from v$sql_monitor where status = 'EXECUTING'"552 " and sid in (select sid from v$session where status = 'ACTIVE')"553 , {}554 , 'one'555 , False)556 return t.get_message(r557 , lambda o, i: f'{o.target} has average concurrency rate = {i}%.'558 , None, t.parameters['concurrency_pct'], 1.5)559@app.route('/<target>/check_frequent_sql')560@title('Frequent SQL')561@template('task')562@message_type('outstanding')563@parameters({'executions': ' >= int'})564@period('24h')565def check_frequent_sql(t):566 """This task based on v$sqlarea which accumulate statistics since SQL statement had been cached."""567 r = execute(t.target568 , "select sql_id, parsing_schema_name, executions,"569 " to_char(to_date(first_load_time, 'yyyy-mm-dd/hh24:mi:ss'), 'dd.mm hh24:mi')"570 " from v$sqlarea where parsing_schema_name not like '%SYS%'"571 " and executions > :executions order by executions desc"572 , {**t.parameters}573 , 'many'574 , False)575 return t.get_message(r576 , lambda o, i: '{} ({}) executed {} times since {}.'577 .format(t_link(f'{o.target}/Q/{i[0]}', i[0]), i[1], get_num_str(i[2]), i[3])...
spec.py
Source:spec.py
...50 result = defaultdict(list)51 for service in self.services.values():52 result[service.endpoint_prefix].append(service.service_name)53 return dict(result)54 def by_target_prefix(self, target_prefix: str) -> List[ServiceName]:55 return self.target_prefix_index.get(target_prefix, [])56 def by_signing_name(self, signing_name: str) -> List[ServiceName]:57 return self.signing_name_index.get(signing_name, [])58 def by_operation(self, operation_name: str) -> List[ServiceName]:...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!