From 54ee01d361427e4b6427f9c58437f0c345ceeca7 Mon Sep 17 00:00:00 2001 From: Varun <48163435+varunch77@users.noreply.github.com> Date: Mon, 27 Jan 2025 10:26:17 -0500 Subject: [PATCH] Fix flaky cloudwatchlogs test (#455) --- test/cloudwatchlogs/publish_logs_test.go | 7 +++++-- test/cloudwatchlogs/resources/config_auto_removal.json | 3 ++- test/cloudwatchlogs/resources/config_log.json | 3 ++- test/cloudwatchlogs/resources/config_log_filter.json | 3 ++- .../resources/config_log_infrequent_access.json | 5 +++-- .../resources/config_log_no_class_specification.json | 5 +++-- test/cloudwatchlogs/resources/config_log_rotated.json | 3 ++- .../resources/config_log_standard_access.json | 5 +++-- test/e2e/jmx/jmx_test.go | 2 +- 9 files changed, 23 insertions(+), 13 deletions(-) diff --git a/test/cloudwatchlogs/publish_logs_test.go b/test/cloudwatchlogs/publish_logs_test.go index 7a5ca8831..faa166b18 100644 --- a/test/cloudwatchlogs/publish_logs_test.go +++ b/test/cloudwatchlogs/publish_logs_test.go @@ -249,7 +249,10 @@ func TestLogGroupClass(t *testing.T) { for _, param := range cloudWatchLogGroupClassTestParameters { t.Run(param.testName, func(t *testing.T) { - defer awsservice.DeleteLogGroupAndStream(param.logGroupName, instanceId) + // add instance id to ensure that running integration tests concurrently doesn't cause tests + // to operate and validate with the same log groups and lead to flaky results + logGroupName := param.logGroupName + "-" + instanceId + defer awsservice.DeleteLogGroupAndStream(logGroupName, instanceId) common.DeleteFile(common.AgentLogFile) common.TouchFile(common.AgentLogFile) @@ -269,7 +272,7 @@ func TestLogGroupClass(t *testing.T) { } t.Logf("Agent logs %s", string(agentLog)) - assert.True(t, awsservice.IsLogGroupExists(param.logGroupName, param.logGroupClass)) + assert.True(t, awsservice.IsLogGroupExists(logGroupName, param.logGroupClass)) }) } } diff --git a/test/cloudwatchlogs/resources/config_auto_removal.json b/test/cloudwatchlogs/resources/config_auto_removal.json index acec8efaf..cfdf7a653 100644 --- a/test/cloudwatchlogs/resources/config_auto_removal.json +++ b/test/cloudwatchlogs/resources/config_auto_removal.json @@ -11,7 +11,8 @@ "log_group_name": "{instance_id}", "log_stream_name": "{instance_id}", "timezone": "UTC", - "auto_removal": true + "auto_removal": true, + "retention_in_days": 7 } ] } diff --git a/test/cloudwatchlogs/resources/config_log.json b/test/cloudwatchlogs/resources/config_log.json index 0cb8fbb4f..c0b690bb6 100644 --- a/test/cloudwatchlogs/resources/config_log.json +++ b/test/cloudwatchlogs/resources/config_log.json @@ -11,7 +11,8 @@ "file_path": "/tmp/cwagent_log_test.log", "log_group_name": "{instance_id}", "log_stream_name": "{instance_id}", - "timezone": "UTC" + "timezone": "UTC", + "retention_in_days": 7 } ] } diff --git a/test/cloudwatchlogs/resources/config_log_filter.json b/test/cloudwatchlogs/resources/config_log_filter.json index 20d4b7aaa..d287a8f85 100644 --- a/test/cloudwatchlogs/resources/config_log_filter.json +++ b/test/cloudwatchlogs/resources/config_log_filter.json @@ -17,7 +17,8 @@ "type": "include", "expression": "foo" } - ] + ], + "retention_in_days": 7 } ] } diff --git a/test/cloudwatchlogs/resources/config_log_infrequent_access.json b/test/cloudwatchlogs/resources/config_log_infrequent_access.json index 9874010d0..e441c2d9b 100644 --- a/test/cloudwatchlogs/resources/config_log_infrequent_access.json +++ b/test/cloudwatchlogs/resources/config_log_infrequent_access.json @@ -9,10 +9,11 @@ "collect_list": [ { "file_path": "/tmp/cwagent_log_test.log", - "log_group_name": "infrequent_access", + "log_group_name": "infrequent_access-{instance_id}", "log_stream_name": "{instance_id}", "timezone": "UTC", - "log_group_class": "INFREQUENT_ACCESS" + "log_group_class": "INFREQUENT_ACCESS", + "retention_in_days": 7 } ] } diff --git a/test/cloudwatchlogs/resources/config_log_no_class_specification.json b/test/cloudwatchlogs/resources/config_log_no_class_specification.json index 6abaa73f7..73d54175b 100644 --- a/test/cloudwatchlogs/resources/config_log_no_class_specification.json +++ b/test/cloudwatchlogs/resources/config_log_no_class_specification.json @@ -9,9 +9,10 @@ "collect_list": [ { "file_path": "/tmp/cwagent_log_test.log", - "log_group_name": "standard-no-specification", + "log_group_name": "standard-no-specification-{instance_id}", "log_stream_name": "{instance_id}", - "timezone": "UTC" + "timezone": "UTC", + "retention_in_days": 7 } ] } diff --git a/test/cloudwatchlogs/resources/config_log_rotated.json b/test/cloudwatchlogs/resources/config_log_rotated.json index 35d8fffe6..810d0f237 100644 --- a/test/cloudwatchlogs/resources/config_log_rotated.json +++ b/test/cloudwatchlogs/resources/config_log_rotated.json @@ -11,7 +11,8 @@ "file_path": "/tmp/rotate_me.log*", "log_group_name": "{instance_id}", "log_stream_name": "{instance_id}Rotated", - "timezone": "UTC" + "timezone": "UTC", + "retention_in_days": 7 } ] } diff --git a/test/cloudwatchlogs/resources/config_log_standard_access.json b/test/cloudwatchlogs/resources/config_log_standard_access.json index 62265b868..5e534874e 100644 --- a/test/cloudwatchlogs/resources/config_log_standard_access.json +++ b/test/cloudwatchlogs/resources/config_log_standard_access.json @@ -9,10 +9,11 @@ "collect_list": [ { "file_path": "/tmp/cwagent_log_test.log", - "log_group_name": "standard-with-specification", + "log_group_name": "standard-with-specification-{instance_id}", "log_stream_name": "{instance_id}", "timezone": "UTC", - "log_group_class": "STANDARD" + "log_group_class": "STANDARD", + "retention_in_days": 7 } ] } diff --git a/test/e2e/jmx/jmx_test.go b/test/e2e/jmx/jmx_test.go index 4c8ba57f7..3b492fa31 100644 --- a/test/e2e/jmx/jmx_test.go +++ b/test/e2e/jmx/jmx_test.go @@ -25,7 +25,7 @@ import ( //------------------------------------------------------------------------------ var ( - env *environment.MetaData + env *environment.MetaData ) //------------------------------------------------------------------------------