lablup / lablup/backend.ai

Implement unified resource-query service and repository (DB allocation + Prometheus utilization)

Open
#12,123 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
670
Forks
183
Avg merge
15h 13m
Merged PRs (30d)
368

Description

Foundation layer for the new resource query API that replaces the legacy resource usage/stats endpoints. The legacy endpoints compute utilization from the now-dead kernel.last_stat column (with a Valkey fallback), so they are effectively non-functional. Build a clean service + repository that sources allocation from the DB and utilization from Prometheus.

Scope:
- Repository (repositories/resource_query/): query kernel resource allocation (occupied_slots-derived cpu/mem/gpu/shared_memory/disk + metadata: session, project, domain, agent, image, status, created/terminated) by domain/project/session/kernel over a time range. Port the existing kernel selection condition (terminated-in-period kernels in RESOURCE_USAGE_KERNEL_STATUSES OR running sessions created before end_date) from models/resource_usage.py / repositories/group db_source.
- Utilization from Prometheus: reuse the existing services/metric stack (MetricService/MetricRepository query_container_metric / query_container_live_stats) instead of kernel.last_stat or ValkeyStatClient.
- Service (services/resource_query/): aggregate kernels into a domain>project>session>kernel hierarchy with per-level totals (allocation + utilization). Define data/ types + Action/ActionResult + Processor.
- Define the unified domain data model here (data/resource_query/) consumed by the endpoint layer (separate issue).

Replaces the inconsistent legacy computations in models/resource_usage.py (parse_resource_usage\*), repositories/group/db_source and repositories/user/db_source.

## Success Criteria
- [ ] Repository returns per-kernel allocation for a given project + time range, grouped to session/project/domain
- [ ] Utilization values are sourced from the Prometheus metric service, NOT kernel.last_stat or ValkeyStatClient
- [ ] Kernel selection covers terminated-in-period kernels and still-running sessions (parity with legacy period condition)
- [ ] Service returns a domain>project>session>kernel hierarchy with correct per-level totals
- [ ] pants test passes for affected manager packages

JIRA Issue: BA-6447

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.