Exits with status code 0 when configuration JSON is malformed
motooka opened this issue · 3 comments
motooka commented
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.json
as a root user
What did you expect to see?
- the command
amazon-cloudwatch-agent-ctl
exits with non-zero status code - the command
amazon-cloudwatch-agent-ctl
DOES NOT sayConfiguration validation succeeded
What did you see instead?
- the command
amazon-cloudwatch-agent-ctl
exits with 0 status code - the command
amazon-cloudwatch-agent-ctl
DOES 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"
}
okankoAMZ commented
Hello,
I was able to replicate this issue I will create a ticket in our backlog to tackle this issue.