-
Notifications
You must be signed in to change notification settings - Fork 30
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
Add logs agent integ test #433
base: main
Are you sure you want to change the base?
Changes from 1 commit
21aa051
734f8e0
5ed1a93
96522cd
b98c612
bdd40b9
43d2ca6
9f28f03
e1bb9ce
fd59713
6e00757
bb229f7
84cc3d3
7a3b428
e37d84a
79744f1
7950725
37cb8a5
006a057
eb95406
df7abce
8dcc2d4
9f5722b
6f1e4cf
5bd4a65
d116feb
6c272ee
58f0a88
a555d2c
5138c20
dfb7272
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,7 +43,7 @@ const ( | |
standardLogGroupClass = "STANDARD" | ||
infrequentAccessLogGroupClass = "INFREQUENT_ACCESS" | ||
cwlPerfEndpoint = "https://logs.us-west-2.amazonaws.com" | ||
pdxRegionalCode = "us-west-2" | ||
pdxRegionalCode = "us-west-2" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. region hardcoding is not needed since entity feature is GA |
||
|
||
entityType = "@entity.KeyAttributes.Type" | ||
entityName = "@entity.KeyAttributes.Name" | ||
|
@@ -275,6 +275,17 @@ func TestWriteLogsWithEntityInfo(t *testing.T) { | |
if err != nil { | ||
t.Fatalf("Error occurred creating log file for writing: %v", err) | ||
} | ||
|
||
// Defer file closing and removal with error handling | ||
defer func() { | ||
if err := f.Close(); err != nil { | ||
t.Errorf("Error occurred closing log file: %v", err) | ||
} | ||
if err := os.Remove(logFilePath + "-" + id.String()); err != nil { | ||
t.Errorf("Error occurred removing log file: %v", err) | ||
} | ||
}() | ||
|
||
common.DeleteFile(common.AgentLogFile) | ||
common.TouchFile(common.AgentLogFile) | ||
|
||
|
@@ -286,11 +297,9 @@ func TestWriteLogsWithEntityInfo(t *testing.T) { | |
time.Sleep(sleepForExtendedFlush) | ||
common.StopAgent() | ||
end := time.Now() | ||
begin := end.Add(-sleepForExtendedFlush * 4) | ||
|
||
ValidateEntity(t, instanceId, instanceId, &end, testCase.expectedEntity) | ||
|
||
f.Close() | ||
os.Remove(logFilePath + "-" + id.String()) | ||
ValidateEntity(t, instanceId, instanceId, &begin, &end, testCase.expectedEntity) | ||
}) | ||
} | ||
} | ||
|
@@ -489,20 +498,20 @@ func checkData(t *testing.T, start time.Time, lineCount int) { | |
assert.NoError(t, err) | ||
} | ||
|
||
func ValidateEntity(t *testing.T, logGroup, logStream string, end *time.Time, expectedEntity expectedEntity) { | ||
func ValidateEntity(t *testing.T, logGroup, logStream string, begin, end *time.Time, expectedEntity expectedEntity) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nonblocking but recommended: This function has a lot of overlaps with this function: https://github.com/aws/amazon-cloudwatch-agent-test/blob/main/test/entity/entity_test.go#L241 Maybe good idea to move |
||
log.Printf("Validating entity for log group: %s, stream: %s", logGroup, logStream) | ||
|
||
logGroupInfo, err := getLogGroup() | ||
logGroupInfo, err := getLogGroup(logGroup) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can just use The helper functions that I wrote was because we had to create a new client in us-east-1 for beta purpose but they are no longer needed |
||
for _, lg := range logGroupInfo { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there no way to get a specific log group when you provide the name? Seems expensive to get all log groups in an account. We have a ton in our test account.. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think there's a way to just search for one log group (why not is beyond me..) but I updated this so it passes in the log group as a prefix to search by (commit 006a057) |
||
if *lg.LogGroupName == logGroup { | ||
log.Println("Log group " + *lg.LogGroupName + " exists") | ||
break | ||
} | ||
} | ||
assert.NoError(t, err) | ||
begin := end.Add(-sleepForExtendedFlush * 4) | ||
|
||
log.Printf("Query start time is " + begin.String() + " and end time is " + end.String()) | ||
queryId, err := getLogQueryId(logGroup, &begin, end) | ||
queryId, err := getLogQueryId(logGroup, begin, end) | ||
assert.NoError(t, err) | ||
log.Printf("queryId is " + *queryId) | ||
result, err := getQueryResult(queryId) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
@@ -614,10 +623,12 @@ func getQueryResult(queryId *string) ([][]types.ResultField, error) { | |
} | ||
} | ||
|
||
func getLogGroup() ([]types.LogGroup, error) { | ||
func getLogGroup(logGroupName string) ([]types.LogGroup, error) { | ||
attempts := 0 | ||
var logGroups []types.LogGroup | ||
params := &cloudwatchlogs.DescribeLogGroupsInput{} | ||
params := &cloudwatchlogs.DescribeLogGroupsInput{ | ||
LogGroupNamePrefix: aws.String(logGroupName), | ||
} | ||
for { | ||
output, err := cwlClient.DescribeLogGroups(context.Background(), params) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This relies on the fact that we are running the test in us-west-2...
I know we only run our tests in us-west-2 but can we detect the region on the host and then populate the endpoint accordingly so that in the future we can support other regions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we may already be constrained by the region being hardcoded elsewhere: https://github.com/aws/amazon-cloudwatch-agent-test/blob/main/util/awsservice/constant.go#L58C1-L60C78. We would need to make edits there but I'm a little wary of what the blast radius of that would look like for our testing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need to hardcode the endpoint here. The code I wrote originally had to use a custom endpoint because it was a beta endpoint but this is the public us-west-2 endpoint which the client will automatically resolve