From c5bb3739b2b64905a25f03c775e8fc62e9b51832 Mon Sep 17 00:00:00 2001 From: Sergei Parshev <8136445+sparshev@users.noreply.github.com> Date: Fri, 3 Jan 2025 11:35:14 -0500 Subject: [PATCH] AWS: OOM in Dedicated pool management subroutine - New Year Jan bug hotfix (#89) This nasty bug appears only in January of each year and affects the Fish configurations with enabled dedicated pool management. It causes OOM due to incorrect handling of 1st month of the year and the schedule runs dedicated pool refresh. --- build.sh | 3 ++- lib/drivers/aws/util.go | 2 +- lib/drivers/aws/util_test.go | 38 ++++++++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 lib/drivers/aws/util_test.go diff --git a/build.sh b/build.sh index c1728e6..55bb190 100755 --- a/build.sh +++ b/build.sh @@ -53,7 +53,8 @@ BINARY_NAME="aquarium-fish-$git_version" echo echo "--- RUN UNIT TESTS ---" -go test -ldflags="$version_flags" -v ./lib/... +# Unit tests should not consume more then 5 sec per run - for that we have integration tests +go test -timeout=5s -ldflags="$version_flags" -v ./lib/... echo echo "--- BUILD ${BINARY_NAME} ($MAXJOBS in parallel) ---" diff --git a/lib/drivers/aws/util.go b/lib/drivers/aws/util.go index 4db5e13..6c63d87 100644 --- a/lib/drivers/aws/util.go +++ b/lib/drivers/aws/util.go @@ -717,7 +717,7 @@ func (d *Driver) deleteImage(conn *ec2.Client, id string) (err error) { func awsLastYearFilterValues(till time.Time) (out []string) { date := till // Iterating over months to cover the last year - for date.Year() == till.Year() || date.Month() >= till.Month() { + for date.Year() == till.Year() || date.Month() > till.Month() { out = append(out, date.Format("2006-01-*")) date = date.AddDate(0, -1, 0) } diff --git a/lib/drivers/aws/util_test.go b/lib/drivers/aws/util_test.go new file mode 100644 index 0000000..dbbfe0e --- /dev/null +++ b/lib/drivers/aws/util_test.go @@ -0,0 +1,38 @@ +/** + * Copyright 2024 Adobe. All rights reserved. + * This file is licensed to you under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. You may obtain a copy + * of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under + * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS + * OF ANY KIND, either express or implied. See the License for the specific language + * governing permissions and limitations under the License. + */ + +package aws + +import ( + "fmt" + "testing" + "time" +) + +// Make sure there is no more issues in a simple logic of awsLastYearFilterValues like the Jan bug +func Test_awsLastYearFilterValues(t *testing.T) { + // Next 100 years should be enough to be sure + imagesTill := time.Now() + endyear := imagesTill.AddDate(100, 0, 0).Year() + for imagesTill.Year() < endyear { + curryear := imagesTill.Year() + t.Run(fmt.Sprintf("Testing year `%d`", curryear), func(t *testing.T) { + for imagesTill.Year() == curryear { + imagesTill = imagesTill.AddDate(0, 1, 0) + out := awsLastYearFilterValues(imagesTill) + if len(out) != 12 { + t.Fatalf("awsLastYearFilterValues(`%s`) = `%s` (len = %d); want: 12 values", imagesTill.Format("2006-01"), out, len(out)) + } + } + }) + } +}