|
25 | 25 | from redisbench_admin.run.common import ( |
26 | 26 | get_start_time_vars, |
27 | 27 | BENCHMARK_REPETITIONS, |
| 28 | + CIRCLE_BUILD_URL, |
| 29 | + CIRCLE_JOB, |
| 30 | + WH_TOKEN, |
28 | 31 | get_setup_type_and_primaries_count, |
29 | 32 | common_properties_log, |
30 | 33 | print_results_table_stdout, |
|
41 | 44 | from redisbench_admin.run.ssh import ssh_pem_check |
42 | 45 | from redisbench_admin.run_remote.args import TF_OVERRIDE_NAME |
43 | 46 | from redisbench_admin.run_remote.consts import min_recommended_benchmark_duration |
| 47 | +from redisbench_admin.run_remote.notifications import generate_failure_notification |
44 | 48 | from redisbench_admin.run_remote.remote_client import run_remote_client_tool |
45 | 49 | from redisbench_admin.run_remote.remote_db import ( |
46 | 50 | remote_tmpdir_prune, |
|
75 | 79 | EC2_REGION, |
76 | 80 | ) |
77 | 81 |
|
| 82 | +from slack_sdk.webhook import WebhookClient |
78 | 83 |
|
79 | 84 | # 7 days expire |
80 | 85 | STALL_INFO_DAYS = 7 |
@@ -116,6 +121,8 @@ def run_remote_command_logic(args, project_name, project_version): |
116 | 121 | profilers_enabled = args.enable_profilers |
117 | 122 | keep_env_and_topo = args.keep_env_and_topo |
118 | 123 |
|
| 124 | + webhook_url = "https://hooks.slack.com/services/{}".format(WH_TOKEN) |
| 125 | + |
119 | 126 | if args.skip_env_vars_verify is False: |
120 | 127 | check_ec2_env() |
121 | 128 |
|
@@ -144,14 +151,39 @@ def run_remote_command_logic(args, project_name, project_version): |
144 | 151 | clusterconfig, |
145 | 152 | ) = prepare_benchmark_definitions(args) |
146 | 153 |
|
| 154 | + ci_job_link = CIRCLE_BUILD_URL |
| 155 | + ci_job_name = CIRCLE_JOB |
| 156 | + failure_reason = "" |
| 157 | + webhook_notifications_active = False |
| 158 | + webhook_client_slack = None |
| 159 | + if ci_job_link is not None: |
| 160 | + logging.info( |
| 161 | + "Detected where in a CI flow named {}. Here's the reference link: {}".format( |
| 162 | + ci_job_name, ci_job_link |
| 163 | + ) |
| 164 | + ) |
| 165 | + webhook_notifications_active = True |
| 166 | + webhook_client_slack = WebhookClient(webhook_url) |
| 167 | + |
147 | 168 | return_code = 0 |
148 | 169 | if benchmark_defs_result is False: |
149 | 170 | return_code = 1 |
150 | 171 | if args.fail_fast: |
151 | | - logging.critical( |
152 | | - "Detected errors while preparing benchmark definitions. Exiting right away!" |
153 | | - ) |
154 | | - exit(1) |
| 172 | + failure_reason = "Detected errors while preparing benchmark definitions" |
| 173 | + logging.critical("{}. Exiting right away!".format(failure_reason)) |
| 174 | + if webhook_notifications_active: |
| 175 | + generate_failure_notification( |
| 176 | + webhook_client_slack, |
| 177 | + ci_job_name, |
| 178 | + ci_job_link, |
| 179 | + failure_reason, |
| 180 | + tf_github_org, |
| 181 | + tf_github_repo, |
| 182 | + tf_github_branch, |
| 183 | + None, |
| 184 | + ) |
| 185 | + |
| 186 | + exit(return_code) |
155 | 187 |
|
156 | 188 | remote_envs = {} |
157 | 189 | dirname = "." |
@@ -872,10 +904,13 @@ def run_remote_command_logic(args, project_name, project_version): |
872 | 904 | tsname_project_total_failures, |
873 | 905 | ) |
874 | 906 | return_code |= 1 |
| 907 | + failure_reason = "Some unexpected exception was caught during remote work on test named {}".format( |
| 908 | + test_name |
| 909 | + ) |
875 | 910 | logging.critical( |
876 | | - "Some unexpected exception was caught " |
877 | | - "during remote work. Failing test...." |
| 911 | + "{}. Failing test....".format(failure_reason) |
878 | 912 | ) |
| 913 | + |
879 | 914 | logging.critical(sys.exc_info()[0]) |
880 | 915 | print("-" * 60) |
881 | 916 | traceback.print_exc(file=sys.stdout) |
@@ -940,6 +975,20 @@ def run_remote_command_logic(args, project_name, project_version): |
940 | 975 | EXPIRE_TIME_SECS_PROFILE_KEYS, |
941 | 976 | profile_markdown_str, |
942 | 977 | ) |
| 978 | + |
| 979 | + if return_code != 0 and webhook_notifications_active: |
| 980 | + if failure_reason == "": |
| 981 | + failure_reason = "Some unexpected exception was caught during remote work" |
| 982 | + generate_failure_notification( |
| 983 | + webhook_client_slack, |
| 984 | + ci_job_name, |
| 985 | + ci_job_link, |
| 986 | + failure_reason, |
| 987 | + tf_github_org, |
| 988 | + tf_github_repo, |
| 989 | + tf_github_branch, |
| 990 | + None, |
| 991 | + ) |
943 | 992 | exit(return_code) |
944 | 993 |
|
945 | 994 |
|
|
0 commit comments