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

@@ -235,3 +235,82 @@ For questions or issues with tests, check:
2. Playwright docs
3. Test failure screenshots/videos in `test-results/`
4. GitHub Actions logs for CI failures
5. Grafana Cloud Loki for centralized test logs
## Grafana Cloud Loki Integration
All test runs automatically send logs to Grafana Cloud Loki for centralized monitoring and analysis.
### Viewing Logs in Grafana Cloud
1. **Access Grafana Cloud**: Go to your Grafana Cloud instance
2. **Navigate to Explore**: Click "Explore" in the left sidebar
3. **Select Loki Data Source**: Choose your Loki data source from the dropdown
4. **Query Test Logs**: Use LogQL queries to filter logs
### Common LogQL Queries
```logql
# All Playwright test logs
{job="playwright_tests"}
# Logs for specific browser
{job="playwright_tests", browser="chromium"}
# Failed tests only
{job="playwright_tests", status="failed"}
# Tests from specific branch
{job="playwright_tests", branch="main"}
# Tests from specific GitHub run
{job="playwright_tests", run_id="1234567890"}
# Logs from specific test file
{job="playwright_tests"} |= "login.spec.ts"
# Failed tests with error messages
{job="playwright_tests", status="failed"} | json | line_format "{{.test_name}}: {{.error}}"
```
### Local Testing with Grafana Cloud
Test your Grafana Cloud integration locally:
```bash
# Set environment variables
export GRAFANA_LOKI_URL="https://logs-prod-us-central1.grafana.net"
export GRAFANA_LOKI_USERNAME="123456" # Your instance ID
export GRAFANA_LOKI_PASSWORD="glc_xxxxxxxxxxxxx" # Your API key
# Run test script
chmod +x scripts/test-grafana-cloud.sh
./scripts/test-grafana-cloud.sh
# Run tests with Loki reporter
npx playwright test tests/e2e/auth/login.spec.ts --project=chromium
```
### Required GitHub Secrets
For CI/CD integration, ensure these secrets are configured in your GitHub repository:
- `GRAFANA_LOKI_URL` - Your Grafana Cloud Loki endpoint (e.g., `https://logs-prod-us-central1.grafana.net`)
- `GRAFANA_LOKI_USERNAME` - Your Grafana Cloud instance ID
- `GRAFANA_LOKI_PASSWORD` - Your Grafana Cloud API key (starts with `glc_`)
### Troubleshooting Grafana Cloud Connection
**401 Unauthorized Error:**
- Check your `GRAFANA_LOKI_USERNAME` (should be your instance ID)
- Verify your `GRAFANA_LOKI_PASSWORD` (API key starting with `glc_`)
- Regenerate API key if needed (Security > API Keys in Grafana Cloud)
**Logs Not Appearing:**
- Verify the correct region in `GRAFANA_LOKI_URL`
- Check time range in Grafana Explore (default is last 5 minutes)
- Run test script to validate connection: `./scripts/test-grafana-cloud.sh`
**429 Rate Limit Error:**
- Reduce test concurrency in `playwright.config.ts`
- Increase `flushInterval` in Loki reporter options