Skip to content

Commit

Permalink
plugin/trans: Unify handleReserve+handleRequested (#936)
Browse files Browse the repository at this point in the history
This introduces a new method on resourceTransitioner[T],
handleRequestedGeneric(), which implements a superset of the
functionality needed by both handleReserve and handleRequested.

The two latter methods now internally "just" call the new method, albeit
with different parameterizations.

---

Other changes:

- The new method has a notion of "forced approval minimum", which sets
  the minimum value it must approve, even if the node would be
  over-budget.
  - This is used to retain the infallible behavior of handleReserve.
  - This is *also* used to move the lastPermit logic into
    handleRequested.
- Because of the new forced approval minimum, handleLastPermit is no
  longer needed.

---

In general, the motivation behind this change is to reduce the number of
distinct implementations of resource logic, so there's fewer changes
involved in implementing overcommit.
  • Loading branch information
sharnoff committed Jun 16, 2024
1 parent 3c250e4 commit 148a85d
Show file tree
Hide file tree
Showing 2 changed files with 211 additions and 156 deletions.
26 changes: 10 additions & 16 deletions pkg/plugin/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/tychoish/fun/srv"
"go.uber.org/zap"

vmapi "github.com/neondatabase/autoscaling/neonvm/apis/neonvm/v1"
"github.com/neondatabase/autoscaling/pkg/api"
)

Expand Down Expand Up @@ -282,30 +283,23 @@ func (e *AutoscaleEnforcer) handleResources(
return api.Resources{VCPU: pod.cpu.Reserved, Mem: pod.mem.Reserved}, 200, nil
}

if lastPermit != nil {
cpuVerdict := makeResourceTransitioner(&node.cpu, &pod.cpu).
handleLastPermit(lastPermit.VCPU)
memVerdict := makeResourceTransitioner(&node.mem, &pod.mem).
handleLastPermit(lastPermit.Mem)
logger.Info(
"Handled last permit info from pod",
zap.Object("verdict", verdictSet{
cpu: cpuVerdict,
mem: memVerdict,
}),
)
}

cpuFactor := cu.VCPU
if !supportsFractionalCPU {
cpuFactor = 1000
}
memFactor := cu.Mem

var lastCPUPermit *vmapi.MilliCPU
var lastMemPermit *api.Bytes
if lastPermit != nil {
lastCPUPermit = &lastPermit.VCPU
lastMemPermit = &lastPermit.Mem
}

cpuVerdict := makeResourceTransitioner(&node.cpu, &pod.cpu).
handleRequested(req.VCPU, startingMigration, cpuFactor)
handleRequested(req.VCPU, lastCPUPermit, startingMigration, cpuFactor)
memVerdict := makeResourceTransitioner(&node.mem, &pod.mem).
handleRequested(req.Mem, startingMigration, memFactor)
handleRequested(req.Mem, lastMemPermit, startingMigration, memFactor)

logger.Info(
"Handled requested resources from pod",
Expand Down
Loading

0 comments on commit 148a85d

Please sign in to comment.