From a2ada5565fe84fee4ecdddadf3f2229042963987 Mon Sep 17 00:00:00 2001 From: Vasi Vasireddy <41936996+vasireddy99@users.noreply.github.com> Date: Tue, 20 Feb 2024 08:30:40 -0800 Subject: [PATCH] Add More regexes for Lambda Layer cleaner (#2647) * Add More regexes for Lambda Layer cleaner * Add Tests * Modify test names * Fix lint error * remove duplicates --- tools/workflow/cleaner/lambda/clean.go | 5 +- tools/workflow/cleaner/lambda/clean_test.go | 60 +++++++++++++++++++++ 2 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 tools/workflow/cleaner/lambda/clean_test.go diff --git a/tools/workflow/cleaner/lambda/clean.go b/tools/workflow/cleaner/lambda/clean.go index 9c2e2b9f19..f2220cc9c3 100644 --- a/tools/workflow/cleaner/lambda/clean.go +++ b/tools/workflow/cleaner/lambda/clean.go @@ -151,10 +151,11 @@ func shouldDeleteLayer(layerList *lambda.LayersListItem, expirationDate time.Tim layerARN := layerList.LayerArn regexList := []string{ ".*:layer:aws-otel-collector.*$", - ".*:layer:aws-otel-lambda-python.*$", ".*:layer:aws-otel-java.*$", - ".*:layer:aws-otel-lambda-nodejs.*$", + ".*:layer:aws-otel-lambda.*$", + ".*:layer:aws-otel-nodejs.*$", ".*:layer:aws-otel-go-wrapper.*$", + ".*:layer:opentelemetry.*$", ".*:layer:aws-observability.*$", ".*:layer:aws-distro-for-opentelemetry.*$", } diff --git a/tools/workflow/cleaner/lambda/clean_test.go b/tools/workflow/cleaner/lambda/clean_test.go new file mode 100644 index 0000000000..1c42e1feff --- /dev/null +++ b/tools/workflow/cleaner/lambda/clean_test.go @@ -0,0 +1,60 @@ +package lambda + +import ( + "testing" + + "github.com/aws/aws-sdk-go/aws" + + "time" + + "github.com/aws/aws-sdk-go/service/lambda" + "github.com/stretchr/testify/assert" +) + +func TestShouldDeleteLayer(t *testing.T) { + namesToTest := []struct { + testName string + mockLayerARN string + expected bool + }{ + { + testName: "aws-otel-go", + mockLayerARN: "arn:aws:lambda:us-east-1:611364707713:layer:aws-otel-go-wrapper-amd64-0ebbb233ce5cb004395b3d69cd753c7977784bf6:2", + expected: true, + }, + { + testName: "aws-otel-lambda-java", + mockLayerARN: "arn:aws:lambda:us-east-1:611364707713:layer:aws-otel-lambda-java-agent-03fe7b9dec95821fe14f0c583b25080241cfed41:1", + expected: true, + }, + { + testName: "aws-otel-lambda-java-aws-sdk", + mockLayerARN: "arn:aws:lambda:us-east-1:611364707713:layer:aws-otel-lambda-java-aws-sdk-agent-0faf1410a828a873c6c9a94e112815a147a3f03b:1", + expected: true, + }, + { + testName: "aws-otel-nodejs", + mockLayerARN: "arn:aws:lambda:us-east-1:611364707713:layer:aws-otel-nodejs-wrapper-amd64-01ccbd39e15554dc244260559f1181e9b0556287:3", + expected: true, + }, + { + testName: "opentelemetry", + mockLayerARN: "arn:aws:lambda:us-east-1:611364707713:layer:opentelemetry-python-aws-sdk-wrapper-arm64-1763695497:1", + expected: true, + }, + } + + for _, test := range namesToTest { + mockLayerARN := test.mockLayerARN + t.Run(test.testName, func(t *testing.T) { + mockInput := &lambda.LayersListItem{ + LayerArn: &mockLayerARN, + LatestMatchingVersion: &lambda.LayerVersionsListItem{ + CreatedDate: aws.String("2024-02-14T10:00:00Z"), + }, + } + actual := shouldDeleteLayer(mockInput, time.Now()) + assert.Equal(t, test.expected, actual) + }) + } +}