Skip to content

Commit

Permalink
AWS: OOM in Dedicated pool management subroutine - New Year Jan bug h…
Browse files Browse the repository at this point in the history
…otfix (#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.
  • Loading branch information
sparshev authored Jan 3, 2025
1 parent 06dfb0a commit c5bb373
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
3 changes: 2 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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) ---"
Expand Down
2 changes: 1 addition & 1 deletion lib/drivers/aws/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
38 changes: 38 additions & 0 deletions lib/drivers/aws/util_test.go
Original file line number Diff line number Diff line change
@@ -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))
}
}
})
}
}

0 comments on commit c5bb373

Please sign in to comment.