Overview
The KMS includes a comprehensive monitoring service that tracks:- Key generation events and success rates
- Encryption operations (client-side testing)
- Decryption operations and failures
- Performance metrics (operation duration)
- Error patterns and failure reasons
Metrics Collection
TheEncryptionMonitoringService automatically records metrics for all encryption operations:
Automatic Metric Recording
Metrics are automatically recorded in the encryption resolver:Metrics Summary Query
GraphQL Query
Retrieve a comprehensive metrics summary for a specific timeframe:Query Parameters
timeframeHours(optional): Number of hours to analyze (default: 24)
Response Format
The query returns a JSON string containing:Metrics Summary Implementation
Finding Problematic Keys
Identify keys with high failure rates that may need rotation:- At least 5 decryption operations have been attempted
- Failure rate exceeds the threshold (default: 10%)
Monitoring Workflow
Identify problematic keys
Use the monitoring service to find keys that need rotation (programmatically).
Metrics Database Schema
Example Monitoring Dashboard
Alerting Strategies
Failure Rate Alerts
Performance Degradation Alerts
Best Practices
Regular Monitoring
Query metrics at regular intervals (e.g., every 5 minutes) to detect issues early.
Failure Thresholds
Set appropriate thresholds for alerts (e.g., >5% warning, >10% critical).
Key Rotation
Automatically rotate keys with consistently high failure rates.
Trend Analysis
Compare metrics across different timeframes to identify trends.
Common Failure Reasons
| Error Reason | Description | Action |
|---|---|---|
Encryption key has expired | Key exceeded its 30-day lifetime | Rotate the key |
Encryption key not found | Key was deleted or never existed | Generate new key |
key_retrieval_failed | Database error retrieving key | Check database connectivity |
Failed to decrypt data | Corrupted data or wrong key | Verify keyId matches |
Encrypted data size exceeds limit | Payload too large | Reduce data size |
Performance Metrics
Normal Operation Ranges
- Key Generation: 30-100ms
- Encryption (client-side): 1-5ms
- Decryption (server-side): 5-20ms
- Database performance
- Server CPU usage
- Network latency
- Large payload sizes
Metrics Retention
Consider implementing a retention policy for metrics:Next Steps
Key Generation
Learn about key generation and rotation
Authentication
Implement secure authentication workflows