Skip to content

Commit 26b55b3

Browse files
hanwen-clusterhanwen-pcluste
authored andcommitted
Overwrite existing CloudWatch config if merging config fails
`append-config` merges config, but fails when there are conflicting parameters: ``` 2024/08/07 19:45:32 Under path : /metrics/metrics_collected/mem | Error : Different values are specified for mem 2024/08/07 19:45:32 Under path : /metrics/metrics_collected/disk | Error : Different values are specified for disk 2024/08/07 19:45:32 Under path : /metrics/append_dimensions | Error : Different values are specified for append_dimensions 2024/08/07 19:45:32 Under path : /metrics/metrics_collected/mem | Error : Different values are specified for mem 2024/08/07 19:45:32 Under path : /metrics/metrics_collected/disk | Error : Different values are specified for disk 2024/08/07 19:45:32 Under path : /metrics/append_dimensions | Error : Different values are specified for append_dimensions ``` `fetch-config` overwrites config. This commit makes the code to try merging the config first. If it fails, overwrite the config. Signed-off-by: Hanwen <[email protected]>
1 parent 27e12b6 commit 26b55b3

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

cookbooks/aws-parallelcluster-environment/resources/cloudwatch/partial/_cloudwatch_common.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,6 @@ def package_path
175175
execute "cloudwatch-agent-start" do
176176
user 'root'
177177
timeout 300
178-
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"
178+
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 || /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"
179179
end unless node['cluster']['cw_logging_enabled'] != 'true' || on_docker?
180180
end

cookbooks/aws-parallelcluster-environment/spec/unit/resources/cloudwatch_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ def self.configure(chef_run)
255255
is_expected.to run_execute("cloudwatch-agent-start").with(
256256
user: 'root',
257257
timeout: 300,
258-
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"
258+
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 || /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"
259259
)
260260
end
261261
end
@@ -313,7 +313,7 @@ def self.configure(chef_run)
313313
is_expected.to run_execute("cloudwatch-agent-start").with(
314314
user: 'root',
315315
timeout: 300,
316-
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"
316+
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 || /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"
317317
)
318318
end
319319
end

0 commit comments

Comments
 (0)