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

Add logic to restart the windows event log service for the windows event log tests #415

Closed
wants to merge 10 commits into from

Conversation

lisguo
Copy link
Contributor

@lisguo lisguo commented Aug 1, 2024

Description of the issue

We need to ensure the agent is able to publish windows event logs even when the event log service restarts or crashes

Description of changes

Adds steps to kill the event log service pid, and then start the service before publishing event logs. Used a variation of the following powershell script:

Function Get-EventLogPid {
	$ServiceName = 'EventLog'
	$filter = "name like ""$ServiceName"" or displayname like ""$ServiceName"""
	$Service = gcim -ClassName Win32_Service -Filter $filter
	return $Service.ProcessId
}


# 1. Get the EvenLogPid
$EventLogPid = Get-EventLogPid

# 2. Kill EventLog service by PID
Stop-Process $EventLogPid -Force
sleep 20


# 3. Start the eventlog service
Start-Service EventLog

License

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Tests

Ran a test with a version of the agent that did not have the event log fix:
https://github.com/aws/amazon-cloudwatch-agent/actions/runs/10205915443

Ran a test with latest changes of the agent with the event log fix:
https://github.com/aws/amazon-cloudwatch-agent/actions/runs/10205917120

@lisguo lisguo requested review from jefchien and okankoAMZ August 1, 2024 21:01
@lisguo lisguo requested a review from a team as a code owner August 1, 2024 21:01
@@ -21,6 +21,41 @@ import (

const logLine = "# %d - This is a log line. \n"

func KillEventLogService() error {
eventLogPid, err := exec.Command("powershell.exe", "-Command", "\"gcim -ClassName Win32_Service -Filter \\\"name like 'EventLog' or displayname like 'EventLog'\\\"").Output()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Could probably have it call your powershell script like the sanity tests.

okankoAMZ
okankoAMZ previously approved these changes Aug 2, 2024
@lisguo lisguo closed this Aug 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants