Exits with status code 0 when configuration JSON is malformed
Describe the bug
With malformed configuration JSON file, the command amazon-cloudwatch-agent-ctl exits as if it succeeds.
Steps to reproduce
- create a configuration file with broken content, which causes JSON parse error
- execute
/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -s -c file:/opt/aws/amazon-cloudwatch-agent/bin/config.jsonas a root user
What did you expect to see?
- the command
amazon-cloudwatch-agent-ctlexits with non-zero status code - the command
amazon-cloudwatch-agent-ctlDOES NOT sayConfiguration validation succeeded
What did you see instead?
- the command
amazon-cloudwatch-agent-ctlexits with 0 status code - the command
amazon-cloudwatch-agent-ctlDOES sayConfiguration validation succeeded
What version did you use?
Version: 1.300031.0b313
What config did you use?
Config: any file with JSON parse error. For example, a file with only single character a will work for reproduction.
Environment OS: Ubuntu 22.04 on EC2
Additional context console log
root@ip-172-31-21-121:/opt/aws/amazon-cloudwatch-agent/bin# /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -s -c file:/opt/aws/amazon-cloudwatch-agent/bin/config.json
****** processing amazon-cloudwatch-agent ******
I! Trying to detect region from ec2 D! [EC2] Found active network interface I! imds retry client will retry 1 timesSuccessfully fetched the config and saved in /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.d/file_config.json.tmp
Start configuration validation...
2023/11/23 11:18:27 Reading json config file path: /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.d/file_config.json.tmp ...
2023/11/23 11:18:27 unable to scan config dir /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.d with error: unable to parse json, error: invalid character 'a' looking for beginning of value
2023/11/23 11:18:27 No json config files found, use the default one
2023/11/23 11:18:27 I! Valid Json input schema.
2023/11/23 11:18:27 D! ec2tagger processor required because append_dimensions is set
2023/11/23 11:18:27 D! pipeline hostDeltaMetrics has no receivers
2023/11/23 11:18:27 Configuration validation first phase succeeded
I! Detecting run_as_user...
I! Trying to detect region from ec2
D! [EC2] Found active network interface
I! imds retry client will retry 1 times
/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent -schematest -config /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.toml
Configuration validation second phase succeeded
Configuration validation succeeded
amazon-cloudwatch-agent has already been stopped
root@ip-172-31-21-121:/opt/aws/amazon-cloudwatch-agent/bin# echo $?
0
root@ip-172-31-21-121:/opt/aws/amazon-cloudwatch-agent/bin# /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -m ec2 -a status
{
"status": "stopped",
"starttime": "",
"configstatus": "configured",
"version": "1.300031.0b313"
}
Hello,
I was able to replicate this issue I will create a ticket in our backlog to tackle this issue.
We are also not able to get the SAP Netwear metrics using Application Insights.
2024/02/21 18:01:20 Reading json config file path: /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json ... 2024/02/21 18:01:20 Reading json config file path: /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.d/ssm_AmazonCloudWatch-ApplicationInsights-SSMParameterForNWS4 ... 2024/02/21 18:01:20 Reading json config file path: /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.d/ssm_AmazonCloudWatch-ApplicationInsights-SSMParameterForNWS4.tmp ... 2024/02/21 18:01:20 I! Valid Json input schema. 2024/02/21 18:01:20 D! ec2tagger processor required because append_dimensions is set 2024/02/21 18:01:20 D! metric decorator required because measurement fields are set 2024/02/21 18:01:20 D! pipeline hostDeltaMetrics has no receivers 2024/02/21 18:01:20 Configuration validation first phase succeeded
Please check this.
still the same and for me: 2024/08/30 11:22:42 D! ec2tagger processor required because append_dimensions is set