Skip to content

Commit

Permalink
fix: Return number of runs in a given project for GetProjects (determ…
Browse files Browse the repository at this point in the history
  • Loading branch information
AmanuelAaron authored Jun 27, 2024
1 parent a5d5616 commit 038bfee
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 60 deletions.
4 changes: 4 additions & 0 deletions harness/determined/common/api/bindings.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion harness/tests/fixtures/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"workspaceName":"",
"state":"WORKSPACE_STATE_UNSPECIFIED",
"errorMessage":"",
"key":"cap1"
"key":"cap1",
"numRuns":0
}
}
4 changes: 4 additions & 0 deletions master/internal/project/postgres_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ func getProjectByIDTx(ctx context.Context, tx bun.Tx, projectID int) (*model.Pro
"(SELECT COUNT(*) FROM experiments WHERE project_id = ?) AS num_experiments",
projectID,
).
ColumnExpr(
"(SELECT COUNT(*) FROM runs WHERE project_id = ?) AS num_runs",
projectID,
).
ColumnExpr(
"(SELECT COUNT(*) FROM experiments WHERE project_id = ? AND state = 'ACTIVE') AS num_active_experiments",
projectID,
Expand Down
2 changes: 2 additions & 0 deletions master/pkg/model/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type Project struct {
Notes []*projectv1.Note `bun:"notes,type:jsonb,nullzero"`
NumActiveExperiments int32 `bun:"num_active_experiments,scanonly"`
NumExperiments int32 `bun:"num_experiments,scanonly"`
NumRuns int32 `bun:"num_runs,scanonly"`
State WorkspaceState `bun:"state,default:'UNSPECIFIED'::workspace_state"`
ErrorMessage string `bun:"error_message"`
LastExperimentStartedAt time.Time `bun:"last_experiment_started_at,scanonly"`
Expand Down Expand Up @@ -53,6 +54,7 @@ func (p Project) Proto() *projectv1.Project {
Description: p.Description,
ErrorMessage: p.ErrorMessage,
NumExperiments: p.NumExperiments,
NumRuns: p.NumRuns,
NumActiveExperiments: p.NumActiveExperiments,
Notes: p.Notes,
LastExperimentStartedAt: lastExperimentStartedAt,
Expand Down
10 changes: 8 additions & 2 deletions master/static/srv/get_project.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ WITH pe AS (
MAX(start_time) AS last_experiment_started_at
FROM experiments
WHERE project_id = $1
), pr AS (
SELECT
COUNT(*) AS num_runs
FROM runs
WHERE project_id = $1
)

SELECT
Expand All @@ -23,8 +28,9 @@ SELECT
COALESCE(MAX(pe.last_experiment_started_at), NULL) AS last_experiment_started_at,
u.username,
p.user_id,
p.key
FROM pe, projects AS p
p.key,
MAX(pr.num_runs) AS num_runs
FROM pe, pr, projects AS p
LEFT JOIN users AS u ON u.id = p.user_id
LEFT JOIN workspaces AS w ON w.id = p.workspace_id
WHERE p.id = $1
Expand Down
1 change: 1 addition & 0 deletions master/static/srv/get_workspace_projects.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ SELECT
p.error_message,
(w.archived OR p.archived) AS archived,
SUM(CASE WHEN pe.project_id = p.id THEN 1 ELSE 0 END) AS num_experiments,
(SELECT COUNT(*) FROM runs r WHERE p.id = r.project_id) AS num_runs,
SUM(
CASE WHEN pe.project_id = p.id
AND pe.state = 'ACTIVE' THEN 1 ELSE 0 END
Expand Down
126 changes: 69 additions & 57 deletions proto/pkg/projectv1/project.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions proto/src/determined/project/v1/project.proto
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ message Project {
"notes",
"num_active_experiments",
"num_experiments",
"num_runs",
"state",
"user_id",
"username",
Expand Down Expand Up @@ -122,6 +123,8 @@ message Project {
string error_message = 15;
// The key of the project.
string key = 16;
// Count of runs associated with this project.
int32 num_runs = 17;
}

// PatchProject is a partial update to a project with all optional fields.
Expand Down
6 changes: 6 additions & 0 deletions webui/react/src/services/api-ts-sdk/api.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 038bfee

Please sign in to comment.