Skip to content

Commit

Permalink
Report monitoring results to slack
Browse files Browse the repository at this point in the history
  • Loading branch information
danielgranhao committed Sep 20, 2024
1 parent 3b06a95 commit d380b22
Show file tree
Hide file tree
Showing 7 changed files with 396 additions and 133 deletions.
34 changes: 0 additions & 34 deletions .github/workflows/e2e_tests.yml

This file was deleted.

57 changes: 57 additions & 0 deletions .github/workflows/monitoring-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: E2E Tests

on:
push:
branches:
- main
pull_request:
schedule:
- cron: '21 2 * * *' # every day at 5:21 AM UTC

env:
GITHUB_REF: ${{ github.ref }}

jobs:
integration:
name: Monitoring Tests
runs-on: ubuntu-latest
steps:
- name: rust-toolchain
uses: actions-rs/toolchain@v1.0.6
with:
toolchain: nightly
override: true
- name: Install Protoc
uses: arduino/setup-protoc@v3
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Checkout
uses: actions/checkout@v3
with:
submodules: true
- name: Config cargo
run: echo -e "$CARGO_CONFIG_TOML_BREEZ" > .cargo/config.toml
env:
CARGO_CONFIG_TOML_BREEZ: ${{ secrets.CARGO_CONFIG_TOML_BREEZ }}
- name: Rust Cache
uses: Swatinem/rust-cache@v2.7.0
- name: Restore .3l_local_test cache
uses: actions/cache/restore@v4
with:
path: .3l_local_test
key: monitor-local-test-cache
- name: Run monitoring tests
run: make monitortest
- name: Save .3l_local_test cache
uses: actions/save/cache@v4
with:
path: .3l_local_test
key: monitor-local-test-cache
- name: Process and publish results
run: |
./generate_report.sh
curl -X POST \
-H "Content-type: application/json" \
--data "$(cat slack_message.json)" \
${{ secrets.LIPA_SLACK_3L_MONITORING_BOT_WEBHOOK_URL }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
.eel_node
.eel_remote
.idea
test.json
test_times.json
slack_message.json

bindings

Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ integrationtests:
testregisternode:
cargo test --test register_node_test -- --ignored --nocapture

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

.PHONY: testall
testall: test integrationtests
Expand Down
181 changes: 181 additions & 0 deletions generate_report.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
#!/bin/bash

# Define the input files and output json file
INPUT_FILE="test.json"
TIMES_FILE="test_times.json"
OUTPUT_FILE="slack_message.json"

# Initialize variables
PASSED_TESTS=()
FAILED_TESTS=()
TEST_NAMES=()
TEST_TIMES=()

# Clear the output file if it already exists
> "$OUTPUT_FILE"

# Function to create the header block for the Slack message
create_header_block() {
cat <<EOF >> "$OUTPUT_FILE"
{
"blocks": [
{
"type": "header",
"text": {
"type": "plain_text",
"text": "3L Monitoring Test Report :test_tube:",
"emoji": true
}
},
{
"type": "divider"
},
EOF
}

# Function to create the summary block for the Slack message
create_summary_block() {
total_passed=$1
total_failed=$2

cat <<EOF >> "$OUTPUT_FILE"
{
"type": "section",
"fields": [
{
"type": "mrkdwn",
"text": "*Total Tests Passed:*\n$total_passed"
},
{
"type": "mrkdwn",
"text": "*Total Tests Failed:*\n$total_failed"
}
]
},
{
"type": "divider"
},
EOF
}

# Function to create the passed tests block
create_passed_tests_block() {
if [ ${#PASSED_TESTS[@]} -gt 0 ]; then
echo " {" >> "$OUTPUT_FILE"
echo ' "type": "section",' >> "$OUTPUT_FILE"
echo ' "text": {' >> "$OUTPUT_FILE"
echo ' "type": "mrkdwn",' >> "$OUTPUT_FILE"
echo ' "text": "*Passed Tests:*"' >> "$OUTPUT_FILE"
echo " }," >> "$OUTPUT_FILE"
echo ' "fields": [' >> "$OUTPUT_FILE"
for test in "${PASSED_TESTS[@]}"; do
echo ' {' >> "$OUTPUT_FILE"
echo ' "type": "mrkdwn",' >> "$OUTPUT_FILE"
echo ' "text": "`'$test'`"' >> "$OUTPUT_FILE"
echo ' },' >> "$OUTPUT_FILE"
done
echo ' ]' >> "$OUTPUT_FILE"
echo ' },' >> "$OUTPUT_FILE"
echo ' {' >> "$OUTPUT_FILE"
echo ' "type": "divider"' >> "$OUTPUT_FILE"
echo ' },' >> "$OUTPUT_FILE"
fi
}

# Function to create the failed tests block
create_failed_tests_block() {
if [ ${#FAILED_TESTS[@]} -gt 0 ]; then
echo " {" >> "$OUTPUT_FILE"
echo ' "type": "section",' >> "$OUTPUT_FILE"
echo ' "text": {' >> "$OUTPUT_FILE"
echo ' "type": "mrkdwn",' >> "$OUTPUT_FILE"
echo ' "text": "*Failed Tests:*"' >> "$OUTPUT_FILE"
echo " }," >> "$OUTPUT_FILE"
echo ' "fields": [' >> "$OUTPUT_FILE"

for test in "${FAILED_TESTS[@]}"; do
test_name=$(echo "$test" | cut -d "|" -f 1)

# Add the test name as its own field
echo ' {' >> "$OUTPUT_FILE"
echo ' "type": "mrkdwn",' >> "$OUTPUT_FILE"
echo ' "text": "`'$test_name'`"' >> "$OUTPUT_FILE"
echo ' },' >> "$OUTPUT_FILE"
done

echo ' ]' >> "$OUTPUT_FILE"
echo ' },' >> "$OUTPUT_FILE"
fi
}

# Function to create the test execution times block
create_test_times_block() {
if [ ${#TEST_NAMES[@]} -gt 0 ]; then
echo " {" >> "$OUTPUT_FILE"
echo ' "type": "section",' >> "$OUTPUT_FILE"
echo ' "text": {' >> "$OUTPUT_FILE"
echo ' "type": "mrkdwn",' >> "$OUTPUT_FILE"
echo ' "text": "*Test Execution Times:*"' >> "$OUTPUT_FILE"
echo " }," >> "$OUTPUT_FILE"
echo ' "fields": [' >> "$OUTPUT_FILE"
for i in "${!TEST_NAMES[@]}"; do
echo ' {' >> "$OUTPUT_FILE"
echo ' "type": "mrkdwn",' >> "$OUTPUT_FILE"
echo ' "text": "`'${TEST_NAMES[$i]}'`: '${TEST_TIMES[$i]}' seconds"' >> "$OUTPUT_FILE"
echo ' },' >> "$OUTPUT_FILE"
done
echo ' ]' >> "$OUTPUT_FILE"
echo ' },' >> "$OUTPUT_FILE"
echo ' {' >> "$OUTPUT_FILE"
echo ' "type": "divider"' >> "$OUTPUT_FILE"
echo ' },' >> "$OUTPUT_FILE"
fi
}

# Function to end the JSON message block
end_json_block() {
echo " ]" >> "$OUTPUT_FILE"
echo "}" >> "$OUTPUT_FILE"
}

# Parse the test times JSON file and store in parallel arrays
while IFS= read -r line; do
test_name=$(echo "$line" | jq -r '.test')
time_seconds=$(echo "$line" | jq -r '.time_seconds')

# Store test names and execution times in parallel arrays
TEST_NAMES+=("$test_name")
TEST_TIMES+=("$time_seconds")
done < "$TIMES_FILE"

# Parse the test result JSON line by line
while IFS= read -r line; do
# Parse the type and event fields from the JSON line
type=$(echo "$line" | jq -r '.type')
event=$(echo "$line" | jq -r '.event')

if [[ "$type" == "test" ]]; then
test_name=$(echo "$line" | jq -r '.name')

if [[ "$event" == "ok" ]]; then
PASSED_TESTS+=("$test_name")
elif [[ "$event" == "failed" ]]; then
FAILED_TESTS+=("$test_name")
fi
elif [[ "$type" == "suite" && ("$event" == "ok" || "$event" == "failed")]]; then
total_passed=$(echo "$line" | jq -r '.passed')
total_failed=$(echo "$line" | jq -r '.failed')

# Create header and summary in the Slack message
create_header_block
create_summary_block "$total_passed" "$total_failed"
fi
done < "$INPUT_FILE"

# Write the Slack message
create_passed_tests_block
create_failed_tests_block
create_test_times_block
end_json_block

echo "Slack Block Kit JSON message generated in $OUTPUT_FILE"
Loading

0 comments on commit d380b22

Please sign in to comment.