Skip to content
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

Exits with status code 0 when configuration JSON is malformed #966

Open
motooka opened this issue Nov 23, 2023 · 3 comments
Open

Exits with status code 0 when configuration JSON is malformed #966

motooka opened this issue Nov 23, 2023 · 3 comments

Comments

@motooka
Copy link

motooka commented Nov 23, 2023

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 say Configuration 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 say Configuration 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
Copy link
Contributor

Hello,

I was able to replicate this issue I will create a ticket in our backlog to tackle this issue.

@okankoAMZ okankoAMZ added the status/backlog Backlog label Nov 27, 2023
@Xblade007
Copy link

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.

@oleksandrsv
Copy link

still the same and for me:
2024/08/30 11:22:42 D! ec2tagger processor required because append_dimensions is set

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants