Skip to content

Commit

Permalink
chore: check config policies on 'det notebook set priority'
Browse files Browse the repository at this point in the history
  • Loading branch information
stoksc committed Oct 15, 2024
1 parent 2ef2f12 commit 72bc3cf
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 26 deletions.
24 changes: 24 additions & 0 deletions master/internal/experiment.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/determined-ai/determined/master/internal/api"
"github.com/determined-ai/determined/master/internal/checkpoints"
"github.com/determined-ai/determined/master/internal/config"
"github.com/determined-ai/determined/master/internal/configpolicy"
internaldb "github.com/determined-ai/determined/master/internal/db"
"github.com/determined-ai/determined/master/internal/experiment"
"github.com/determined-ai/determined/master/internal/job/jobservice"
Expand Down Expand Up @@ -1033,6 +1034,29 @@ func (e *internalExperiment) setPriority(priority *int, forward bool) (err error
if priority == nil {
return nil
}

workspaceModel, err := workspace.WorkspaceByProjectID(context.TODO(), e.ProjectID)
if err != nil && errors.Cause(err) != sql.ErrNoRows {
return err
}
wkspID := resolveWorkspaceID(workspaceModel)

// Returns an error if RM does not implement priority.
if smallerHigher, err := e.rm.SmallerValueIsHigherPriority(); err == nil {
ok, err := configpolicy.PriorityUpdateAllowed(
wkspID,
model.ExperimentType,
*priority,
smallerHigher,
)
if err != nil {
return err
}
if !ok {
return fmt.Errorf("priority exceeds task config policy's priority_limit")
}
}

oldPriority := config.DefaultSchedulingPriority
var oldPriorityPtr *int
resources := e.activeConfig.Resources()
Expand Down
27 changes: 1 addition & 26 deletions master/internal/experiment_job_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,14 @@ package internal

import (
"context"
"database/sql"
"fmt"
"strconv"

"github.com/pkg/errors"
"google.golang.org/protobuf/types/known/timestamppb"

"github.com/determined-ai/determined/master/internal/config"
"github.com/determined-ai/determined/master/internal/configpolicy"
"github.com/determined-ai/determined/master/internal/workspace"
"github.com/determined-ai/determined/master/pkg/model"
"github.com/determined-ai/determined/proto/pkg/jobv1"
)

Expand Down Expand Up @@ -57,29 +54,7 @@ func (e *internalExperiment) SetJobPriority(priority int) error {
return fmt.Errorf("priority must be between 1 and 99")
}

workspaceModel, err := workspace.WorkspaceByProjectID(context.TODO(), e.ProjectID)
if err != nil && errors.Cause(err) != sql.ErrNoRows {
return err
}
wkspID := resolveWorkspaceID(workspaceModel)

// Returns an error if RM does not implement priority.
if smallerHigher, err := e.rm.SmallerValueIsHigherPriority(); err == nil {
ok, err := configpolicy.PriorityUpdateAllowed(
wkspID,
model.ExperimentType,
priority,
smallerHigher,
)
if err != nil {
return err
}
if !ok {
return fmt.Errorf("priority exceeds task config policy's priority_limit")
}
}

err = e.setPriority(&priority, true)
err := e.setPriority(&priority, true)
if err != nil {
e.syslog.WithError(err).Info("setting experiment job priority")
}
Expand Down

0 comments on commit 72bc3cf

Please sign in to comment.