Skip to content

Commit

Permalink
Adding else condition for CloudWatchMetrics instead of hardcoded list
Browse files Browse the repository at this point in the history
  • Loading branch information
mitali-salvi committed Oct 11, 2023
1 parent 5b046e0 commit 0c50f1d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 28 deletions.
2 changes: 1 addition & 1 deletion exporter/awsemfexporter/emf_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
34 changes: 7 additions & 27 deletions exporter/awsemfexporter/metric_translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 0c50f1d

Please sign in to comment.