-
Notifications
You must be signed in to change notification settings - Fork 31
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 Windows Start Agent With EC2 Run Command #378
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,7 +62,7 @@ resource "aws_instance" "cwagent" { | |
vpc_security_group_ids = [module.basic_components.security_group] | ||
associate_public_ip_address = true | ||
instance_initiated_shutdown_behavior = "terminate" | ||
user_data = length(regexall("/feature/windows/userdata", var.test_dir)) > 0 ? data.template_file.user_data.rendered : "" | ||
user_data = length(regexall("/feature/windows/custom_start/userdata", var.test_dir)) > 0 ? data.template_file.user_data.rendered : "" | ||
get_password_data = true | ||
|
||
metadata_options { | ||
|
@@ -86,7 +86,7 @@ resource "aws_ssm_parameter" "upload_ssm" { | |
} | ||
|
||
resource "null_resource" "integration_test_setup_agent" { | ||
count = length(regexall("/feature/windows/userdata", var.test_dir)) > 0 ? 0 : 1 | ||
count = length(regexall("/feature/windows/custom_start/userdata", var.test_dir)) > 0 ? 0 : 1 | ||
depends_on = [aws_instance.cwagent, module.validator, aws_ssm_parameter.upload_ssm] | ||
|
||
# Install software | ||
|
@@ -193,7 +193,7 @@ resource "null_resource" "integration_test_run" { | |
|
||
resource "null_resource" "integration_test_run_validator" { | ||
# run validator only when test_dir is not passed e.g. the default from variable.tf | ||
count = length(regexall("/feature/windows", var.test_dir)) > 0 && length(regexall("/feature/windows/userdata", var.test_dir)) < 1 ? 1 : 0 | ||
count = length(regexall("/feature/windows", var.test_dir)) > 0 && length(regexall("/feature/windows/custom_start", var.test_dir)) < 1 ? 1 : 0 | ||
depends_on = [ | ||
null_resource.integration_test_setup_agent, | ||
null_resource.integration_test_setup_validator, | ||
|
@@ -237,9 +237,9 @@ resource "null_resource" "integration_test_run_validator" { | |
} | ||
} | ||
|
||
resource "null_resource" "integration_test_run_validator_userdata" { | ||
resource "null_resource" "integration_test_run_validator_start_agent_ssm" { | ||
# run validator only when test_dir is not passed e.g. the default from variable.tf | ||
count = length(regexall("/feature/windows/userdata", var.test_dir)) > 0 ? 1 : 0 | ||
count = length(regexall("/feature/windows/custom_start/ssm_start", var.test_dir)) > 0 ? 1 : 0 | ||
depends_on = [ | ||
null_resource.integration_test_setup_validator, | ||
null_resource.integration_test_wait, | ||
|
@@ -262,12 +262,47 @@ resource "null_resource" "integration_test_run_validator_userdata" { | |
destination = module.validator.instance_validator_config | ||
} | ||
|
||
//runs validator and sets up prometheus java agent | ||
provisioner "remote-exec" { | ||
inline = [ | ||
"set AWS_REGION=${var.region}", | ||
"aws ssm send-command --document-name AmazonCloudWatch-ManageAgent --parameters optionalConfigurationLocation=${local.ssm_parameter_name} --targets Key=tag:Name,Values=cwagent-integ-test-ec2-windows-${var.test_name}-${module.common.testing_id}", | ||
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. ssm command to start the agent with the config file uploaded to ssm parameters |
||
] | ||
} | ||
} | ||
|
||
resource "null_resource" "integration_test_run_validator_custom_start" { | ||
# run validator only when test_dir is not passed e.g. the default from variable.tf | ||
count = length(regexall("/feature/windows/custom_start", var.test_dir)) > 0 ? 1 : 0 | ||
depends_on = [ | ||
null_resource.integration_test_setup_validator, | ||
null_resource.integration_test_wait, | ||
null_resource.integration_test_run_validator_start_agent_ssm | ||
] | ||
|
||
connection { | ||
type = "winrm" | ||
user = "Administrator" | ||
password = rsadecrypt(aws_instance.cwagent.password_data, local.private_key_content) | ||
host = aws_instance.cwagent.public_dns | ||
} | ||
|
||
provisioner "file" { | ||
source = module.validator.agent_config | ||
destination = module.validator.instance_agent_config | ||
} | ||
|
||
provisioner "file" { | ||
source = module.validator.validator_config | ||
destination = module.validator.instance_validator_config | ||
} | ||
|
||
//runs validator and sets up prometheus java agent | ||
provisioner "remote-exec" { | ||
inline = [ | ||
"set AWS_REGION=${var.region}", | ||
"validator.exe --validator-config=${module.validator.instance_validator_config} --preparation-mode=true", | ||
"powershell.exe \"& \"C:ProgramFiles\\Amazon\\AmazonCloudWatchAgent\\amazon-cloudwatch-agent-ctl.ps1\" -m ec2 -a status\"", | ||
"powershell.exe \"& 'C:ProgramFiles\\Amazon\\AmazonCloudWatchAgent\\amazon-cloudwatch-agent-ctl.ps1' -m ec2 -a status\"", | ||
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 should not use double quotes here to get status check |
||
"validator.exe --validator-config=${module.validator.instance_validator_config} --preparation-mode=false" | ||
] | ||
} | ||
|
File renamed without changes.
File renamed without changes.
216 changes: 216 additions & 0 deletions
216
test/feature/windows/custom_start/userdata/agent_config.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,216 @@ | ||
{ | ||
"agent": { | ||
"debug": true | ||
}, | ||
"metrics": { | ||
"namespace": "CloudWatchAgentWinFeature", | ||
"metrics_collected": { | ||
"Processor": { | ||
"measurement": [ | ||
{ | ||
"name":"% Idle Time", | ||
"rename": "Idle_Time" | ||
}, | ||
{ | ||
"name":"% Interrupt Time", | ||
"rename": "Interrupt_Time" | ||
}, | ||
{ | ||
"name":"% User Time", | ||
"rename": "User_Time" | ||
}, | ||
{ | ||
"name":"% Processor Time", | ||
"rename": "Processor_Time" | ||
} | ||
], | ||
"resources": [ | ||
"*" | ||
], | ||
"metrics_collection_interval": 1 | ||
}, | ||
"LogicalDisk": { | ||
"measurement": [ | ||
{ | ||
"name":"% Free Space", | ||
"rename":"Free_Space" | ||
} | ||
], | ||
"resources": [ | ||
"*" | ||
], | ||
"metrics_collection_interval": 1 | ||
}, | ||
"PhysicalDisk": { | ||
"measurement": [ | ||
{ | ||
"name":"% Disk Time", | ||
"rename": "Disk_Time" | ||
}, | ||
{ | ||
"name":"Disk Write Bytes/sec", | ||
"rename": "Write_Bytes_Per_Sec" | ||
}, | ||
{ | ||
"name":"Disk Read Bytes/sec", | ||
"rename": "Read_Bytes_Per_Sec" | ||
}, | ||
{ | ||
"name":"Disk Writes/sec", | ||
"rename": "Write_Per_Sec" | ||
}, | ||
{ | ||
"name":"Disk Reads/sec", | ||
"rename": "Disk_Read_Per_Sec" | ||
} | ||
], | ||
"resources": [ | ||
"*" | ||
], | ||
"metrics_collection_interval": 1 | ||
}, | ||
"Network Interface": { | ||
"measurement": [ | ||
{ | ||
"name":"Bytes Sent/sec", | ||
"rename": "Bytes_Sent_Per_Sec" | ||
}, | ||
{ | ||
"name":"Bytes Received/sec", | ||
"rename": "Bytes_Received_Per_Sec" | ||
}, | ||
{ | ||
"name":"Packets Sent/sec", | ||
"rename": "Packets_Sent_Per_Sec" | ||
}, | ||
{ | ||
"name":"Packets Received/sec", | ||
"rename": "Packets_Received_Per_Sec" | ||
} | ||
], | ||
"resources": [ | ||
"*" | ||
], | ||
"metrics_collection_interval": 1 | ||
}, | ||
"Memory": { | ||
"measurement": [ | ||
{ | ||
"name": "Available Bytes", | ||
"rename": "Available_Bytes" | ||
}, | ||
{ | ||
"name":"Cache Faults/sec", | ||
"rename": "Cache_Faults_Per_Sec" | ||
}, | ||
{ | ||
"name":"Page Faults/sec", | ||
"rename": "Page_Faults_Per_sec" | ||
}, | ||
{ | ||
"name":"Pages/sec", | ||
"rename":"Page_Per_Sec" | ||
} | ||
], | ||
"metrics_collection_interval": 1 | ||
}, | ||
"System": { | ||
"measurement": [ | ||
{ | ||
"name": "Processor Queue Length", | ||
"rename": "Processor_Queue_Length" | ||
} | ||
], | ||
"metrics_collection_interval": 1 | ||
}, | ||
"TCPv4": { | ||
"measurement": [ | ||
{ | ||
"name": "Connections Established", | ||
"rename": "Connections_Established" | ||
} | ||
], | ||
"metrics_collection_interval": 1 | ||
}, | ||
"TCPv6": { | ||
"measurement": [ | ||
{ | ||
"name": "Connections Established", | ||
"rename": "Connections_Established" | ||
} | ||
], | ||
"metrics_collection_interval": 1 | ||
}, | ||
"procstat": [ | ||
{ | ||
"exe": "amazon-cloudwatch-agent", | ||
"measurement": [ | ||
"cpu_usage", | ||
"memory_rss" | ||
], | ||
"metrics_collection_interval": 1 | ||
} | ||
] | ||
}, | ||
"append_dimensions": { | ||
"InstanceId": "${aws:InstanceId}" | ||
}, | ||
"force_flush_interval": 30 | ||
}, | ||
"logs": { | ||
"logs_collected": { | ||
"windows_events": { | ||
"collect_list": [ | ||
{ | ||
"event_name": "Security", | ||
"event_levels": [ | ||
"INFORMATION", | ||
"WARNING", | ||
"ERROR", | ||
"CRITICAL", | ||
"VERBOSE" | ||
], | ||
"log_group_name": "{instance_id}", | ||
"log_stream_name": "SecurityEvent" | ||
}, | ||
{ | ||
"event_name": "System", | ||
"event_levels": [ | ||
"INFORMATION", | ||
"WARNING", | ||
"ERROR", | ||
"CRITICAL", | ||
"VERBOSE" | ||
], | ||
"log_group_name": "{instance_id}", | ||
"log_stream_name": "System" | ||
}, | ||
{ | ||
"event_name": "Application", | ||
"event_levels": [ | ||
"INFORMATION", | ||
"WARNING", | ||
"ERROR", | ||
"CRITICAL", | ||
"VERBOSE" | ||
], | ||
"log_group_name": "{instance_id}", | ||
"log_stream_name": "Application" | ||
} | ||
] | ||
}, | ||
|
||
"files": { | ||
"collect_list": [ | ||
{ | ||
"file_path": "C:/Users/Administrator/AppData/Local/Temp/test1.log", | ||
"log_group_name": "{instance_id}", | ||
"log_stream_name": "test1.log", | ||
"timezone": "UTC" | ||
} | ||
] | ||
} | ||
}, | ||
"force_flush_interval": 5 | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Since this is an exception case where we only need to test starting the agent with ssm commands, I think it is fine to only run on a single os.
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 is a sanity test the agent can start and get metrics.