aws / aws/amazon-cloudwatch-agent
Remove --sample-config flag from amazon-cloudwatch-agent executable
- Dominant language
- Go
- Stars
- 550
- Forks
- 271
- Avg merge
- 1d 21h
- Merged PRs (30d)
- 13
Description
The [--sample-config flag](https://github.com/aws/amazon-cloudwatch-agent/blob/master/cmd/amazon-cloudwatch-agent/amazon-cloudwatch-agent.go#L66) is useless, it prints out a TOML config which is not relevant for a CWAgent customer. Not to mention it panics because it tries to print the config for one of the container processors, which expects `/rootfs` to exist - see below. The existence of this flag is confusing to customers because they might think it could show them a sample JSON config.
This flag should be removed, along with the [--section-filter](https://github.com/aws/amazon-cloudwatch-agent/blob/master/cmd/amazon-cloudwatch-agent/amazon-cloudwatch-agent.go#L69), [--input-filter](https://github.com/aws/amazon-cloudwatch-agent/blob/master/cmd/amazon-cloudwatch-agent/amazon-cloudwatch-agent.go#L71), [--output-filter](https://github.com/aws/amazon-cloudwatch-agent/blob/master/cmd/amazon-cloudwatch-agent/amazon-cloudwatch-agent.go#L75), [--aggregator-filter](https://github.com/aws/amazon-cloudwatch-agent/blob/master/cmd/amazon-cloudwatch-agent/amazon-cloudwatch-agent.go#L79), and [--processor-filter](https://github.com/aws/amazon-cloudwatch-agent/blob/master/cmd/amazon-cloudwatch-agent/amazon-cloudwatch-agent.go#L81) flags which are only used in conjunction with --sample-config.
Panic output:
```
2022-10-19T13:56:51Z E! /rootfs/proc does not exist
panic: E! /rootfs/proc does not exist
goroutine 1 [running]:
log.Panic({0xc0009bf738?, 0xc00050f500?, 0x3ad4dc0?})
/usr/lib/golang/src/log/log.go:385 +0x65
github.com/aws/amazon-cloudwatch-agent/internal/containerinsightscommon.NewNodeCapacity()
/builddir/build/BUILD/amazon-cloudwatch-agent-1.247354.0b251981/amazon-cloudwatch-agent/internal/containerinsightscommon/nodeCapacity.go:21 +0x7c
github.com/aws/amazon-cloudwatch-agent/plugins/processors/ecsdecorator.init.0.func1()
/builddir/build/BUILD/amazon-cloudwatch-agent-1.247354.0b251981/amazon-cloudwatch-agent/plugins/processors/ecsdecorator/ecsdecorator.go:166 +0x19
github.com/influxdata/telegraf/plugins/processors.upgradeToStreamingProcessor.func1()
/builddir/build/BUILD/amazon-cloudwatch-agent-1.247354.0b251981/amazon-cloudwatch-agent/vendor/github.com/influxdata/telegraf/plugins/processors/registry.go:24 +0x1d
github.com/influxdata/telegraf/config.printFilteredProcessors({0xc0006da180, 0x5, 0x8?}, 0x1?)
/builddir/build/BUILD/amazon-cloudwatch-agent-1.247354.0b251981/amazon-cloudwatch-agent/vendor/github.com/influxdata/telegraf/config/config.go:577 +0x266
github.com/influxdata/telegraf/config.PrintSampleConfig({0xc0009bfcf0, 0x0, 0x0}, {0x560d170?, 0x0, 0x0}, {0x560d170?, 0x0, 0x0}, {0xc0009bfcf0, ...}, ...)
/builddir/build/BUILD/amazon-cloudwatch-agent-1.247354.0b251981/amazon-cloudwatch-agent/vendor/github.com/influxdata/telegraf/config/config.go:519 +0x6a5
main.main()
/builddir/build/BUILD/amazon-cloudwatch-agent-1.247354.0b251981/amazon-cloudwatch-agent/cmd/amazon-cloudwatch-agent/amazon-cloudwatch-agent.go:473 +0xb9a
```
Contributor guide
Research direction
Start in cmd/amazon-cloudwatch-agent/amazon-cloudwatch-agent.go, where --sample-config and the related filter flags are defined and handled. Trace their references and remove the flag handling so the executable no longer exposes these options or reaches the panicking sample-configuration path. Done means the obsolete flags and their uses are gone without affecting normal agent startup.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 62/100