Skip to content

Commit

Permalink
updating based on comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mitali-salvi committed Oct 11, 2023
1 parent 0c50f1d commit ff86286
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 27 deletions.
11 changes: 5 additions & 6 deletions exporter/awsemfexporter/emf_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,14 @@ func (emf *emfExporter) pushMetricsData(_ context.Context, md pmetric.Metrics) e
for _, groupedMetric := range groupedMetrics {
cWMetric := translateGroupedMetricToCWMetric(groupedMetric, emf.config)
putLogEvent, err := translateCWMetricToEMF(cWMetric, emf.config)
if emf.config.EnhancedContainerInsights && (putLogEvent != nil &&
putLogEvent.InputLogEvent != nil &&
putLogEvent.InputLogEvent.Message != nil) && *putLogEvent.InputLogEvent.Message == "" {
emf.config.logger.Debug("Dropping empty putLogEvents for EnhancedContainerInsights")
continue
}
if err != nil {
return err
}
// Drop a nil putLogEvent for EnhancedContainerInsights
if emf.config.EnhancedContainerInsights && putLogEvent == nil {
emf.config.logger.Debug("Dropping empty putLogEvents for EnhancedContainerInsights")
continue
}
// Currently we only support two options for "OutputDestination".
if strings.EqualFold(outputDestination, outputDestinationStdout) {
if putLogEvent != nil &&
Expand Down
8 changes: 2 additions & 6 deletions exporter/awsemfexporter/metric_translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,12 +432,8 @@ 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
// Return nil if requests does not contain metrics when EnhancedContainerInsights is enabled
return nil, nil
}

pleMsg, err := json.Marshal(fieldMap)
Expand Down
32 changes: 17 additions & 15 deletions exporter/awsemfexporter/metric_translator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ func TestTranslateCWMetricToEMFForEnhancedContainerInsights(t *testing.T) {
EnhancedContainerInsights bool
fields map[string]interface{}
measurements []cWMeasurement
expectedEMFLogEvent string
expectedEMFLogEvent interface{}
}{
"EnhancedContainerInsightsEnabled": {
EnhancedContainerInsights: true,
Expand All @@ -499,7 +499,7 @@ func TestTranslateCWMetricToEMFForEnhancedContainerInsights(t *testing.T) {
"Sources": "[\"apiserver\"]",
},
measurements: nil,
expectedEMFLogEvent: "",
expectedEMFLogEvent: nil,
},
"EnhancedContainerInsightsDisabled": {
EnhancedContainerInsights: false,
Expand Down Expand Up @@ -534,7 +534,9 @@ func TestTranslateCWMetricToEMFForEnhancedContainerInsights(t *testing.T) {
emfLogEvent, err := translateCWMetricToEMF(cloudwatchMetric, config)
require.NoError(t, err)

assert.Equal(t, tc.expectedEMFLogEvent, *emfLogEvent.InputLogEvent.Message)
if tc.expectedEMFLogEvent != nil {
assert.Equal(t, tc.expectedEMFLogEvent, *emfLogEvent.InputLogEvent.Message)
}
})
}

Expand Down Expand Up @@ -1454,22 +1456,22 @@ func TestGroupedMetricToCWMeasurementsWithFilters(t *testing.T) {
MetricNameSelectors: []string{"metric(1|3)"},
},
}, []cWMeasurement{
{
Namespace: namespace,
Dimensions: [][]string{{}},
Metrics: []map[string]string{
{
"Name": "metric1",
"Unit": "Count",
},
{
"Name": "metric3",
"Unit": "Seconds",
},
{
Namespace: namespace,
Dimensions: [][]string{{}},
Metrics: []map[string]string{
{
"Name": "metric1",
"Unit": "Count",
},
{
"Name": "metric3",
"Unit": "Seconds",
},
},
},
},
},
{
"label matchers",
[]*MetricDeclaration{
Expand Down

0 comments on commit ff86286

Please sign in to comment.