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 d446399
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 30 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
11 changes: 9 additions & 2 deletions internal/backend/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,16 @@ 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.999% to avoid
// unnecessary resize operations
FileSystemResizeThreshold = float64(99.9)
// Why is the threshold set to 99.999%?
// - The largest EBS volume you can provision is a 64 TiB
// io2 Block Express volume.
// - EBS volumes can only be specified in increments of 1 GiB
// - 64 TiB = 65536 GiB | 99.999 % * 65536 = 65535.34 GiB
// - Therefore, a resize threshold of 99.999% ensures a resize
// operation from 65535 GiB to 65536 GiB, since 65535 < 65535.34
FileSystemResizeThreshold = float64(99.999)
)

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.999%
// 999989 / 1000000 → 99.9989% < 99.999% → true
{
Name: "Should Resize",
BlockDeviceMetrics: &model.BlockDeviceMetrics{
FileSystemSize: 9989,
BlockDeviceSize: 10000,
FileSystemSize: 999989,
BlockDeviceSize: 1000000,
},
ExpectedOutput: true,
},
// FileSystemThreshold = 99.9%
// 9999 / 10000 → 99.9% < 99.9% → false
// FileSystemThreshold = 99.999%
// 999990 / 100000 → 99.999% < 99.999% → false
{
Name: "Should Not Resize",
BlockDeviceMetrics: &model.BlockDeviceMetrics{
FileSystemSize: 9990,
BlockDeviceSize: 10000,
FileSystemSize: 999990,
BlockDeviceSize: 1000000,
},
ExpectedOutput: false,
},
Expand Down
38 changes: 20 additions & 18 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: 999990,
BlockDeviceSize: 1000000,
},
},
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: 999989,
BlockDeviceSize: 1000000,
},
},
CmpOption: cmp.AllowUnexported(
Expand All @@ -84,7 +84,9 @@ func TestResizeDeviceLayerModify(t *testing.T) {
},
ExpectedError: nil,
},
// These devices must be
// These devices must be mounted prior to a resize operation.
// The target of the resize opeartion would be the mountpoint, rather
// than the device itself. XFS is a file system produces this behaviour
{
Name: "Resize Block Device: Must be Mounted",
Config: &config.Config{
Expand All @@ -107,8 +109,8 @@ func TestResizeDeviceLayerModify(t *testing.T) {
},
BlockDeviceMetrics: map[string]*model.BlockDeviceMetrics{
"/dev/xvdf": {
FileSystemSize: 80,
BlockDeviceSize: 100,
FileSystemSize: 999989,
BlockDeviceSize: 1000000,
},
},
CmpOption: cmp.AllowUnexported(
Expand Down Expand Up @@ -140,8 +142,8 @@ func TestResizeDeviceLayerModify(t *testing.T) {
},
BlockDeviceMetrics: map[string]*model.BlockDeviceMetrics{
"/dev/xvdf": {
FileSystemSize: 80,
BlockDeviceSize: 100,
FileSystemSize: 999989,
BlockDeviceSize: 1000000,
},
},
CmpOption: cmp.AllowUnexported(),
Expand All @@ -168,8 +170,8 @@ func TestResizeDeviceLayerModify(t *testing.T) {
},
BlockDeviceMetrics: map[string]*model.BlockDeviceMetrics{
"/dev/xvdf": {
FileSystemSize: 80,
BlockDeviceSize: 100,
FileSystemSize: 999989,
BlockDeviceSize: 1000000,
},
},
CmpOption: cmp.AllowUnexported(),
Expand Down Expand Up @@ -217,8 +219,8 @@ func TestResizeDeviceLayerValidate(t *testing.T) {
},
BlockDeviceMetrics: map[string]*model.BlockDeviceMetrics{
"/dev/xvdf": {
FileSystemSize: 9990,
BlockDeviceSize: 10000,
FileSystemSize: 999990,
BlockDeviceSize: 1000000,
},
},
ExpectedError: nil,
Expand All @@ -243,8 +245,8 @@ func TestResizeDeviceLayerValidate(t *testing.T) {
},
BlockDeviceMetrics: map[string]*model.BlockDeviceMetrics{
"/dev/xvdf": {
FileSystemSize: 9989,
BlockDeviceSize: 10000,
FileSystemSize: 999989,
BlockDeviceSize: 1000000,
},
},
ExpectedError: nil,
Expand All @@ -269,11 +271,11 @@ func TestResizeDeviceLayerValidate(t *testing.T) {
},
BlockDeviceMetrics: map[string]*model.BlockDeviceMetrics{
"/dev/xvdf": {
FileSystemSize: 9989,
BlockDeviceSize: 10000,
FileSystemSize: 999989,
BlockDeviceSize: 1000000,
},
},
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=999989 Block Device=1000000 (bytes)"),
},
}
for _, subtest := range subtests {
Expand Down

0 comments on commit d446399

Please sign in to comment.