fix: enhance performance check to account for slow endpoints and improve reporting

This commit is contained in:
mirage
2026-03-27 13:29:18 +01:00
parent a18af7537e
commit b8efa61e08

View File

@@ -57,7 +57,7 @@ jobs:
sleep 1 sleep 1
done done
' '
echo "Application prête !" echo "Application prête!"
- name: Test endpoint response times - name: Test endpoint response times
id: perf_test id: perf_test
@@ -66,20 +66,23 @@ jobs:
bash scripts/test-endpoints.sh http://localhost:5038 1000 2>&1 | tee /tmp/webzine_endpoint_output.txt bash scripts/test-endpoints.sh http://localhost:5038 1000 2>&1 | tee /tmp/webzine_endpoint_output.txt
EXIT_CODE=${PIPESTATUS[0]} EXIT_CODE=${PIPESTATUS[0]}
# Count failures (but not slow endpoints as failures) # Count failures
FAIL_COUNT=$(grep -cE "^\[ÉCHEC\]" /tmp/webzine_endpoint_output.txt 2>/dev/null || echo 0) FAIL_COUNT=$(grep -cE "^\[ÉCHEC\]" /tmp/webzine_endpoint_output.txt 2>/dev/null || echo 0)
SLOW_COUNT=$(grep -cE "^\[LENT\]" /tmp/webzine_endpoint_output.txt 2>/dev/null || echo 0) SLOW_COUNT=$(grep -cE "^\[LENT\]" /tmp/webzine_endpoint_output.txt 2>/dev/null || echo 0)
echo "failed=$FAIL_COUNT" >> "$GITHUB_OUTPUT" echo "failed=$FAIL_COUNT" >> "$GITHUB_OUTPUT"
echo "slow=$SLOW_COUNT" >> "$GITHUB_OUTPUT" echo "slow=$SLOW_COUNT" >> "$GITHUB_OUTPUT"
# Only fail if there are actual failures # Échoue sil y a DES problèmes (échecs OU lents)
if [ $FAIL_COUNT -gt 0 ]; then if [ $FAIL_COUNT -gt 0 ] || [ $SLOW_COUNT -gt 0 ]; then
echo "❌ Performance check failed: $FAIL_COUNT endpoint(s) failed, $SLOW_COUNT endpoint(s) exceeded threshold (1000ms)"
exit 1 exit 1
fi fi
echo "✅ All endpoints passed performance check (< 1000ms)"
- name: Post performance report as PR comment - name: Post performance report as PR comment
if: always() if: always() # Always post comment, even on failure
env: env:
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
GITEA_SERVER_URL: ${{ gitea.server_url }} GITEA_SERVER_URL: ${{ gitea.server_url }}
@@ -88,12 +91,21 @@ jobs:
run: | run: |
RAW_REPORT=$(cat /tmp/webzine_endpoint_output.txt 2>/dev/null || echo "Aucune sortie capturée.") RAW_REPORT=$(cat /tmp/webzine_endpoint_output.txt 2>/dev/null || echo "Aucune sortie capturée.")
FAILED_COUNT="${{ steps.perf_test.outputs.failed }}" FAILED_COUNT="${{ steps.perf_test.outputs.failed }}"
SLOW_COUNT="${{ steps.perf_test.outputs.slow }}"
# Convertir le rapport ANSI en Markdown avec couleurs # Determine if the check passed or failed
# Supprimer d'abord les codes ANSI pour le traitement if [ "$FAILED_COUNT" -gt 0 ] || [ "$SLOW_COUNT" -gt 0 ]; then
STATUS_HEADER="❌ **PERFORMANCE CHECK FAILED**"
STATUS_ICON="❌"
else
STATUS_HEADER="✅ **PERFORMANCE CHECK PASSED**"
STATUS_ICON="✅"
fi
# Convert report to Markdown with colors
CLEAN_REPORT=$(echo "$RAW_REPORT" | sed 's/\x1b\[[0-9;]*m//g') CLEAN_REPORT=$(echo "$RAW_REPORT" | sed 's/\x1b\[[0-9;]*m//g')
# Générer le rapport formaté en Markdown avec couleurs # Generate formatted report
FORMATTED_REPORT=$(echo "$CLEAN_REPORT" | sed \ FORMATTED_REPORT=$(echo "$CLEAN_REPORT" | sed \
-e 's/^\[OK\] /✅ /' \ -e 's/^\[OK\] /✅ /' \
-e 's/^\[LENT\] /⚠️ /' \ -e 's/^\[LENT\] /⚠️ /' \
@@ -105,16 +117,22 @@ jobs:
-e 's/^\(Total.*\)$/\n**\1**/' \ -e 's/^\(Total.*\)$/\n**\1**/' \
-e 's/^\(Réussis.*\)$/**✅ \1**/' \ -e 's/^\(Réussis.*\)$/**✅ \1**/' \
-e 's/^\(Échecs.*\)$/**❌ \1**/' \ -e 's/^\(Échecs.*\)$/**❌ \1**/' \
-e 's/^\(⚠️ ENDPOINTS LENTS.*\)$/\n### \1/' \
-e 's/^\(❌ ENDPOINTS EN ÉCHEC.*\)$/\n### \1/' \ -e 's/^\(❌ ENDPOINTS EN ÉCHEC.*\)$/\n### \1/' \
-e 's/^\(La PR doit.*\)$/\n**❌ \1**/' \ -e 's/^\(La PR doit.*\)$/\n**❌ \1**/')
-e 's/^╔\(.*\)╗$/```\n╔\1╗/' \
-e 's/^╚\(.*\)╝$/╚\1╝\n```/')
BODY=$(cat <<EOF BODY=$(cat <<EOF
$STATUS_HEADER
$FORMATTED_REPORT $FORMATTED_REPORT
--- ---
**Seuil**: 1000ms **Seuil**: 1000ms
**Statistiques**:
- ✅ Endpoints rapides: \$(grep -c "^\[OK\]" /tmp/webzine_endpoint_output.txt 2>/dev/null || echo 0)
- ⚠️ Endpoints lents (>1000ms): $SLOW_COUNT
- ❌ Endpoints en échec: $FAILED_COUNT
**Vérifié par**: Workflow PR Endpoint Performance **Vérifié par**: Workflow PR Endpoint Performance
EOF EOF
) )
@@ -123,4 +141,10 @@ jobs:
-H "Authorization: token $GITEA_TOKEN" \ -H "Authorization: token $GITEA_TOKEN" \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
-d "$(jq -n --arg body "$BODY" '{body: $body}')" \ -d "$(jq -n --arg body "$BODY" '{body: $body}')" \
"$GITEA_SERVER_URL/api/v1/repos/$REPO/issues/$PR_NUMBER/comments" "$GITEA_SERVER_URL/api/v1/repos/$REPO/issues/$PR_NUMBER/comments"
- name: Fail job if performance issues detected
if: steps.perf_test.outputs.failed > 0 || steps.perf_test.outputs.slow > 0
run: |
echo "❌ Job failed due to performance issues"
exit 1