Deprecate and remove legacy resource usage/stats REST endpoints and dead last_stat-based code
- Dominant language
- Python
- Stars
- 670
- Forks
- 183
- Avg merge
- 15h 13m
- Merged PRs (30d)
- 368
Description
After the unified resource-query API lands, remove the four legacy endpoints and the dead last_stat/Valkey-based computation paths they rely on. These compute utilization from kernel.last_stat (no longer populated) so they are effectively non-functional; webui does not use them.
Legacy endpoints to remove (api/rest/resource/handler.py + registry.py):
- usage_per_period - GET /resource/usage/period
- usage_per_month - GET /resource/usage/month
- user_month_stats - GET /resource/stats/user/month
- admin_month_stats - GET /resource/stats/admin/month
Dead code to remove/clean:
- models/resource_usage.py: parse_resource_usage / parse_resource_usage_groups / parse_total_resource_group and last_stat extraction
- repositories/group/db_source.py: get_container_stats_for_period (last_stat + valkey fallback)
- repositories/user/db_source.py + repositories/user/repository.py: _get_time_binned_monthly_stats path
- RESOURCE_USAGE_KERNEL_STATUSES (models/kernel/row.py) - remove if no other consumers, otherwise keep with a note
- Associated Actions/Services/Processors that become unused
Control-panel save_raw_usage_csv.sh still calls /resource/usage/period; its migration is tracked separately (control-panel repo) and is a prerequisite for production removal.
Depends on the new unified resource-query API being available.
## Success Criteria
- [ ] The 4 legacy routes are removed from the resource REST registry and their handlers deleted
- [ ] Dead last_stat/Valkey-based resource computation code is removed
- [ ] No remaining references to the removed symbols in the repo (grep clean), imports cleaned up
- [ ] RESOURCE_USAGE_KERNEL_STATUSES removed if unused elsewhere (otherwise documented why kept)
- [ ] pants lint/check passes (no unused imports) and pants test passes for affected packages
JIRA Issue: BA-6449
Contributor guide
Research direction
Start with api/rest/resource/handler.py and registry.py, then trace the listed last_stat paths in models/resource_usage.py, repositories/group/db_source.py, and repositories/user/{db_source.py,repository.py}. Check the control-panel dependency and search for remaining symbol references before removing anything. Done means the four routes and unused computation code are gone, imports are clean, and pants lint/check plus affected-package tests pass.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- docker, python
- Domain
- api, backend, distributed-systems
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100