Skip to content

Commit

Permalink
have MinimumFreeSize take precedence over the low usage threshold
Browse files Browse the repository at this point in the history
  • Loading branch information
majewsky committed Feb 20, 2020
1 parent 882bb98 commit 2496599
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
9 changes: 9 additions & 0 deletions internal/core/logic.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,15 @@ func checkReason(res db.Resource, asset db.Asset, reason db.OperationReason) *ui
}
}

//ALSO the MinimumFreeSize takes precedence over the low threshold: we're
//allowed to go into low usage if it helps us satisfy the MinimumFreeSize
if res.MinimumFreeSize != nil && asset.AbsoluteUsage != nil {
minSize := *res.MinimumFreeSize + *asset.AbsoluteUsage
if lowSize < minSize {
lowSize = minSize
}
}

if lowSize > 0 {
c.forbidAbove(lowSize)
}
Expand Down
33 changes: 32 additions & 1 deletion internal/tasks/asset_scrape_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1119,7 +1119,7 @@ func TestResizesEndingUpInLowThreshold(baseT *testing.T) {
t.ExpectPendingOperations(c.DB /*, nothing */)
t.ExpectFinishedOperations(c.DB /*, nothing */)

//BUT when we're inside the high/critical threshold, a downsize should be
//BUT when we're inside the high/critical threshold, an upsize should be
//generated even though upsizing puts us below the low threshold -- the
//idea being that it's better to be slightly too large than slightly too
//small
Expand All @@ -1141,6 +1141,37 @@ func TestResizesEndingUpInLowThreshold(baseT *testing.T) {
})
}

func TestUpsizeBecauseOfMinFreeSizePassingLowThreshold(baseT *testing.T) {
t := test.T{T: baseT}
forAllSteppingStrategies(t, func(c *Context, res db.Resource, setAsset func(plugins.StaticAsset), clock *test.FakeClock) {

//test that min_free_size takes precedence over the low usage threshold: we
//should upsize the asset to guarantee the min_free_size, even if this puts
//usage below the threshold
t.MustExec(c.DB, `UPDATE resources SET min_free_size = 2500`)
if !res.SingleStep {
//for percentage-step resizing, we need to set the size step comically
//large because we need to get below the low usage threshold to actually
//trigger the condition we want to test
t.MustExec(c.DB, `UPDATE resources SET size_step_percent = 200`)
}

clock.StepBy(10 * time.Minute)
t.Must(c.ScrapeNextAsset("foo", c.TimeNow()))

t.ExpectPendingOperations(c.DB, db.PendingOperation{
ID: 1,
AssetID: 1,
Reason: db.OperationReasonHigh,
OldSize: 1000,
NewSize: 3000,
UsagePercent: 50,
CreatedAt: c.TimeNow(),
})
t.ExpectFinishedOperations(c.DB /*, nothing */)
})
}

func ifthenelseF64(cond bool, thenValue float64, elseValue float64) float64 {
if cond {
return thenValue
Expand Down

0 comments on commit 2496599

Please sign in to comment.