Skip to content

Commit bb41211

Browse files
Merge pull request #1194 from getlipa/feature/report-monitor-results-to-slack
Report monitoring results to slack
2 parents f00faf6 + 1f35c6f commit bb41211

File tree

7 files changed

+413
-133
lines changed

7 files changed

+413
-133
lines changed

.github/workflows/e2e_tests.yml

Lines changed: 0 additions & 34 deletions
This file was deleted.
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: Monitoring Tests
2+
3+
on:
4+
schedule:
5+
- cron: '21 2 * * *' # every day at 2:21 AM UTC
6+
workflow_dispatch: # allow manually triggering a run
7+
8+
9+
env:
10+
GITHUB_REF: ${{ github.ref }}
11+
12+
jobs:
13+
integration:
14+
name: Monitoring Tests
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: rust-toolchain
18+
uses: actions-rs/toolchain@v1.0.6
19+
with:
20+
toolchain: nightly
21+
override: true
22+
- name: Install Protoc
23+
uses: arduino/setup-protoc@v3
24+
with:
25+
repo-token: ${{ secrets.GITHUB_TOKEN }}
26+
- name: Checkout
27+
uses: actions/checkout@v3
28+
with:
29+
submodules: true
30+
- name: Config cargo
31+
run: echo -e "$CARGO_CONFIG_TOML_BREEZ" > .cargo/config.toml
32+
env:
33+
CARGO_CONFIG_TOML_BREEZ: ${{ secrets.CARGO_CONFIG_TOML_BREEZ }}
34+
- name: Rust Cache
35+
uses: Swatinem/rust-cache@v2.7.0
36+
- name: Restore .3l_local_test cache
37+
uses: actions/cache/restore@v4
38+
with:
39+
path: .3l_local_test
40+
key: monitor-local-test-cache
41+
- name: Run monitoring tests
42+
id: monitortest
43+
run: make monitortest
44+
continue-on-error: true
45+
- name: Save .3l_local_test cache
46+
uses: actions/cache/save@v4
47+
with:
48+
path: .3l_local_test
49+
key: monitor-local-test-cache
50+
- name: Check test result
51+
run: |
52+
if [ ${{ steps.monitortest.outcome }} == "failure" ]; then
53+
echo "Tests failed"
54+
echo "failure" > test_status.txt
55+
else
56+
echo "Tests passed"
57+
echo "success" > test_status.txt
58+
fi
59+
- name: Process and publish results
60+
run: |
61+
./generate_report.sh
62+
63+
TEST_STATUS=$(cat test_status.txt)
64+
if [ "$TEST_STATUS" = "failure" ]; then
65+
curl -X POST \
66+
-H "Content-type: application/json" \
67+
--data "$(cat slack_message.json)" \
68+
${{ secrets.LIPA_SLACK_3L_MONITORING_FAILURE_BOT_WEBHOOK_URL }}
69+
else
70+
curl -X POST \
71+
-H "Content-type: application/json" \
72+
--data "$(cat slack_message.json)" \
73+
${{ secrets.LIPA_SLACK_3L_MONITORING_BOT_WEBHOOK_URL }}
74+
fi

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
.eel_node
99
.eel_remote
1010
.idea
11+
test.json
12+
test_times.json
13+
slack_message.json
1114

1215
bindings
1316

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ integrationtests:
3535
testregisternode:
3636
cargo test --test register_node_test -- --ignored --nocapture
3737

38-
.PHONY: testsatflows
39-
testsatflows:
40-
cargo test --test sat_flows -- --ignored --nocapture
38+
.PHONY: monitortest
39+
monitortest:
40+
cargo +nightly test --test monitoring_test -- --test-threads=1 --ignored -Z unstable-options --report-time --format json > test.json
4141

4242
.PHONY: testall
4343
testall: test integrationtests

