From a5a7535347422a3a84d7c291f8c9e8add2c5e0e2 Mon Sep 17 00:00:00 2001 From: lasith-kg Date: Thu, 23 May 2024 14:09:18 +0000 Subject: [PATCH] (feat): Increase resize threshold to 99.99% --- internal/backend/lvm.go | 4 ++-- internal/backend/metrics.go | 4 ++-- internal/backend/metrics_test.go | 16 +++++++-------- internal/layer/resize_test.go | 34 ++++++++++++++++---------------- 4 files changed, 29 insertions(+), 29 deletions(-) diff --git a/internal/backend/lvm.go b/internal/backend/lvm.go index aa54b4e..d1f53b6 100644 --- a/internal/backend/lvm.go +++ b/internal/backend/lvm.go @@ -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 @@ -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). diff --git a/internal/backend/metrics.go b/internal/backend/metrics.go index 1fc12df..928d931 100644 --- a/internal/backend/metrics.go +++ b/internal/backend/metrics.go @@ -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 { diff --git a/internal/backend/metrics_test.go b/internal/backend/metrics_test.go index 37e999f..6f2f66c 100644 --- a/internal/backend/metrics_test.go +++ b/internal/backend/metrics_test.go @@ -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, }, diff --git a/internal/layer/resize_test.go b/internal/layer/resize_test.go index e7dfbdd..cf2ffef 100644 --- a/internal/layer/resize_test.go +++ b/internal/layer/resize_test.go @@ -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(), @@ -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( @@ -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( @@ -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(), @@ -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(), @@ -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, @@ -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, @@ -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 {