From 0c50f1d4f2f927184be39f6e32bf4840310a1568 Mon Sep 17 00:00:00 2001 From: Mitali Salvi Date: Wed, 11 Oct 2023 13:58:54 -0400 Subject: [PATCH] Adding else condition for CloudWatchMetrics instead of hardcoded list --- exporter/awsemfexporter/emf_exporter.go | 2 +- exporter/awsemfexporter/metric_translator.go | 34 ++++---------------- 2 files changed, 8 insertions(+), 28 deletions(-) diff --git a/exporter/awsemfexporter/emf_exporter.go b/exporter/awsemfexporter/emf_exporter.go index 7b1c13e599da..fbea133a9b09 100644 --- a/exporter/awsemfexporter/emf_exporter.go +++ b/exporter/awsemfexporter/emf_exporter.go @@ -110,7 +110,7 @@ func (emf *emfExporter) pushMetricsData(_ context.Context, md pmetric.Metrics) e if emf.config.EnhancedContainerInsights && (putLogEvent != nil && putLogEvent.InputLogEvent != nil && putLogEvent.InputLogEvent.Message != nil) && *putLogEvent.InputLogEvent.Message == "" { - emf.config.logger.Info("Dropping Prometheus job instance metrics log for EnhancedContainerInsights") + emf.config.logger.Debug("Dropping empty putLogEvents for EnhancedContainerInsights") continue } if err != nil { diff --git a/exporter/awsemfexporter/metric_translator.go b/exporter/awsemfexporter/metric_translator.go index 55787ebaaf98..8dec71bb46b6 100644 --- a/exporter/awsemfexporter/metric_translator.go +++ b/exporter/awsemfexporter/metric_translator.go @@ -31,15 +31,6 @@ const ( fieldPrometheusMetricType = "prom_metric_type" ) -// Prometheus instance availability monitoring metrics - https://prometheus.io/docs/concepts/jobs_instances -var prometheusInstanceScrapeMetrics = map[string]struct{}{ - "up": {}, - "scrape_duration_seconds": {}, - "scrape_samples_post_metric_relabeling": {}, - "scrape_samples_scraped": {}, - "scrape_series_added": {}, -} - var fieldPrometheusTypes = map[pmetric.MetricType]string{ pmetric.MetricTypeEmpty: "", pmetric.MetricTypeGauge: "gauge", @@ -367,24 +358,6 @@ func translateCWMetricToEMF(cWMetric *cWMetrics, config *Config) (*cwlogs.Event, // convert CWMetric into map format for compatible with PLE input fieldMap := cWMetric.fields - for key := range fieldMap { - if _, ok := prometheusInstanceScrapeMetrics[key]; ok { - config.logger.Debug( - "Detected prometheus job instance metrics", - zap.Any("key", key), - zap.Any("value", fieldMap[key]), - ) - // Return empty logEvent for prometheusInstanceScrapeMetrics if EnhancedContainerInsights is enabled - if config.EnhancedContainerInsights { - logEvent := cwlogs.NewEvent( - int64(0), - "", - ) - return logEvent, nil - } - } - } - // restore the json objects that are stored as string in attributes for _, key := range config.ParseJSONEncodedAttributeValues { if fieldMap[key] == nil { @@ -458,6 +431,13 @@ func translateCWMetricToEMF(cWMetric *cWMetrics, config *Config) (*cwlogs.Event, */ fieldMap["CloudWatchMetrics"] = cWMetric.measurements } + } else if len(cWMetric.measurements) < 1 && config.EnhancedContainerInsights { + // Return empty logEvent if requests does not contain metrics when EnhancedContainerInsights is enabled + logEvent := cwlogs.NewEvent( + int64(0), + "", + ) + return logEvent, nil } pleMsg, err := json.Marshal(fieldMap)