generate_report.sh

Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
#!/bin/bash
2+
3+
# Define the input files and output json file
4+
INPUT_FILE="test.json"
5+
TIMES_FILE="test_times.json"
6+
OUTPUT_FILE="slack_message.json"
7+
8+
# Initialize variables
9+
PASSED_TESTS=()
10+
FAILED_TESTS=()
11+
TEST_NAMES=()
12+
TEST_TIMES=()
13+
14+
# Clear the output file if it already exists
15+
> "$OUTPUT_FILE"
16+
17+
# Function to create the header block for the Slack message
18+
create_header_block() {
19+
cat <<EOF >> "$OUTPUT_FILE"
20+
{
21+
"blocks": [
22+
{
23+
"type": "header",
24+
"text": {
25+
"type": "plain_text",
26+
"text": "3L Monitoring Test Report :test_tube:",
27+
"emoji": true
28+
}
29+
},
30+
{
31+
"type": "divider"
32+
},
33+
EOF
34+
}
35+
36+
# Function to create the summary block for the Slack message
37+
create_summary_block() {
38+
total_passed=$1
39+
total_failed=$2
40+
41+
cat <<EOF >> "$OUTPUT_FILE"
42+
{
43+
"type": "section",
44+
"fields": [
45+
{
46+
"type": "mrkdwn",
47+
"text": "*Total Tests Passed:*\n$total_passed"
48+
},
49+
{
50+
"type": "mrkdwn",
51+
"text": "*Total Tests Failed:*\n$total_failed"
52+
}
53+
]
54+
},
55+
{
56+
"type": "divider"
57+
},
58+
EOF
59+
}
60+
61+
# Function to create the passed tests block
62+
create_passed_tests_block() {
63+
if [ ${#PASSED_TESTS[@]} -gt 0 ]; then
64+
echo " {" >> "$OUTPUT_FILE"
65+
echo ' "type": "section",' >> "$OUTPUT_FILE"
66+
echo ' "text": {' >> "$OUTPUT_FILE"
67+
echo ' "type": "mrkdwn",' >> "$OUTPUT_FILE"
68+
echo ' "text": "*Passed Tests:*"' >> "$OUTPUT_FILE"
69+
echo " }," >> "$OUTPUT_FILE"
70+
echo ' "fields": [' >> "$OUTPUT_FILE"
71+
for test in "${PASSED_TESTS[@]}"; do
72+
echo ' {' >> "$OUTPUT_FILE"
73+
echo ' "type": "mrkdwn",' >> "$OUTPUT_FILE"
74+
echo ' "text": "`'$test'`"' >> "$OUTPUT_FILE"
75+
echo ' },' >> "$OUTPUT_FILE"
76+
done
77+
echo ' ]' >> "$OUTPUT_FILE"
78+
echo ' },' >> "$OUTPUT_FILE"
79+
echo ' {' >> "$OUTPUT_FILE"
80+
echo ' "type": "divider"' >> "$OUTPUT_FILE"
81+
echo ' },' >> "$OUTPUT_FILE"
82+
fi
83+
}
84+
85+
# Function to create the failed tests block
86+
create_failed_tests_block() {
87+
if [ ${#FAILED_TESTS[@]} -gt 0 ]; then
88+
echo " {" >> "$OUTPUT_FILE"
89+
echo ' "type": "section",' >> "$OUTPUT_FILE"
90+
echo ' "text": {' >> "$OUTPUT_FILE"
91+
echo ' "type": "mrkdwn",' >> "$OUTPUT_FILE"
92+
echo ' "text": "*Failed Tests:*"' >> "$OUTPUT_FILE"
93+
echo " }," >> "$OUTPUT_FILE"
94+
echo ' "fields": [' >> "$OUTPUT_FILE"
95+
96+
for test in "${FAILED_TESTS[@]}"; do
97+
test_name=$(echo "$test" | cut -d "|" -f 1)
98+
99+
# Add the test name as its own field
100+
echo ' {' >> "$OUTPUT_FILE"
101+
echo ' "type": "mrkdwn",' >> "$OUTPUT_FILE"
102+
echo ' "text": "`'$test_name'`"' >> "$OUTPUT_FILE"
103+
echo ' },' >> "$OUTPUT_FILE"
104+
done
105+
106+
echo ' ]' >> "$OUTPUT_FILE"
107+
echo ' },' >> "$OUTPUT_FILE"
108+
fi
109+
}
110+
111+
# Function to create the test execution times block
112+
create_test_times_block() {
113+
if [ ${#TEST_NAMES[@]} -gt 0 ]; then
114+
echo " {" >> "$OUTPUT_FILE"
115+
echo ' "type": "section",' >> "$OUTPUT_FILE"
116+
echo ' "text": {' >> "$OUTPUT_FILE"
117+
echo ' "type": "mrkdwn",' >> "$OUTPUT_FILE"
118+
echo ' "text": "*Execution Times:*"' >> "$OUTPUT_FILE"
119+
echo " }," >> "$OUTPUT_FILE"
120+
echo ' "fields": [' >> "$OUTPUT_FILE"
121+
for i in "${!TEST_NAMES[@]}"; do
122+
echo ' {' >> "$OUTPUT_FILE"
123+
echo ' "type": "mrkdwn",' >> "$OUTPUT_FILE"
124+
echo ' "text": "`'${TEST_NAMES[$i]}'`: '${TEST_TIMES[$i]}' seconds"' >> "$OUTPUT_FILE"
125+
echo ' },' >> "$OUTPUT_FILE"
126+
done
127+
echo ' ]' >> "$OUTPUT_FILE"
128+
echo ' },' >> "$OUTPUT_FILE"
129+
echo ' {' >> "$OUTPUT_FILE"
130+
echo ' "type": "divider"' >> "$OUTPUT_FILE"
131+
echo ' },' >> "$OUTPUT_FILE"
132+
fi
133+
}
134+
135+
# Function to end the JSON message block
136+
end_json_block() {
137+
echo " ]" >> "$OUTPUT_FILE"
138+
echo "}" >> "$OUTPUT_FILE"
139+
}
140+
141+
# Parse the test times JSON file and store in parallel arrays
142+
while IFS= read -r line; do
143+
test_name=$(echo "$line" | jq -r '.test')
144+
time_seconds=$(echo "$line" | jq -r '.time_seconds')
145+
146+
# Store test names and execution times in parallel arrays
147+
TEST_NAMES+=("$test_name")
148+
TEST_TIMES+=("$time_seconds")
149+
done < "$TIMES_FILE"
150+
151+
# Parse the test result JSON line by line
152+
while IFS= read -r line; do
153+
# Parse the type and event fields from the JSON line
154+
type=$(echo "$line" | jq -r '.type')
155+
event=$(echo "$line" | jq -r '.event')
156+
157+
if [[ "$type" == "test" ]]; then
158+
test_name=$(echo "$line" | jq -r '.name')
159+
160+
if [[ "$event" == "ok" ]]; then
161+
PASSED_TESTS+=("$test_name")
162+
elif [[ "$event" == "failed" ]]; then
163+
FAILED_TESTS+=("$test_name")
164+
fi
165+
elif [[ "$type" == "suite" && ("$event" == "ok" || "$event" == "failed")]]; then
166+
total_passed=$(echo "$line" | jq -r '.passed')
167+
total_failed=$(echo "$line" | jq -r '.failed')
168+
169+
# Create header and summary in the Slack message
170+
create_header_block
171+
create_summary_block "$total_passed" "$total_failed"
172+
fi
173+
done < "$INPUT_FILE"
174+
175+
# Write the Slack message
176+
create_passed_tests_block
177+
create_failed_tests_block
178+
create_test_times_block
179+
end_json_block
180+
181+
echo "Slack Block Kit JSON message generated in $OUTPUT_FILE"

0 commit comments

Comments
 (0)