From b753866b982a6cc82edbf46f1e5a664312f64ee7 Mon Sep 17 00:00:00 2001 From: grabowski Date: Wed, 13 Aug 2025 14:28:25 +0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20Make=20health=20checks=20more=20?= =?UTF-8?q?robust=20with=20detailed=20debugging?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ๐Ÿ” Enhanced Debugging: - Show HTTP response codes and response bodies - Remove -f flag that was causing curl to fail on valid responses - Add detailed logging for each endpoint test - Show container logs on failures ๐ŸŒ Improved Health Check Logic: - Check HTTP code = 200 AND response body exists - Use curl -w to capture HTTP status codes - Parse response and status separately - More tolerant of response format variations ๐Ÿงช Better API Endpoint Testing: - Test each endpoint individually with status reporting - Show specific HTTP codes for each endpoint - Clear success/failure messages per endpoint - Exit only on actual HTTP errors ๐ŸŽฏ Addresses CI-Specific Issues: - Local testing shows endpoints work correctly - CI environment may have different curl behavior - More detailed output will help identify root cause - Removes false failures from -f flag sensitivity Should resolve curl failures despite HTTP 200 responses --- .gitea/workflows/release.yml | 39 ++++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/.gitea/workflows/release.yml b/.gitea/workflows/release.yml index 714158f..3a9b7b8 100644 --- a/.gitea/workflows/release.yml +++ b/.gitea/workflows/release.yml @@ -223,25 +223,48 @@ jobs: for i in {1..15}; do echo "โณ Attempt $i/15: Testing health endpoint..." - # Use curl with more verbose output and longer timeout - if curl -f -s --max-time 10 --connect-timeout 5 http://127.0.0.1:8080/health; then + # Test health endpoint with detailed debugging + echo "Testing health endpoint..." + + # First try with verbose output to see what's happening + response=$(curl -s --max-time 10 --connect-timeout 5 -w "HTTP_CODE:%{http_code}" http://127.0.0.1:8080/health) + http_code=$(echo "$response" | grep -o "HTTP_CODE:[0-9]*" | cut -d: -f2) + response_body=$(echo "$response" | sed 's/HTTP_CODE:[0-9]*$//') + + echo "HTTP Code: $http_code" + echo "Response Body: $response_body" + + if [ "$http_code" = "200" ] && [ -n "$response_body" ]; then echo "โœ… Health endpoint responding successfully!" break else - echo "โŒ Health check failed, waiting 15 seconds..." + echo "โŒ Health check failed (HTTP: $http_code), waiting 15 seconds..." # Show what's happening with the container echo "Container status:" docker ps | grep ping-river-monitor-test || echo "Container not found" + echo "Recent container logs:" + docker logs --tail 5 ping-river-monitor-test || true sleep 15 fi done - # Test API endpoints + # Test API endpoints with better error handling echo "๐Ÿงช Testing API endpoints..." - curl -f http://127.0.0.1:8080/health || exit 1 - curl -f http://127.0.0.1:8080/docs || exit 1 - curl -f http://127.0.0.1:8080/stations || exit 1 - curl -f http://127.0.0.1:8080/metrics || exit 1 + + endpoints=("health" "docs" "stations" "metrics") + for endpoint in "${endpoints[@]}"; do + echo "Testing /$endpoint..." + response=$(curl -s --max-time 10 -w "HTTP_CODE:%{http_code}" http://127.0.0.1:8080/$endpoint) + http_code=$(echo "$response" | grep -o "HTTP_CODE:[0-9]*" | cut -d: -f2) + + if [ "$http_code" = "200" ]; then + echo "โœ… /$endpoint: OK (HTTP $http_code)" + else + echo "โŒ /$endpoint: FAILED (HTTP $http_code)" + echo "Response: $(echo "$response" | sed 's/HTTP_CODE:[0-9]*$//')" + exit 1 + fi + done echo "โœ… All health checks passed!"