404Dev: GraphQL API, Prometheus & New Threading
โจ NEW FEATURES
๐ฏ GraphQL API
- Full GraphQL support using Strawberry GraphQL
- Endpoint:
POST /api/v2/graphql - Queries:
userTime,clockStatus,leaderboard,insights,systemHealth - Mutations:
clockIn,clockOut - Interactive playground at
/api/v2/graphql
๐ Prometheus Metrics & Monitoring
- 50+ metrics for comprehensive observability
- Metrics endpoint:
GET /metrics(Prometheus text format) - Categories tracked:
- API requests (count, duration, size, in-flight)
- Authentication (attempts, rate limits, active keys)
- Database (Redis/PostgreSQL operations, connection pools)
- Cache (hit/miss rates, sizes, evictions per layer)
- Threading (workers, queue size, lock contention)
- Business (active sessions, clock ops, WebSocket connections)
- Batch processing (operations, sizes, durations)
๐ฅ Enhanced Health Checks
- Basic health:
GET /health- Simple up/down status - Detailed health:
GET /health/detailed- Full system diagnostics - Thread pool status (active workers, queue size)
- Redis connection status
- PostgreSQL pool usage and database size
- Active sessions count
- Cache sizes (L1, L2, L3)
- Circuit breaker metrics
๐ Thread-Safe Atomic Operations
- New module:
Utils/atomic_operations.py - Decorators:
@atomic_redis,@atomic_db,@atomic_cache - Batch processor:
AtomicBatchProcessorfor efficient bulk operations - Context managers:
AtomicRedisContext,AtomicDBContext - Metrics integration: Automatic lock wait time tracking
- Thread-safe singleton: Base class for shared resources
๐งต Threading Model
- API in separate thread with its own asyncio event loop
- Thread pool: 4 workers for batch processing
- No bot interference: API operations don't block Discord bot
- Better CPU utilization: Multi-core usage
- Daemon thread: Automatic cleanup on bot shutdown
๐จ Enhanced API Documentation
- Swagger UI improvements:
- Search/filter enabled
- Request duration display
- Deep linking (shareable URLs)
- Monokai dark theme
- Persistent authorization
- Auto-collapsed models
- GraphQL Playground: Interactive GraphQL IDE
- ReDoc: Alternative documentation view