Audit Log CLI for Enhanced Operational Visibility
- Dominant language
- Python
- Stars
- 670
- Forks
- 183
- Avg merge
- 17h 7m
- Merged PRs (30d)
- 358
Description
## Summary
Implement a command-line interface for querying and viewing AuditLog data to improve operational visibility and debugging capabilities.
## Background
Currently, AuditLog data is only accessible via GraphQL queries through `AuditLogNode`. There is no CLI support for administrators to quickly inspect audit logs from the terminal, making it difficult to diagnose issues and track operation history in production environments.
## Goals
1. **CLI for AuditLog Queries**: Enable terminal-based querying of `AuditLogNode` with filtering, sorting, and pagination support
1. **Request ID Lookup**: Allow quick lookup of audit logs by request ID for debugging specific operations
1. **Time-based Filtering**: Support date range queries for analyzing operations within specific periods
## Scope
### AuditLog CLI Commands
- Add `./backend.ai mgr audit-log` CLI command group
- Implement subcommands:
- `list`: List audit logs with filters (entity_type, operation, status, date range, triggered_by)
- `get `: Get detailed information for a specific audit log entry by request ID
- `stats`: Show aggregated statistics (counts by entity_type, operation, status)
- Support filtering options:
- `--request-id`: Filter by specific request ID
- `--from-date / --to-date`: Filter by date range
- `--entity-type`: Filter by entity type
- `--operation`: Filter by operation type
- `--status`: Filter by status
- Support output formats: table, JSON, CSV
## Technical Considerations
- CLI should use the existing Click-based CLI framework in `src/ai/backend/manager/cli/`
- Consider pagination for large result sets
- Ensure consistent output formatting with other Backend.AI CLI commands
## Acceptance Criteria
- [ ] Administrators can query audit logs from terminal without direct database access
- [ ] Administrators can look up specific audit logs by request ID
- [ ] Administrators can filter audit logs by date range (from/to)
- [ ] CLI provides intuitive filtering and output format options
- [ ] Output is consistent with existing Backend.AI CLI conventions
## Related Components
- `src/ai/backend/manager/models/audit_log.py`
- `src/ai/backend/manager/models/gql_models/audit_log.py`
- `src/ai/backend/manager/actions/monitors/audit_log.py`
- `src/ai/backend/manager/cli/`
JIRA Issue: BA-3641
Contributor guide
Assessment
This issue has not been assessed yet.