Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test auto removal #345

Merged
merged 8 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions test/cloudwatchlogs/publish_logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,35 @@ func TestWriteLogsToCloudWatch(t *testing.T) {
}
}

// TestAutoRemovalStopAgent configures agent to monitor a file with auto removal on.
// Then it restarts the agent.
// Verify the file is NOT removed.
func TestAutoRemovalStopAgent(t *testing.T) {
adam-mateen marked this conversation as resolved.
Show resolved Hide resolved
// Use instance id so 2 tests in parallel on different machines do not conflict.
instanceId := awsservice.GetInstanceId()
defer awsservice.DeleteLogGroupAndStream(instanceId, instanceId)
fpath := logFilePath + "1"
f, err := os.Create(fpath)
if err != nil {
t.Fatalf("Error occurred creating log file for writing: %v", err)
}
defer f.Close()
defer os.Remove(fpath)
configPath := "resources/config_auto_removal.json"
common.StartAgent(configPath, true, false)
// Sleep 20 seconds before and after writing the file to ensure the agent reads it.
sleepTime := time.Second*20
time.Sleep(sleepTime)
writeLogs(t, f, 1000)
time.Sleep(sleepTime)
common.StopAgent()
time.Sleep(sleepTime)
assert.FileExists(t, fpath, "file does not exist, {}", fpath)
common.StartAgent(configPath, true, false)
adam-mateen marked this conversation as resolved.
Show resolved Hide resolved
time.Sleep(sleepTime)
assert.FileExists(t, fpath, "file does not exist, {}", fpath)
}

// TestRotatingLogsDoesNotSkipLines validates https://github.com/aws/amazon-cloudwatch-agent/issues/447
// The following should happen in the test:
// 1. A log line of size N should be written
Expand Down
20 changes: 20 additions & 0 deletions test/cloudwatchlogs/resources/config_auto_removal.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"agent": {
"debug": true
},
"logs": {
"logs_collected": {
"files": {
"collect_list": [
{
"file_path": "/tmp/test.log*",
"log_group_name": "{instance_id}",
"log_stream_name": "{instance_id}",
"timezone": "UTC",
"auto_removal": true
}
]
}
}
}
}