Skip to content

Commit

Permalink
Append pcluster CloudWatch config when CW agent is running
Browse files Browse the repository at this point in the history
Before this commit, pcluster CW config is not loaded when CW agent is running on the custom AMI, causing the lack of logs on CloudWatch.

This commit appends pcluster CW config regardless of whether the CW agent is running. Therefore, CW config in the custom AMI will be preserved in addition to pcluster CW config. If there are conflicting parameters, the parameters in pcluster CW config overwrites the config from custom AMI.

Signed-off-by: Hanwen <[email protected]>
  • Loading branch information
hanwen-cluster committed Aug 6, 2024
1 parent 0aaa259 commit 00187b8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ def package_path
execute "cloudwatch-agent-start" do
user 'root'
timeout 300
command "/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c file:/opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json -s"
not_if "/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a status | grep status | grep running"
command "/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a append-config -m ec2 -c file:/opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json -s"
end unless node['cluster']['cw_logging_enabled'] != 'true' || on_docker?
end
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ def self.configure(chef_run)
is_expected.to run_execute("cloudwatch-agent-start").with(
user: 'root',
timeout: 300,
command: "/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c file:/opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json -s"
command: "/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a append-config -m ec2 -c file:/opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json -s"
)
end
end
Expand Down Expand Up @@ -309,8 +309,12 @@ def self.configure(chef_run)
ConvergeCloudWatch.configure(runner)
end

it 'does not start cloudwatch' do
is_expected.not_to run_execute("cloudwatch-agent-start")
it 'starts cloudwatch agent' do
is_expected.to run_execute("cloudwatch-agent-start").with(
user: 'root',
timeout: 300,
command: "/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a append-config -m ec2 -c file:/opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json -s"
)
end
end
end
Expand Down

0 comments on commit 00187b8

Please sign in to comment.