Skip to content

Commit

Permalink
chore: check config policies on 'det notebook set priority' (#10047)
Browse files Browse the repository at this point in the history
  • Loading branch information
stoksc authored Oct 15, 2024
1 parent 2ef2f12 commit 5a39ecb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
11 changes: 11 additions & 0 deletions master/internal/command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/uptrace/bun"
"golang.org/x/exp/slices"

"github.com/determined-ai/determined/master/internal/configpolicy"
internaldb "github.com/determined-ai/determined/master/internal/db"
"github.com/determined-ai/determined/master/internal/job/jobservice"
"github.com/determined-ai/determined/master/internal/rm"
Expand Down Expand Up @@ -278,6 +279,16 @@ func (c *Command) garbageCollect() {
}

func (c *Command) setNTSCPriority(priority int, forward bool) error {
if smallerHigher, err := c.rm.SmallerValueIsHigherPriority(); err == nil {
ok, err := configpolicy.PriorityUpdateAllowed(int(c.Metadata.WorkspaceID), model.NTSCType, priority, smallerHigher)
if err != nil {
return err
}
if !ok {
return fmt.Errorf("priority exceeds task config policy's priority_limit")
}
}

if forward {
switch err := c.rm.SetGroupPriority(sproto.SetGroupPriority{
Priority: priority,
Expand Down
1 change: 1 addition & 0 deletions master/internal/command/command_intg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ func setupTest(t *testing.T) *db.PgDB {
mockRM.On("Allocate", mock.Anything, mock.Anything).Return(sub, nil)
mockRM.On("Release", mock.Anything, mock.Anything).Return(nil)
mockRM.On("SetGroupPriority", mock.Anything, mock.Anything).Return(nil)
mockRM.On("SmallerValueIsHigherPriority").Return(true, nil)

cs, _ := NewService(db.SingleDB(), &mockRM)
SetDefaultService(cs)
Expand Down

0 comments on commit 5a39ecb

Please sign in to comment.