Skip to content

Conversation

@nmgaston
Copy link
Contributor

Summary

Adds backend caching for AMT API endpoints to dramatically reduce latency and backend load for repeated requests within short time windows.

Problem

When users interact with the KVM interface or monitor device status, the frontend makes repeated API calls to fetch power state, features, and KVM display settings. Each call requires a round-trip to the AMT firmware, adding 150-500ms latency per request.

Solution

Implements a thread-safe in-memory cache with TTL-based expiration:

  • Power state: 5-second TTL (state changes frequently during power actions)
  • Features & KVM displays: 30-second TTL (settings rarely change)
  • Automatic invalidation: Cache cleared when power actions are performed

Performance Impact

Testing with realistic human interaction patterns (5-10 second intervals):

  • Response time improvement: 15-53x faster for cached requests
    • Without cache: ~1.15s per request
    • With cache @ 5s: 0.074s (15.3x faster)
    • With cache @ 10s: 0.021s (53.1x faster)
  • Backend load reduction: ~67% fewer AMT API calls
  • Cache efficiency: ~100% hit rate within TTL window

Implementation Details

  • Thread-safe with sync.RWMutex for concurrent access
  • Generic TTL-based expiration with background cleanup
  • Minimal code changes to existing endpoints
  • No breaking changes to API contracts

Testing

  • Verified cache hit/miss behavior with console logs
  • Load tested with baseline-test.sh script simulating real user interactions
  • Confirmed cache invalidation on power actions

- Add thread-safe cache implementation with TTL support
- Cache power state (5s TTL) with invalidation on power actions
- Cache features and KVM displays (30s TTL)
- Reduces backend API calls by ~67% for typical usage
- Improves response times by 15-53x for repeated requests
Add GET /api/v1/admin/kvm/init/{guid} endpoint that combines:
- Display settings (GetKVMScreenSettings)
- Power state (GetPowerState)
- Redirection status (hardcoded for now)
- AMT features (GetFeatures)

This reduces 4 separate API calls during KVM initialization to just 1,
significantly improving page load time and reducing network latency.

Changes:
- Add KVMInitResponse DTO that combines all required data
- Add GetKVMInitData usecase method with caching (30s TTL)
- Add cache key for KVM init data
- Register endpoint in both v1 and OpenAPI routers
- Add HTTP handler for the new endpoint
Add monitoring stack with:
- Prometheus for metrics collection from /metrics endpoint
- Grafana for visualization and dashboards
- Persistent volumes for both services
- Add GetKVMInitData method to ws/v1 Feature interface
- Add SetLinkPreference method to ws/v1 Feature interface
- Regenerate all mock files with updated interface signatures
- Update gomock import paths from github.com/golang/mock to go.uber.org/mock
- Generate prometheus.yml dynamically in GitHub Actions workflow
- Fixes CI error where prometheus.yml mount fails
- Keep prometheus.yml in .gitignore for local development
- Specify vault, postgres, app services explicitly in docker compose up
- Removes need for prometheus.yml in CI environment
- Keeps all prometheus-related config out of repository
- Remove prometheus and grafana services from docker-compose.yml
- Remove prometheus-data and grafana-data volumes
- Revert api-test.yml to original since services are removed
- Keeps monitoring configuration separate from main compose file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant