Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions frontend/src/pages/Runs/Details/Jobs/Metrics/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export const JobMetrics: React.FC = () => {
const { cpuChartProps, memoryChartProps, eachGPUChartProps, eachGPUMemoryChartProps, isLoading } = useMetricsData({
project_name: paramProjectName,
run_name: runData?.run_spec.run_name ?? '',
run_id: runData?.id ?? '',
job_num: jobData?.job_spec.job_num ?? 0,
limit: 1000,
});
Expand Down
1 change: 1 addition & 0 deletions frontend/src/types/run.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ declare type TStopRunsRequestParams = {
declare type TJobMetricsRequestParams = {
project_name: IProject['project_name'];
run_name: string;
run_id: string;
replica_num?: number;
job_num: number;
limit?: number;
Expand Down
8 changes: 6 additions & 2 deletions src/dstack/_internal/server/routers/metrics.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from datetime import datetime
from typing import Optional, Tuple
from uuid import UUID

from fastapi import APIRouter, Depends
from sqlalchemy.ext.asyncio import AsyncSession
Expand Down Expand Up @@ -29,6 +30,7 @@
)
async def get_job_metrics(
run_name: str,
run_id: Optional[UUID] = None,
replica_num: int = 0,
job_num: int = 0,
limit: int = 1,
Expand All @@ -39,8 +41,9 @@ async def get_job_metrics(
):
"""
Returns job-level metrics such as hardware utilization
given `run_name`, `replica_num`, and `job_num`.
If only `run_name` is specified, returns metrics of `(replica_num=0, job_num=0)`.
given `run_name`, `run_id`, `replica_num`, and `job_num`.
If only `run_name` is specified, returns metrics of `(replica_num=0, job_num=0)`
of the latest run with the given name.
By default, returns one latest sample. To control time window/number of samples, use
`limit`, `after`, `before`.

Expand All @@ -61,6 +64,7 @@ async def get_job_metrics(
session=session,
project=project,
run_name=run_name,
run_id=run_id,
replica_num=replica_num,
job_num=job_num,
)
Expand Down
27 changes: 18 additions & 9 deletions src/dstack/_internal/server/services/jobs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,19 +97,28 @@ def find_job(jobs: List[Job], replica_num: int, job_num: int) -> Job:


async def get_run_job_model(
session: AsyncSession, project: ProjectModel, run_name: str, replica_num: int, job_num: int
session: AsyncSession,
project: ProjectModel,
run_name: str,
run_id: Optional[UUID],
replica_num: int,
job_num: int,
) -> Optional[JobModel]:
filters = [
RunModel.project_id == project.id,
RunModel.run_name == run_name,
JobModel.replica_num == replica_num,
JobModel.job_num == job_num,
]
if run_id is not None:
filters.append(RunModel.id == run_id)
else:
# Assuming run_name is unique for non-deleted runs
filters.append(RunModel.deleted == False)
res = await session.execute(
select(JobModel)
.join(JobModel.run)
.where(
RunModel.project_id == project.id,
# assuming run_name is unique for non-deleted runs
RunModel.run_name == run_name,
RunModel.deleted == False,
JobModel.replica_num == replica_num,
JobModel.job_num == job_num,
)
.where(*filters)
.order_by(JobModel.submission_num.desc())
.limit(1)
)
Expand Down