Skip to main content

Diagnostics & Troubleshooting

Debug endpoints, health checks, and troubleshooting procedures.


Table of Contents


Health Checks

ClickHouse Connection Test

Test ClickHouse connectivity and query a sample table.

curl https://your-worker.workers.dev/test/clickhouse

Success Response:

{
"status": "ok",
"clickhouse_connected": true,
"sample_query_result": [...]
}

Failure Response:

{
"status": "error",
"error": "Connection timeout",
"clickhouse_connected": false
}

Initialize ClickHouse Schema

Create ClickHouse tables on first deployment.

curl https://your-worker.workers.dev/init/clickhouse

Response:

{
"status": "initialized",
"tables_created": [
"keyword_snapshots",
"serp_runs",
"app_analytics"
]
}

Auto-initialization:

If CLICKHOUSE_AUTO_INIT=true in environment, schema initializes automatically on first request.


Debug Endpoints

Debug Room Data

Debug Apple room/grouping data structure.

curl "https://your-worker.workers.dev/api/app-store/room/debug?room_id=apple_games"

Response:

{
"room_id": "apple_games",
"categories": [...],
"hierarchy": {...},
"raw_data": {...}
}

Debug Catalog

Debug complete catalog structure.

curl https://your-worker.workers.dev/api/app-store/catalog/debug

Response:

{
"total_categories": 142,
"by_platform": {
"apple": 78,
"google_play": 64
},
"hierarchy_depth": 4,
"orphaned_categories": []
}

Queue Status

Get queue metrics and health.

curl https://your-worker.workers.dev/api/admin/queue-status

Response:

{
"queues": {
"rankfabric-tasks": {
"pending": 15,
"in_progress": 3,
"completed_today": 1247
},
"clickhouse-ingestion": {
"pending": 5,
"in_progress": 1
}
}
}

Webhook Troubleshooting

Test Webhook Authentication

The worker sends webhooks to Base44/React when category syncs complete.

Webhook Headers:

X-Webhook-Secret: <NEXUS_WEBHOOK_SECRET>
Content-Type: application/json

Payload Example:

{
"event": "categories_synced",
"platform": "apple",
"device": "iphone",
"categories_count": 78,
"timestamp": "2025-11-17T10:00:00Z"
}

Common Webhook Issues

401 Unauthorized

Cause: Secret mismatch between worker and receiver.

Fix:

# Verify worker secret is set
wrangler secret list | grep NEXUS_WEBHOOK_SECRET

# Set matching secret on both sides
echo "your-secret-here" | wrangler secret put NEXUS_WEBHOOK_SECRET

# Set same secret in React app environment
NEXUS_WEBHOOK_SECRET=your-secret-here

404 Not Found

Cause: Webhook URL incorrect or endpoint doesn't exist.

Fix:

# Verify webhook URL is set
wrangler secret list | grep BASE44_WEBHOOK_URL

# Set correct URL
echo "https://base44.app/api/functions/webhookCategories" | \
wrangler secret put BASE44_WEBHOOK_URL

Connection Timeout

Cause: Receiver is down or not accessible.

Fix:

  1. Check receiver app is running
  2. Verify URL is publicly accessible
  3. Check firewall/network rules
  4. Test with curl:
curl -X POST https://your-webhook-url \
-H "X-Webhook-Secret: your-secret" \
-H "Content-Type: application/json" \
-d '{"test": true}'

Manual Webhook Test

Test webhook delivery manually:

# Set your secret
WEBHOOK_SECRET="your-secret-here"

# Test webhook call
curl -X POST https://your-webhook-url/api/functions/webhookCategories \
-H "X-Webhook-Secret: $WEBHOOK_SECRET" \
-H "Content-Type: application/json" \
-d '{
"event": "test",
"platform": "apple",
"device": "iphone",
"categories_count": 1
}'

Expected: 200 OK with {"success": true}

Webhook Setup Checklist

  • Generate secret: openssl rand -hex 32
  • Set secret in worker: wrangler secret put NEXUS_WEBHOOK_SECRET
  • Set webhook URL: wrangler secret put BASE44_WEBHOOK_URL
  • Set same secret in React app environment
  • Deploy worker: wrangler deploy
  • Test webhook with curl
  • Trigger actual webhook (rebuild catalog)
  • Check logs on both sides

Queue Diagnostics

View Queue Logs

Tail worker logs in real-time:

wrangler tail --format pretty

Filter for specific queue jobs:

wrangler tail --format pretty | grep "harvest_keywords"

Dead Letter Queue

Check dead letter queue for failed jobs:

# View DLQ messages (Cloudflare dashboard)
# Navigate to: Queues → rankfabric-dlq → Messages

Retry Failed Jobs

Manually requeue failed jobs:

# Get failed job from DLQ
# Resubmit to main queue via admin endpoint (to be implemented)

Clear Queue

⚠️ Destructive operation

# Stop all queue consumers
wrangler queues consumer stop rankfabric-tasks

# Clear messages (via Cloudflare dashboard)

