From b63ec240653afb35d5691f2bfe41842191613229 Mon Sep 17 00:00:00 2001 From: Musa <165414028+musa-asad@users.noreply.github.com> Date: Tue, 23 Jul 2024 16:55:12 -0400 Subject: [PATCH] Drop original metrics support added for all metrics. (#1206) --- translator/config/schema.json | 18 ++++++++++++++++++ .../sampleConfig/complete_linux_config.json | 10 ++++++++-- .../sampleConfig/complete_linux_config.yaml | 2 ++ .../awscloudwatch/testdata/config.json | 13 +++++++++++++ .../otel/exporter/awscloudwatch/translator.go | 15 +++++++++++++++ .../exporter/awscloudwatch/translator_test.go | 6 ++++++ 6 files changed, 62 insertions(+), 2 deletions(-) diff --git a/translator/config/schema.json b/translator/config/schema.json index 68505ed585..955e42a3d3 100644 --- a/translator/config/schema.json +++ b/translator/config/schema.json @@ -230,6 +230,12 @@ }, "metrics_aggregation_interval": { "$ref": "#/definitions/timeIntervalWithZeroDefinition" + }, + "drop_original_metrics": { + "type": "array", + "items": { "type": "string" }, + "minItems": 1, + "uniqueItems": true } }, "additionalProperties": false @@ -337,6 +343,12 @@ "type": "string", "minLength": 1, "maxLength": 255 + }, + "drop_original_metrics": { + "type": "array", + "items": { "type": "string" }, + "minItems": 1, + "uniqueItems": true } }, "additionalProperties": false @@ -471,6 +483,12 @@ }, "append_dimensions": { "$ref": "#/definitions/generalAppendDimensionsDefinition" + }, + "drop_original_metrics": { + "type": "array", + "items": { "type": "string" }, + "minItems": 1, + "uniqueItems": true } }, "additionalProperties": false diff --git a/translator/tocwconfig/sampleConfig/complete_linux_config.json b/translator/tocwconfig/sampleConfig/complete_linux_config.json index 699f2f31d3..1b7260fbc7 100755 --- a/translator/tocwconfig/sampleConfig/complete_linux_config.json +++ b/translator/tocwconfig/sampleConfig/complete_linux_config.json @@ -82,7 +82,10 @@ "collectd_typesdb": [ "/usr/share/collectd/types.db" ], - "metrics_aggregation_interval": 60 + "metrics_aggregation_interval": 60, + "drop_original_metrics": [ + "collectd_drop" + ] }, "cpu": { "resources": [ @@ -155,7 +158,10 @@ "service_address": ":8125", "metrics_collection_interval": 10, "metrics_aggregation_interval": 60, - "metric_separator": "_" + "metric_separator": "_", + "drop_original_metrics": [ + "statsd_drop" + ] }, "swap": { "measurement": [ diff --git a/translator/tocwconfig/sampleConfig/complete_linux_config.yaml b/translator/tocwconfig/sampleConfig/complete_linux_config.yaml index 4e12ee827d..1e4bae98a2 100644 --- a/translator/tocwconfig/sampleConfig/complete_linux_config.yaml +++ b/translator/tocwconfig/sampleConfig/complete_linux_config.yaml @@ -2,7 +2,9 @@ exporters: awscloudwatch: drop_original_metrics: CPU_USAGE_IDLE: true + collectd_drop: true cpu_time_active: true + statsd_drop: true endpoint_override: https://monitoring-fips.us-west-2.amazonaws.com force_flush_interval: 1m0s max_datums_per_call: 1000 diff --git a/translator/translate/otel/exporter/awscloudwatch/testdata/config.json b/translator/translate/otel/exporter/awscloudwatch/testdata/config.json index bb6aa7f3cc..da68768dd6 100644 --- a/translator/translate/otel/exporter/awscloudwatch/testdata/config.json +++ b/translator/translate/otel/exporter/awscloudwatch/testdata/config.json @@ -1,6 +1,9 @@ { "metrics": { "metrics_collected": { + "collectd": { + "drop_original_metrics": ["collectd_drop"] + }, "cpu": { "drop_original_metrics": ["cpu_usage_idle", "time_active"], "measurement": [ @@ -19,8 +22,18 @@ ] }, "disk": {}, + "ethtool": { + "metrics_include": [ + "rx_packets", + "tx_packets" + ], + "drop_original_metrics": ["tx_packets"] + }, "nvidia_gpu": { "drop_original_metrics": ["utilization_gpu", "temperature_gpu"] + }, + "statsd": { + "drop_original_metrics": ["statsd_drop"] } }, "aggregation_dimensions" : [["ImageId"], ["InstanceId", "InstanceType"], ["d1"], []], diff --git a/translator/translate/otel/exporter/awscloudwatch/translator.go b/translator/translate/otel/exporter/awscloudwatch/translator.go index b8291623b9..736b2aeffd 100644 --- a/translator/translate/otel/exporter/awscloudwatch/translator.go +++ b/translator/translate/otel/exporter/awscloudwatch/translator.go @@ -34,6 +34,13 @@ type translator struct { var _ common.Translator[component.Config] = (*translator)(nil) +// Map to support dropping metrics without measurement. +var toDropMap = map[string]struct{}{ + "collectd": {}, + "statsd": {}, + "ethtool": {}, +} + func NewTranslator() common.Translator[component.Config] { return NewTranslatorWithName("") } @@ -164,6 +171,14 @@ func getDropOriginalMetrics(conf *confmap.Conf) map[string]bool { */ if dropMetrics := common.GetArray[any](conf, dropOriginalCfgKey); dropMetrics != nil { for _, dropMetric := range dropMetrics { + if _, in := toDropMap[category]; in { + dropMetric, ok := dropMetric.(string) + if ok { + dropOriginalMetrics[dropMetric] = true + } + continue + } + measurements := common.GetArray[any](conf, measurementCfgKey) if measurements == nil { continue diff --git a/translator/translate/otel/exporter/awscloudwatch/translator_test.go b/translator/translate/otel/exporter/awscloudwatch/translator_test.go index 62924e995b..a4df903f47 100644 --- a/translator/translate/otel/exporter/awscloudwatch/translator_test.go +++ b/translator/translate/otel/exporter/awscloudwatch/translator_test.go @@ -118,7 +118,10 @@ func TestTranslator(t *testing.T) { RollupDimensions: [][]string{{"ImageId"}, {"InstanceId", "InstanceType"}, {"d1"}, {}}, DropOriginalConfigs: map[string]bool{ "CPU_USAGE_IDLE": true, + "collectd_drop": true, "cpu_time_active": true, + "statsd_drop": true, + "tx_packets": true, }, }, wantWindows: &cloudwatch.Config{ @@ -131,7 +134,10 @@ func TestTranslator(t *testing.T) { RollupDimensions: [][]string{{"ImageId"}, {"InstanceId", "InstanceType"}, {"d1"}, {}}, DropOriginalConfigs: map[string]bool{ "CPU_USAGE_IDLE": true, + "collectd_drop": true, "cpu time_active": true, + "statsd_drop": true, + "tx_packets": true, }, }, },