Skip to content

Debugging Guide

This guide provides systematic approaches to debug issues in the Local AI Cyber Lab environment.

Debugging Methodology

1. Information Gathering

System State

# Check system resources
htop
nvidia-smi
df -h

# Check Docker status
docker ps
docker stats

Logs Collection

# Collect service logs
docker-compose logs --tail=100 service-name

# Check system logs
journalctl -u docker
dmesg | grep -i error

2. Problem Isolation

Service Dependencies

  1. Map service dependencies:

    docker-compose config --services
    

  2. Check service health:

    curl http://localhost:port/health
    

  3. Verify network connectivity:

    docker network inspect bridge
    

Component Testing

  1. Test individual components:

    # Test AI Guardian
    curl -X POST http://localhost:8000/api/v1/validate \
      -H "Authorization: Bearer ${AI_GUARDIAN_API_KEY}" \
      -d '{"prompt": "test"}'
    
    # Test Database
    docker-compose exec supabase-db psql -U postgres -c "\l"
    

  2. Verify configurations:

    # Check environment variables
    docker-compose config
    
    # Validate config files
    yamllint docker-compose.yml
    

3. Debug Tools

Docker Debugging

  1. Container inspection:

    # Get container details
    docker inspect container_id
    
    # Execute commands in container
    docker exec -it container_id /bin/bash
    

  2. Resource monitoring:

    # Monitor container resources
    docker stats container_id
    
    # Check container logs
    docker logs -f container_id
    

Network Debugging

  1. Network connectivity:

    # Test inter-container networking
    docker-compose exec service1 ping service2
    
    # Check port bindings
    netstat -tulpn | grep LISTEN
    

  2. DNS resolution:

    # Test DNS
    docker-compose exec service nslookup other-service
    

4. Performance Debugging

CPU Profiling

  1. Process monitoring:

    top -H -p $(pgrep -d',' python)
    

  2. System load analysis:

    uptime
    sar -u 1 10
    

Memory Analysis

  1. Memory usage:

    free -h
    vmstat 1 10
    

  2. Container memory:

    docker stats --format "table {{.Name}}\t{{.MemUsage}}"
    

5. Security Debugging

Access Control

  1. Check permissions:

    ls -la /path/to/sensitive/files
    

  2. Audit authentication:

    # Review auth logs
    tail -f /var/log/auth.log
    
    # Check API key usage
    grep "Authentication failed" logs/ai-guardian.log
    

Network Security

  1. Port scanning:

    nmap -p- localhost
    

  2. TLS verification:

    openssl s_client -connect localhost:443
    

6. Debug Logging

Enable Debug Logs

  1. Update logging configuration:

    # In Python services
    import logging
    logging.basicConfig(level=logging.DEBUG)
    

  2. Docker logging:

    # Update daemon.json
    {
      "log-level": "debug"
    }
    

Log Analysis

  1. Parse logs:

    # Search for errors
    grep -r "ERROR" logs/
    
    # Track requests
    tail -f access.log | grep "POST /api"
    

  2. Log aggregation:

    # Combine service logs
    docker-compose logs --tail=1000 > debug.log
    

7. Recovery Steps

Service Recovery

  1. Restart services:

    docker-compose restart service-name
    

  2. Clean restart:

    docker-compose down
    docker system prune
    docker-compose up -d
    

Data Recovery

  1. Backup data:

    ./scripts/backup.sh
    

  2. Restore from backup:

    ./scripts/restore.sh backup_file
    

Best Practices

  1. Systematic Approach:
  2. Start with logs
  3. Isolate components
  4. Test incrementally
  5. Document findings

  6. Monitoring:

  7. Set up alerts
  8. Monitor resource usage
  9. Track error rates
  10. Log key metrics

  11. Prevention:

  12. Regular health checks
  13. Automated testing
  14. Configuration validation
  15. Security audits

Debug Checklist

  • [ ] Collect system information
  • [ ] Review recent changes
  • [ ] Check service status
  • [ ] Verify configurations
  • [ ] Test component isolation
  • [ ] Monitor resource usage
  • [ ] Review security logs
  • [ ] Document findings
  • [ ] Implement fixes
  • [ ] Verify solution
  • [ ] Update documentation

Additional Resources

  1. Docker Debug Documentation
  2. System Monitoring Tools
  3. Security Debugging Guide
  4. Performance Tuning