Implement usage tracking and quota enforcement
- Dominant language
- Python
- Stars
- 670
- Forks
- 183
- Avg merge
- 17h 7m
- Merged PRs (30d)
- 358
Description
## Motivation
With quota configuration in place, we need to calculate current usage and enforce limits during artifact import. This prevents storage exhaustion and enables capacity planning.
## Required Features
- Add usage aggregation query in `StorageNamespaceRepository`
- JOIN `association_artifacts_storages` with `artifact_revisions`
- Return: `total_size`, `artifact_count`, `revision_count`, `max_size`
- Create `StorageNamespaceQuotaService` with `check_quota()` method
- Compare current usage + additional size against max_size
- Raise `StorageNamespaceQuotaExceededError` if exceeded
- Integrate quota check into `ArtifactRevisionService.import_revision()`
- Check quota before starting import
- Use `revision_data.size` as estimated size
## Impact
- `src/ai/backend/manager/repositories/storage_namespace/repository.py`
- `src/ai/backend/manager/repositories/storage_namespace/db_source/db_source.py`
- `src/ai/backend/manager/services/storage_namespace/` (new quota service)
- `src/ai/backend/manager/services/artifact_revision/service.py`
- `src/ai/backend/manager/errors/storage.py`
## Testing Scenarios
- Usage query returns correct aggregated values
- Quota check passes when under limit
- Quota check passes when `max_size` is NULL (unlimited)
- Quota check raises error when limit would be exceeded
- Import flow rejects artifact when quota exceeded
- Import flow succeeds when quota has room
JIRA Issue: BA-3991
Contributor guide
Assessment
This issue has not been assessed yet.