feat: add Valkey caching layer with New Relic monitoring and structur…#3
Merged
feat: add Valkey caching layer with New Relic monitoring and structur…#3
Conversation
…ed logging - Add Valkey/Redis cluster caching with automatic failover - Implement cache utilities: getCache, setCache, deleteCache, deleteCachePattern - Fix cluster SCAN to query all master nodes, not just one - Add batch deletion (100 keys) to prevent overwhelming cluster - Centralized cache keys and TTL configuration - Implement standardized logging with New Relic APM integration - Create Logger class with structured JSON logging - Add specialized methods: httpRequest, cacheOperation, businessEvent, securityEvent - Automatic metrics recording (response time, cache hit/miss, status codes) - Replace all console.log/error with logger for consistency - Configure rate limiting via environment variables - HTTP API: HTTP_RATE_LIMIT_WINDOW_MS, HTTP_RATE_LIMIT_MAX_REQUESTS - File uploads: HTTP_FILE_RATE_LIMIT_MAX - Code execution: CODE_EXEC_RATE_LIMIT_MAX, CODE_EXEC_RATE_WINDOW_MS - WebSocket: existing WS_* variables - Log rate limit configuration on startup - Improve security and configuration - Remove default CORS origins (requires explicit configuration) - Add warning when CORS_ORIGINS not set - Set New Relic log level: warn (dev), info (production) - Add graceful shutdown with cache cleanup - Add ESLint + Prettier integration - Install @eslint/js, eslint-config-prettier, eslint-plugin-prettier - Create .prettierrc and .prettierignore - Format all code consistently (double quotes, semicolons, 100 char width) - Fix TypeScript strict mode compliance - Add nullish coalescing operators for optional properties - Proper error type handling throughout - Type-safe LogMetadata for New Relic API compatibility
|
🎉 This PR is included in version 1.6.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds comprehensive caching with Valkey/Redis cluster, New Relic APM integration, standardized structured logging,
and configurable rate limiting across all endpoints.
Key Changes
🚀 Valkey/Redis Cluster Caching
src/lib/cache.ts,src/lib/cache-keys.ts)Performance: Folder queries reduced from ~150ms → <5ms (30x faster)
📊 New Relic APM Integration
src/lib/logger.ts)console.log/errorwith structured loggerMetrics:
Custom/HTTP/ResponseTime,Custom/HTTP/Status/*,Custom/Cache/{Hit,Miss}🛡️ Configurable Rate Limiting
Made all rate limits configurable via environment variables:
HTTP_RATE_LIMIT_WINDOW_MS(15min),HTTP_RATE_LIMIT_MAX_REQUESTS(1000)HTTP_FILE_RATE_LIMIT_MAX(100)CODE_EXEC_RATE_LIMIT_MAX(50 prod / 100 dev)All configurations logged on startup for visibility.
🔒 Security & Quality
CORS_ORIGINSconfigurationwarnlevel in dev,infoin productionNew Environment Variables
Caching (optional)
VALKEY_HOST=your-cluster.serverless.use1.cache.amazonaws.com
VALKEY_PORT=6379
Monitoring (optional)
NEW_RELIC_LICENSE_KEY=your_license_key
NEW_RELIC_LOG_LEVEL=warn # error, warn, info, debug, trace
HTTP Rate Limiting (optional - has defaults)
HTTP_RATE_LIMIT_WINDOW_MS=900000
HTTP_RATE_LIMIT_MAX_REQUESTS=1000
HTTP_FILE_RATE_LIMIT_MAX=100
Code Execution Rate Limiting (optional - has defaults)
CODE_EXEC_RATE_LIMIT_MAX=50