Skip to content

Conversation

@typelets
Copy link
Owner

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

  • Complete cache layer with cluster support (src/lib/cache.ts, src/lib/cache-keys.ts)
  • Cache folders list, folder tree, and note lists (10-15min TTLs)
  • Critical fix: SCAN now queries ALL master nodes (was only scanning one)
  • Batch deletion (100 keys) to prevent cluster overload
  • Graceful degradation when cache unavailable
  • Auto-invalidation on note/folder updates

Performance: Folder queries reduced from ~150ms → <5ms (30x faster)

📊 New Relic APM Integration

  • Standardized Logger class with automatic metrics (src/lib/logger.ts)
  • HTTP request tracking (method, path, status, duration, userId)
  • Cache hit/miss metrics with operation duration
  • Business events (note_limit_exceeded, storage_limit_exceeded)
  • Security events (failed_auth, suspicious_activity)
  • Automatic error tracking with stack traces
  • Replaced all console.log/error with structured logger

Metrics: Custom/HTTP/ResponseTime, Custom/HTTP/Status/*, Custom/Cache/{Hit,Miss}

🛡️ Configurable Rate Limiting

Made all rate limits configurable via environment variables:

  • HTTP API: HTTP_RATE_LIMIT_WINDOW_MS (15min), HTTP_RATE_LIMIT_MAX_REQUESTS (1000)
  • File uploads: HTTP_FILE_RATE_LIMIT_MAX (100)
  • Code execution: CODE_EXEC_RATE_LIMIT_MAX (50 prod / 100 dev)

All configurations logged on startup for visibility.

🔒 Security & Quality

  • CORS: Removed default origins - now requires explicit CORS_ORIGINS configuration
  • Graceful shutdown: Cache cleanup on SIGTERM/SIGINT
  • TypeScript: Fixed all strict mode issues, proper nullish coalescing
  • Code quality: ESLint + Prettier integration, 788 auto-fixes applied
  • New Relic logs: warn level in dev, info in production

New 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

…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
@typelets typelets self-assigned this Oct 15, 2025
@typelets typelets merged commit 794b5b2 into main Oct 15, 2025
4 checks passed
@github-actions
Copy link

🎉 This PR is included in version 1.6.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants