Skip to content

Commit

Permalink
(feat): Increase resize threshold to 99.99%
Browse files Browse the repository at this point in the history
  • Loading branch information
lasith-kg committed May 23, 2024
1 parent b2b8d87 commit a5a7535
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 29 deletions.
4 changes: 2 additions & 2 deletions internal/backend/lvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
const (
// The % tolerance to expect the logical volume size to be within
// -------------------------------------------------------
// If the (logical volume / volume group size) * 100 is less than
// If the (logical volume size / volume group size) * 100 is less than
// (lvmConsumption% - tolerance%) then we perform a resize operation
// -------------------------------------------------------
// If the (logical volume / volume group size) * 100 is greater than
Expand All @@ -31,7 +31,7 @@ const (
LogicalVolumeResizeTolerance = float64(0.1)
// The % threshold at which to resize a physical volume
// -------------------------------------------------------
// If the (physical volume / device size) * 100 falls
// If the (physical volume size / device size) * 100 falls
// under this threshold then we perform a resize operation
// -------------------------------------------------------
// The smallest gp3 EBS volume you can create is 1GiB (1073741824 bytes).
Expand Down
4 changes: 2 additions & 2 deletions internal/backend/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ const (
// slightly less than that of the underlying block device
// - This is likely due to reserved sections that store
// file system metadata
// - Therefore we set the threshold to 99.9% to avoid
// - Therefore we set the threshold to 99.99% to avoid
// unnecessary resize operations
FileSystemResizeThreshold = float64(99.9)
FileSystemResizeThreshold = float64(99.99)
)

type DeviceMetricsBackend interface {
Expand Down
16 changes: 8 additions & 8 deletions internal/backend/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,23 +57,23 @@ func TestLinuxDeviceMetricsBackendShouldResize(t *testing.T) {
BlockDeviceMetrics *model.BlockDeviceMetrics
ExpectedOutput bool
}{
// FileSystemThreshold = 99.9%
// 9989 / 10000 → 99.89% < 99.9% → true
// FileSystemThreshold = 99.99%
// 99989 / 100000 → 99.989% < 99.99% → true
{
Name: "Should Resize",
BlockDeviceMetrics: &model.BlockDeviceMetrics{
FileSystemSize: 9989,
BlockDeviceSize: 10000,
FileSystemSize: 99989,
BlockDeviceSize: 100000,
},
ExpectedOutput: true,
},
// FileSystemThreshold = 99.9%
// 9999 / 10000 → 99.9% < 99.9% → false
// FileSystemThreshold = 99.99%
// 99990 / 100000 → 99.99% < 99.99% → false
{
Name: "Should Not Resize",
BlockDeviceMetrics: &model.BlockDeviceMetrics{
FileSystemSize: 9990,
BlockDeviceSize: 10000,
FileSystemSize: 99990,
BlockDeviceSize: 100000,
},
ExpectedOutput: false,
},
Expand Down
34 changes: 17 additions & 17 deletions internal/layer/resize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ func TestResizeDeviceLayerModify(t *testing.T) {
},
BlockDeviceMetrics: map[string]*model.BlockDeviceMetrics{
"/dev/xvdf": {
FileSystemSize: 9990,
BlockDeviceSize: 10000,
FileSystemSize: 99990,
BlockDeviceSize: 100000,
},
},
CmpOption: cmp.AllowUnexported(),
Expand All @@ -71,8 +71,8 @@ func TestResizeDeviceLayerModify(t *testing.T) {
},
BlockDeviceMetrics: map[string]*model.BlockDeviceMetrics{
"/dev/xvdf": {
FileSystemSize: 9989,
BlockDeviceSize: 10000,
FileSystemSize: 99989,
BlockDeviceSize: 100000,
},
},
CmpOption: cmp.AllowUnexported(
Expand Down Expand Up @@ -107,8 +107,8 @@ func TestResizeDeviceLayerModify(t *testing.T) {
},
BlockDeviceMetrics: map[string]*model.BlockDeviceMetrics{
"/dev/xvdf": {
FileSystemSize: 80,
BlockDeviceSize: 100,
FileSystemSize: 99989,
BlockDeviceSize: 100000,
},
},
CmpOption: cmp.AllowUnexported(
Expand Down Expand Up @@ -140,8 +140,8 @@ func TestResizeDeviceLayerModify(t *testing.T) {
},
BlockDeviceMetrics: map[string]*model.BlockDeviceMetrics{
"/dev/xvdf": {
FileSystemSize: 80,
BlockDeviceSize: 100,
FileSystemSize: 99989,
BlockDeviceSize: 100000,
},
},
CmpOption: cmp.AllowUnexported(),
Expand All @@ -168,8 +168,8 @@ func TestResizeDeviceLayerModify(t *testing.T) {
},
BlockDeviceMetrics: map[string]*model.BlockDeviceMetrics{
"/dev/xvdf": {
FileSystemSize: 80,
BlockDeviceSize: 100,
FileSystemSize: 99989,
BlockDeviceSize: 100000,
},
},
CmpOption: cmp.AllowUnexported(),
Expand Down Expand Up @@ -217,8 +217,8 @@ func TestResizeDeviceLayerValidate(t *testing.T) {
},
BlockDeviceMetrics: map[string]*model.BlockDeviceMetrics{
"/dev/xvdf": {
FileSystemSize: 9990,
BlockDeviceSize: 10000,
FileSystemSize: 99990,
BlockDeviceSize: 100000,
},
},
ExpectedError: nil,
Expand All @@ -243,8 +243,8 @@ func TestResizeDeviceLayerValidate(t *testing.T) {
},
BlockDeviceMetrics: map[string]*model.BlockDeviceMetrics{
"/dev/xvdf": {
FileSystemSize: 9989,
BlockDeviceSize: 10000,
FileSystemSize: 99989,
BlockDeviceSize: 100000,
},
},
ExpectedError: nil,
Expand All @@ -269,11 +269,11 @@ func TestResizeDeviceLayerValidate(t *testing.T) {
},
BlockDeviceMetrics: map[string]*model.BlockDeviceMetrics{
"/dev/xvdf": {
FileSystemSize: 9989,
BlockDeviceSize: 10000,
FileSystemSize: 99989,
BlockDeviceSize: 100000,
},
},
ExpectedError: fmt.Errorf("🔴 /dev/xvdf: Failed to resize file system. File System=9989 Block Device=10000 (bytes)"),
ExpectedError: fmt.Errorf("🔴 /dev/xvdf: Failed to resize file system. File System=99989 Block Device=100000 (bytes)"),
},
}
for _, subtest := range subtests {
Expand Down

0 comments on commit a5a7535

Please sign in to comment.