feat: Implement Grafana Cloud fixes

This commit is contained in:
gpt-engineer-app[bot]
2025-10-30 16:00:03 +00:00
parent 72a7cb7f7c
commit 63dbd2efd4
5 changed files with 313 additions and 85 deletions

View File

@@ -29,51 +29,41 @@ jobs:
fi
echo "✅ Required secrets validated"
- name: Check Loki Connection
if: ${{ secrets.GRAFANA_LOKI_URL != '' }}
run: |
echo "🔍 Testing Loki connection..."
if [ -n "${{ secrets.GRAFANA_LOKI_USERNAME }}" ]; then
response=$(curl -s -o /dev/null -w "%{http_code}" \
-u "${{ secrets.GRAFANA_LOKI_USERNAME }}:${{ secrets.GRAFANA_LOKI_PASSWORD }}" \
"${{ secrets.GRAFANA_LOKI_URL }}/ready")
else
response=$(curl -s -o /dev/null -w "%{http_code}" \
"${{ secrets.GRAFANA_LOKI_URL }}/ready")
fi
if [ "$response" = "200" ]; then
echo "✅ Loki is ready at ${{ secrets.GRAFANA_LOKI_URL }}"
else
echo "⚠️ Loki connection check returned HTTP $response"
echo "Tests will continue but logs may not be sent to Loki"
fi
- name: Send Pre-flight Event to Loki
- name: Test Grafana Cloud Loki Connection
if: ${{ secrets.GRAFANA_LOKI_URL != '' }}
continue-on-error: true
run: |
echo "🔍 Testing Grafana Cloud Loki connection..."
timestamp=$(date +%s)000000000
auth_header=""
if [ -n "${{ secrets.GRAFANA_LOKI_USERNAME }}" ]; then
auth_header="-u ${{ secrets.GRAFANA_LOKI_USERNAME }}:${{ secrets.GRAFANA_LOKI_PASSWORD }}"
fi
curl -X POST "${{ secrets.GRAFANA_LOKI_URL }}/loki/api/v1/push" \
$auth_header \
response=$(curl -s -w "\n%{http_code}" \
--max-time 10 \
-u "${{ secrets.GRAFANA_LOKI_USERNAME }}:${{ secrets.GRAFANA_LOKI_PASSWORD }}" \
-H "Content-Type: application/json" \
-H "User-Agent: ThrillWiki-Playwright-Tests/1.0" \
-X POST "${{ secrets.GRAFANA_LOKI_URL }}/loki/api/v1/push" \
-d "{
\"streams\": [{
\"stream\": {
\"job\": \"playwright-preflight\",
\"job\": \"playwright_preflight\",
\"workflow\": \"${{ github.workflow }}\",
\"branch\": \"${{ github.ref_name }}\",
\"commit\": \"${{ github.sha }}\",
\"run_id\": \"${{ github.run_id }}\",
\"event\": \"preflight_complete\"
\"run_id\": \"${{ github.run_id }}\"
},
\"values\": [[\"$timestamp\", \"Pre-flight checks completed successfully\"]]
\"values\": [[\"$timestamp\", \"Preflight check complete\"]]
}]
}" || echo "⚠️ Failed to send pre-flight event to Loki"
}")
http_code=$(echo "$response" | tail -n1)
if [ "$http_code" = "204" ] || [ "$http_code" = "200" ]; then
echo "✅ Successfully connected to Grafana Cloud Loki"
else
echo "⚠️ Loki connection returned HTTP $http_code"
echo "Response: $(echo "$response" | head -n -1)"
echo "Tests will continue but logs may not be sent to Loki"
fi
test:
needs: preflight
@@ -101,20 +91,22 @@ jobs:
- name: Send Test Start Event to Loki
if: ${{ secrets.GRAFANA_LOKI_URL != '' }}
continue-on-error: true
run: |
timestamp=$(date +%s)000000000
auth_header=""
if [ -n "${{ secrets.GRAFANA_LOKI_USERNAME }}" ]; then
auth_header="-u ${{ secrets.GRAFANA_LOKI_USERNAME }}:${{ secrets.GRAFANA_LOKI_PASSWORD }}"
fi
curl -X POST "${{ secrets.GRAFANA_LOKI_URL }}/loki/api/v1/push" \
$auth_header \
response=$(curl -s -w "\n%{http_code}" \
--max-time 10 \
--retry 3 \
--retry-delay 2 \
-u "${{ secrets.GRAFANA_LOKI_USERNAME }}:${{ secrets.GRAFANA_LOKI_PASSWORD }}" \
-H "Content-Type: application/json" \
-H "User-Agent: ThrillWiki-Playwright-Tests/1.0" \
-X POST "${{ secrets.GRAFANA_LOKI_URL }}/loki/api/v1/push" \
-d "{
\"streams\": [{
\"stream\": {
\"job\": \"playwright-tests\",
\"job\": \"playwright_tests\",
\"browser\": \"${{ matrix.browser }}\",
\"workflow\": \"${{ github.workflow }}\",
\"branch\": \"${{ github.ref_name }}\",
@@ -124,7 +116,12 @@ jobs:
},
\"values\": [[\"$timestamp\", \"Starting Playwright tests for ${{ matrix.browser }}\"]]
}]
}" || echo "⚠️ Failed to send start event to Loki"
}")
http_code=$(echo "$response" | tail -n1)
if [ "$http_code" != "204" ] && [ "$http_code" != "200" ]; then
echo "⚠️ Failed to send to Loki (HTTP $http_code): $(echo "$response" | head -n -1)"
fi
- name: Run Playwright tests
id: playwright-run
@@ -172,21 +169,23 @@ jobs:
- name: Send Test Results to Loki
if: always() && secrets.GRAFANA_LOKI_URL != ''
continue-on-error: true
run: |
timestamp=$(date +%s)000000000
STATUS="${{ steps.playwright-run.outputs.test_exit_code == '0' && 'success' || 'failure' }}"
auth_header=""
if [ -n "${{ secrets.GRAFANA_LOKI_USERNAME }}" ]; then
auth_header="-u ${{ secrets.GRAFANA_LOKI_USERNAME }}:${{ secrets.GRAFANA_LOKI_PASSWORD }}"
fi
timestamp=$(date +%s)000000000
curl -X POST "${{ secrets.GRAFANA_LOKI_URL }}/loki/api/v1/push" \
$auth_header \
response=$(curl -s -w "\n%{http_code}" \
--max-time 10 \
--retry 3 \
--retry-delay 2 \
-u "${{ secrets.GRAFANA_LOKI_USERNAME }}:${{ secrets.GRAFANA_LOKI_PASSWORD }}" \
-H "Content-Type: application/json" \
-H "User-Agent: ThrillWiki-Playwright-Tests/1.0" \
-X POST "${{ secrets.GRAFANA_LOKI_URL }}/loki/api/v1/push" \
-d "{
\"streams\": [{
\"stream\": {
\"job\": \"playwright-tests\",
\"job\": \"playwright_tests\",
\"browser\": \"${{ matrix.browser }}\",
\"workflow\": \"${{ github.workflow }}\",
\"branch\": \"${{ github.ref_name }}\",
@@ -197,7 +196,12 @@ jobs:
},
\"values\": [[\"$timestamp\", \"{\\\"total\\\": ${{ steps.parse-results.outputs.total || 0 }}, \\\"passed\\\": ${{ steps.parse-results.outputs.passed || 0 }}, \\\"failed\\\": ${{ steps.parse-results.outputs.failed || 0 }}, \\\"skipped\\\": ${{ steps.parse-results.outputs.skipped || 0 }}, \\\"duration_ms\\\": ${{ steps.parse-results.outputs.duration || 0 }}}\"]]
}]
}" || echo "⚠️ Failed to send results to Loki"
}")
http_code=$(echo "$response" | tail -n1)
if [ "$http_code" != "204" ] && [ "$http_code" != "200" ]; then
echo "⚠️ Failed to send results to Loki (HTTP $http_code): $(echo "$response" | head -n -1)"
fi
- name: Upload test results
uses: actions/upload-artifact@v4