aws / amazon-cloudwatch-agent

CloudWatch Agent enables you to collect and export host-level metrics and logs on instances running Linux or Windows server.
MIT License
420 stars 185 forks source link

Additional prop support added for all metrics. #1206

Open musa-asad opened 3 weeks ago

musa-asad commented 3 weeks ago

Description of the issue

Public docs state that the drop_original_metrics feature is supported, but, when we try to run it, the config translation states it isn't allowed: Under path : /metrics/metrics_collected/statsd | Error : Additional property drop_original_metrics is not allowed.

Description of changes

I allow drop_original_metrics for the statsd metric as well as other metrics that didn't have it (collectd and ethtool) and adjusted the CW exporter translator code to allow for this.

License

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Tests

I first replicated the issue and then tried running CWAgent with the following config:

{
    "metrics": {
        "aggregation_dimensions": [
            ["InstanceId"]
        ],
        "metrics_collected": {
            "statsd": {
                "service_address": ":8125",
        "metrics_collection_interval": 10,
                "metrics_aggregation_interval": 50,
        "drop_original_metrics": ["should_drop_24"]
            }
        }
    }
}

The relevant errors are as follows (when we try using drop_original_metrics for all metrics collected):

Under path : /metrics/metrics_collected/ethtool | Error : Additional property drop_original_metrics is not allowed
Under path : /metrics/metrics_collected/collectd | Error : Additional property drop_original_metrics is not allowed
Under path : /metrics/metrics_collected/statsd | Error : Additional property drop_original_metrics is not allowed

After that, I re-ran the configuration and the error didn't persist.

Then, I ran echo "should_drop_24:123|c" | nc -u -w1 127.0.0.1 8125 and echo "should_not_drop_24:123|c" | nc -u -w1 127.0.0.1 8125.

As expected, the should_drop_24 didn't show up in the CW console, but should_not_drop_24 did.

Screenshot 2024-06-24 at 11 55 42 AM

We also see this in the yaml file:

exporters:
    awscloudwatch:
        drop_original_metrics:
            should_drop_24: true

Requirements

Before commit the code, please do the following steps.

  1. Run make fmt and make fmt-sh
  2. Run make lint
github-actions[bot] commented 1 week ago

This PR was marked stale due to lack of activity.

sky333999 commented 1 week ago

Mind adding a screenshot of what the metrics look like in CW console? I would have expected an append_dimensions for the InstanceId so Im curious how it worked without that.