Skip to content

Commit

Permalink
[forge] report to slack and add loggging link
Browse files Browse the repository at this point in the history
  • Loading branch information
rustielin authored and aptos-bot committed Apr 14, 2022
1 parent 825d42b commit 756e4a1
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 13 deletions.
21 changes: 19 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ orbs:
aws-cli: circleci/[email protected]
aws-ecr: circleci/[email protected]
kubernetes: circleci/[email protected]
slack: circleci/[email protected]

executors:
ubuntu-medium:
Expand Down Expand Up @@ -153,7 +154,7 @@ jobs:
FGI_REPRO_CMD="./scripts/fgi/run --tag $IMAGE_TAG --suite land_blocking --report forge_report.json"
eval $FGI_REPRO_CMD
FGI_EXIT_CODE=$?
echo "export FGI_REPRO_CMD=$FGI_REPRO_CMD" >> $BASH_ENV
echo "export FGI_REPRO_CMD='$FGI_REPRO_CMD'" >> $BASH_ENV
echo "export FGI_EXIT_CODE=$FGI_EXIT_CODE" >> $BASH_ENV
- run:
name: Post Forge test results
Expand All @@ -163,18 +164,34 @@ jobs:
PR_NUMBER=$(echo "${commit_message}" | grep 'Closes: #' | tail -1 | sed 's/Closes: #//')
echo "Repro: $FGI_REPRO_CMD"
FORGE_REPORT_TXT=$(cat forge_report.json | jq -r .text)
echo "export FORGE_REPORT_TXT='$FORGE_REPORT_TXT'" >> $BASH_ENV
cat \<<EOF > forge_comment.txt
Forge run: ${CIRCLE_BUILD_URL}
Forge Test Result: \`$(cat forge_report.json | jq -r .text)\`
Forge Test Result: \`${FORGE_REPORT_TXT}\`
EOF
# replace all newlines
FORGE_COMMENT=$(awk '{printf "%s\\n", $0}' forge_comment.txt)
# post github comment on the PR
curl -s -H "Authorization: token ${FORGE_GH_TOKEN}" \
-X POST -d "{\"body\": \"${FORGE_COMMENT}\"}" \
"https://api.github.com/repos/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}/issues/${PR_NUMBER}/comments"
exit 0
- slack/notify:
custom: |
{
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "[fgi($FGI_EXIT_CODE)] <$CIRCLE_BUILD_URL|Forge run> for $IMAGE_TAG: `$FORGE_REPORT_TXT`"
}
}
]
}
docker-compose-test:
executor: ubuntu-medium
steps:
Expand Down
1 change: 1 addition & 0 deletions scripts/fgi/kube.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
WORKSPACE_CHART_BUCKETS = {
"forge-0": "aptos-testnet-forge-0-helm-312428ba",
"forge-1": "aptos-testnet-forge-1-helm-a2b65112",
"forge-dev": "aptos-testnet-forge-dev-helm-8d0a5291",
}

AWS_ACCOUNT = (
Expand Down
34 changes: 23 additions & 11 deletions scripts/fgi/run
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import subprocess
import sys
import tempfile
import time
from datetime import datetime

from kube import (
kube_init_context,
Expand All @@ -25,9 +26,10 @@ TAG = ""
BASE_TAG = ""
WORKSPACE = ""
REPORT = ""
DEFL_TIMEOUT_SECS = 2700 # Default timeout is 45 mins
DEFL_TIMEOUT_SECS = 1800 # Default timeout is 30 mins
USER = getpass.getuser() # Use the current user for naming
OUTPUT_TEE = os.getenv("FGI_OUTPUT_LOG", tempfile.mkstemp()[1])
TIME_FMT = '%Y-%m-%dT%H:%M:%S.000Z'

HEADER = "\033[95m"
OKBLUE = "\033[94m"
Expand Down Expand Up @@ -92,6 +94,10 @@ def cli_tool_installed(tool_name):
return ret.returncode == 0


def get_opensearch_time(timestamp_ms):
return datetime.fromtimestamp(timestamp_ms/1000).strftime(TIME_FMT)


# ================ Parse the args ================
args, forge_args = build_argparser()

Expand Down Expand Up @@ -229,14 +235,17 @@ except Exception as e:

end_ts_ms = int(time.time() * 1000)
DASHBOARD_LINK = f"{grafana_url}/d/overview/overview?from={start_ts_ms}&to={end_ts_ms}&orgId=1"
LOGGING_LINK = "https://es.forge.aptosdev.com/_dashboards/app/discover#/?_g=(filters:!()," \
"refreshInterval:(pause:!t,value:0),time:(from:now-15m,to:now))&_a=(columns:!(),filters:!()," \
"index:'2da2a6e0-f70a-11eb-ad53-b979a6c9b83a',interval:auto,query:(language:kuery,query:'')," \
"sort:!(!('@timestamp',desc)))"
print("\n**********")
print(
f"{OKBLUE}Dashboard snapshot:{RESTORE} {DASHBOARD_LINK}"
LOGGING_LINK = (
"https://es.devinfra.aptosdev.com/_dashboards/app/discover#/?_g=(filters:!(),"
f"refreshInterval:(pause:!t,value:0),time:(from:'{get_opensearch_time(start_ts_ms)}',to:'{get_opensearch_time(end_ts_ms)}'))&_a=(columns:!(_source),filters:!,"
"(('$state':(store:appState),meta:(alias:!n,disabled:!f,index:ac3499a0-abc8-11ec-9a50-89b84ac337af,"
f"key:chain_name,negate:!f,params:(query:aptos-{workspace}),type:phrase),query:(match_phrase:(chain_name:aptos-{workspace})))),"
"index:ac3499a0-abc8-11ec-9a50-89b84ac337af,interval:auto,query:(language:kuery,query:''),sort:!())"
)

print("\n**********")
print(f"{OKBLUE}Dashboard snapshot:{RESTORE} {DASHBOARD_LINK}")
print(f"{OKBLUE}Logs snapshot:{RESTORE} {LOGGING_LINK}")
print("**********\n")

test_res = 'failed'
Expand All @@ -245,11 +254,14 @@ test_report = []
read_lines = False
with open(f"{OUTPUT_TEE}", 'r') as file:
for line in file.readlines():
if 'json-report-end' in line: read_lines = False
if 'json-report-end' in line:
read_lines = False
if read_lines:
test_report.append(line)
if 'json-report-begin' in line: read_lines = True
if 'test result: ok' in line: test_res = 'passed'
if 'json-report-begin' in line:
read_lines = True
if 'test result: ok' in line:
test_res = 'passed'
if len(test_report) == 0:
test_report.append("{\"text\": \"Forge test runner is terminated\"}")
temp = json.loads(''.join(test_report))
Expand Down

0 comments on commit 756e4a1

Please sign in to comment.