Skip to content

Commit 863a7e6

Browse files
feature/callback: add callback in to run_remote logic (#378)
* feature/callback: add callback in to run_remote logic * feature/callback: test fix for gnupg * feature/callback: remove cat gpg.conf command from action * feature/callback: try another way of fix gnupg problem * feature/callback: remove actions-setup-docker * feature/callback: different poetry install * feature/callback: shell way to install poetry * feature/callback: try another actions lib to install poetry * feature/callback: fix file * feature/callback: poetry version * feature/callback: test ci without python3.6 * feature/callback: fix formatting * feature/callback: fix what flake8 found * feature/callback: add callback url * feature/callback: change github env variable name to avoid problem with github actions env * feature/callback: remove branch, workflow id from request, make github token not required * feature/callback: fix callback url formatting * feature/callback: callback_headers statement in function * formatter check fix Co-authored-by: filipe oliveira <[email protected]>
1 parent 0d289b5 commit 863a7e6

File tree

5 files changed

+71
-2
lines changed

5 files changed

+71
-2
lines changed

.github/workflows/tox.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ jobs:
2525
with:
2626
python-version: ${{ matrix.python-version }}
2727

28-
- uses: docker-practice/actions-setup-docker@master
29-
3028
- name: Install Poetry
3129
run: |
3230
curl -sSL https://install.python-poetry.org | python3 -

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ utilities/redis_benchmarks_specification/__pycache__/
1717
*.py[cod]
1818
*$py.class
1919

20+
# mac
21+
.DS_Store
22+
2023
# C extensions
2124
*.so
2225
*.so.1

redisbench_admin/run_remote/args.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,19 @@ def create_run_remote_arguments(parser):
9898
type=str,
9999
help="Use this key for ssh connections.",
100100
)
101+
parser.add_argument(
102+
"--callback",
103+
required=False,
104+
default=False,
105+
action="store_true",
106+
help="Push status to callback url",
107+
)
108+
parser.add_argument(
109+
"--callback_url",
110+
required=False,
111+
default="https://dashi.cto.redislabs.com/callback",
112+
help="Callback url",
113+
)
101114
parser.add_argument("--terraform_bin_path", type=str, default=TERRAFORM_BIN_PATH)
102115
parser.add_argument("--setup_name_sufix", type=str, default="")
103116
parser.add_argument(

redisbench_admin/run_remote/run_remote.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
EC2_ACCESS_KEY,
7878
EC2_SECRET_KEY,
7979
EC2_REGION,
80+
make_dashboard_callback,
8081
)
8182

8283
from slack_sdk.webhook import WebhookClient
@@ -1070,6 +1071,15 @@ def run_remote_command_logic(args, project_name, project_version):
10701071
tf_github_branch,
10711072
None,
10721073
)
1074+
if args.callback:
1075+
make_dashboard_callback(
1076+
args.callback_url,
1077+
return_code,
1078+
ci_job_name,
1079+
tf_github_repo,
1080+
tf_github_branch,
1081+
tf_github_sha,
1082+
)
10731083
exit(return_code)
10741084

10751085

redisbench_admin/utils/utils.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,51 @@ def wait_for_conn(conn, retries=20, command="PING", should_be=True, initial_slee
383383
return result
384384

385385

386+
def make_dashboard_callback(
387+
callback_url,
388+
return_code,
389+
ci_job_name,
390+
tf_github_repo,
391+
tf_github_branch,
392+
tf_github_sha,
393+
):
394+
callback_headers = {}
395+
status = "success"
396+
if return_code != 0:
397+
status = "failed"
398+
github_token = os.getenv("GH_TOKEN", None)
399+
if github_token is None:
400+
logging.error(
401+
"-- github token is None. Callback will be send without github-token header --"
402+
)
403+
else:
404+
callback_headers = {"Github-Token": github_token}
405+
callback_url = (
406+
"{}"
407+
"?repository={}"
408+
"&test_name={}"
409+
"&status={}"
410+
"&commit={}".format(
411+
callback_url,
412+
tf_github_repo,
413+
ci_job_name,
414+
status,
415+
tf_github_sha,
416+
)
417+
)
418+
logging.info("-- make callback to {} -- ".format(callback_url))
419+
try:
420+
request = requests.get(callback_url, headers=callback_headers, timeout=10)
421+
except Exception as ex:
422+
logging.error("-- callback request exception: {}".format(ex))
423+
return
424+
logging.info(
425+
"-- callback response {} and body {} -- ".format(
426+
request.status_code, request.text.replace("\n", " ")
427+
)
428+
)
429+
430+
386431
EC2_REGION = os.getenv("AWS_DEFAULT_REGION", None)
387432
EC2_SECRET_KEY = os.getenv("AWS_SECRET_ACCESS_KEY", None)
388433
EC2_PRIVATE_PEM = os.getenv("EC2_PRIVATE_PEM", None)

0 commit comments

Comments
 (0)