# Restart consumers
wrangler queues consumer start rankfabric-tasks

Common Issues

ClickHouse Connection Errors

Symptom: Failed to connect to ClickHouse

Solutions:

  1. Check credentials:
wrangler secret list | grep CLICKHOUSE
  1. Verify secrets are set:
echo "your-host" | wrangler secret put CLICKHOUSE_HOST
echo "your-user" | wrangler secret put CLICKHOUSE_USER
echo "your-password" | wrangler secret put CLICKHOUSE_PASSWORD
echo "your-database" | wrangler secret put CLICKHOUSE_DATABASE
  1. Test connection:
curl https://your-worker.workers.dev/test/clickhouse
  1. Reinitialize schema:
curl https://your-worker.workers.dev/init/clickhouse

Base44 Authentication Failures

Symptom: 401 Unauthorized from Base44 API

Solutions:

  1. Verify Base44 secrets:
wrangler secret list | grep BASE44
  1. Check JWT secret:
echo "your-jwt-secret" | wrangler secret put BASE44_JWT_SECRET
  1. Test Base44 connection:
curl https://your-worker.workers.dev/diagnostics/keyword?keyword=test

Queue Stuck

Symptom: Jobs stay in pending status indefinitely

Solutions:

  1. Check queue dashboard:

    • Cloudflare Dashboard → Queues → rankfabric-tasks
    • Look for error rate spike
  2. Check worker logs:

wrangler tail --format pretty | grep ERROR
  1. View dead letter queue:

    • Check if jobs moved to DLQ
    • Investigate error messages
  2. Restart queue consumer:

# Redeploy worker to restart consumers
wrangler deploy

DataForSEO Quota Exceeded

Symptom: 429 Too Many Requests from DataForSEO

Solutions:

  1. Check daily budget:
# Budget is tracked in KV: budget:daily
wrangler kv:key get --namespace-id=<your-namespace> "budget:daily"
  1. Increase budget limit:
// In wrangler.toml
[vars]
DATAFORSEO_DAILY_BUDGET = "100"
  1. Wait for reset:

    • Budget resets at midnight UTC
    • Or wait for account quota reset
  2. Check account balance:

    • Log into DataForSEO dashboard
    • Verify account credits

App Details Not Found

Symptom: 404 Not Found for app details endpoint

Solutions:

  1. Verify app exists in database:
-- Via wrangler d1 execute
SELECT * FROM apps WHERE id = 'com.example.app';
  1. Check platform parameter:
# Correct
curl "...?platform=google_play"

# Wrong
curl "...?platform=android"
  1. Trigger fresh crawl:
curl -X POST .../api/app-store/crawl/full \
-d '{"platform":"google_play","categories":["..."]}'

Logging & Monitoring

Enable Debug Logging

Set log level in environment:

# wrangler.toml
[vars]
LOG_LEVEL = "debug"

Structured Logging

All logs include structured fields:

{
"timestamp": "2025-11-17T10:00:00Z",
"level": "info",
"message": "Crawl started",
"project_id": "proj_123",
"platform": "google_play"
}

Key Log Patterns

Successful crawl:

[crawl] Starting project: proj_google_play_...
[crawl] Queued 10 categories
[crawl] Completed 10/10 categories
[crawl] Project complete: 150 apps discovered

Failed job:

[queue] Processing job: harvest_keywords
[queue] ERROR: Failed to fetch keywords
[queue] Retrying job (attempt 2/3)

Webhook delivery:

[webhook] Sending to: https://base44.app/...
[webhook] Response: 200 OK

Monitoring Dashboards

Cloudflare Dashboard:

  • Workers → Analytics → Requests, Errors, CPU time
  • Queues → Metrics → Queue depth, Processing time
  • D1 → Metrics → Reads, Writes, Storage

Custom Metrics (ClickHouse):

Query app crawl health:

SELECT 
platform,
COUNT(*) as total_apps,
MAX(updated_at) as last_update
FROM apps
GROUP BY platform;

Query SERP tracking activity:

SELECT 
toDate(tracked_at) as date,
COUNT(*) as serp_runs
FROM serp_runs
WHERE tracked_at > now() - INTERVAL 7 DAY
GROUP BY date
ORDER BY date DESC;

Debugging Checklist

When something goes wrong:

  1. Check worker logs:

    wrangler tail --format pretty
  2. Verify secrets are set:

    wrangler secret list
  3. Test external connections:

    • ClickHouse: GET /test/clickhouse
    • Base44: GET /diagnostics/keyword?keyword=test
  4. Check queue status:

    curl .../api/admin/queue-status
  5. Review recent deployments:

    wrangler deployments list
  6. Check for rate limits:

    • DataForSEO quota
    • Worker CPU time limits
    • D1 read/write limits
  7. Verify data integrity:

    wrangler d1 execute rankfabric_db --command "SELECT COUNT(*) FROM apps"

Getting Help

For operational issues:

  1. Check this diagnostics guide
  2. Review Runbook
  3. Check worker logs
  4. Search GitHub issues

For integration questions:

For API questions: