diff --git a/exporter/awsemfexporter/datapoint.go b/exporter/awsemfexporter/datapoint.go index 4aba2c5bba50..65f01334b994 100644 --- a/exporter/awsemfexporter/datapoint.go +++ b/exporter/awsemfexporter/datapoint.go @@ -81,15 +81,11 @@ type numberDataPointSlice struct { // histogramDataPointSlice is a wrapper for pmetric.HistogramDataPointSlice type histogramDataPointSlice struct { - // Todo:(khanhntd) Calculate delta value for count and sum value with histogram - // https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/18245 deltaMetricMetadata pmetric.HistogramDataPointSlice } type exponentialHistogramDataPointSlice struct { - // TODO: Calculate delta value for count and sum value with exponential histogram - // https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/18245 deltaMetricMetadata pmetric.ExponentialHistogramDataPointSlice } @@ -146,16 +142,40 @@ func (dps numberDataPointSlice) CalculateDeltaDatapoints(i int, instrumentationS } // CalculateDeltaDatapoints retrieves the HistogramDataPoint at the given index. -func (dps histogramDataPointSlice) CalculateDeltaDatapoints(i int, instrumentationScopeName string, _ bool, _ *emfCalculators) ([]dataPoint, bool) { +func (dps histogramDataPointSlice) CalculateDeltaDatapoints(i int, instrumentationScopeName string, _ bool, calculators *emfCalculators) ([]dataPoint, bool) { metric := dps.HistogramDataPointSlice.At(i) labels := createLabels(metric.Attributes(), instrumentationScopeName) timestamp := unixNanoToMilliseconds(metric.Timestamp()) + sum := metric.Sum() + count := metric.Count() + + var datapoints []dataPoint + + if dps.adjustToDelta { + var delta interface{} + mKey := aws.NewKey(dps.deltaMetricMetadata, labels) + delta, retained := calculators.summary.Calculate(mKey, summaryMetricEntry{sum, count}, metric.Timestamp().AsTime()) + + // If a delta to the previous data point could not be computed use the current metric value instead + if !retained && dps.retainInitialValueForDelta { + retained = true + delta = summaryMetricEntry{sum, count} + } + + if !retained { + return datapoints, retained + } + summaryMetricDelta := delta.(summaryMetricEntry) + sum = summaryMetricDelta.sum + count = summaryMetricDelta.count + } + return []dataPoint{{ name: dps.metricName, value: &cWMetricStats{ - Count: metric.Count(), - Sum: metric.Sum(), + Count: count, + Sum: sum, Max: metric.Max(), Min: metric.Min(), }, @@ -350,6 +370,8 @@ func getDataPoints(pmd pmetric.Metric, metadata cWMetricMetadata, logger *zap.Lo } case pmetric.MetricTypeHistogram: metric := pmd.Histogram() + // the prometheus histograms from the container insights should be adjusted for delta + metricMetadata.adjustToDelta = metadata.receiver == containerInsightsReceiver dps = histogramDataPointSlice{ metricMetadata, metric.DataPoints(), @@ -368,7 +390,7 @@ func getDataPoints(pmd pmetric.Metric, metadata cWMetricMetadata, logger *zap.Lo // attribute processor) from resource metrics. If it exists, and equals to prometheus, the sum and count will be // converted. // For more information: https://github.com/open-telemetry/opentelemetry-collector/blob/main/receiver/prometheusreceiver/DESIGN.md#summary - metricMetadata.adjustToDelta = metadata.receiver == prometheusReceiver + metricMetadata.adjustToDelta = metadata.receiver == prometheusReceiver || metadata.receiver == containerInsightsReceiver dps = summaryDataPointSlice{ metricMetadata, metric.DataPoints(), diff --git a/exporter/awsemfexporter/datapoint_test.go b/exporter/awsemfexporter/datapoint_test.go index 03be10da76d2..2c87095dc059 100644 --- a/exporter/awsemfexporter/datapoint_test.go +++ b/exporter/awsemfexporter/datapoint_test.go @@ -383,10 +383,52 @@ func TestCalculateDeltaDatapoints_HistogramDataPointSlice(t *testing.T) { assert.True(t, retained) assert.Equal(t, 1, histogramDatapointSlice.Len()) assert.Equal(t, tc.expectedDatapoint, dps[0]) - }) } +} + +func TestCalculateDeltaDatapoints_HistogramDataPointSlice_Delta(t *testing.T) { + cumulativeDeltaMetricMetadata := generateDeltaMetricMetadata(true, "foo", false) + + histogramDPS := pmetric.NewHistogramDataPointSlice() + histogramDP := histogramDPS.AppendEmpty() + histogramDP.SetCount(uint64(17)) + histogramDP.SetSum(17.13) + histogramDP.SetMin(10) + histogramDP.SetMax(30) + histogramDP.Attributes().PutStr("label1", "value1") + histogramDatapointSlice := histogramDataPointSlice{cumulativeDeltaMetricMetadata, histogramDPS} + emfCalcs := setupEmfCalculators() + defer require.NoError(t, shutdownEmfCalculators(emfCalcs)) + dps, retained := histogramDatapointSlice.CalculateDeltaDatapoints(0, instrLibName, false, emfCalcs) + + assert.False(t, retained) + assert.Equal(t, 1, histogramDatapointSlice.Len()) + assert.Equal(t, 0, len(dps)) + + dps, retained = histogramDatapointSlice.CalculateDeltaDatapoints(0, instrLibName, false, emfCalcs) + assert.True(t, retained) + assert.Equal(t, 1, histogramDatapointSlice.Len()) + assert.Equal(t, dataPoint{ + name: "foo", + value: &cWMetricStats{Sum: 0, Count: 0, Min: 10, Max: 30}, + labels: map[string]string{oTellibDimensionKey: instrLibName, "label1": "value1"}, + }, dps[0]) + + histogramDatapointSlice.HistogramDataPointSlice.At(0).SetCount(uint64(27)) + histogramDatapointSlice.HistogramDataPointSlice.At(0).SetSum(27.27) + histogramDP.SetMin(5) + histogramDP.SetMax(40) + + dps, retained = histogramDatapointSlice.CalculateDeltaDatapoints(0, instrLibName, false, emfCalcs) + assert.True(t, retained) + assert.Equal(t, 1, histogramDatapointSlice.Len()) + assert.Equal(t, dataPoint{ + name: "foo", + value: &cWMetricStats{Sum: 10.14, Count: 10, Min: 5, Max: 40}, + labels: map[string]string{oTellibDimensionKey: instrLibName, "label1": "value1"}, + }, dps[0]) } func TestCalculateDeltaDatapoints_ExponentialHistogramDataPointSlice(t *testing.T) { @@ -600,54 +642,75 @@ func TestCreateLabels(t *testing.T) { func TestGetDataPoints(t *testing.T) { logger := zap.NewNop() - normalDeltraMetricMetadata := generateDeltaMetricMetadata(false, "foo", false) + normalDeltaMetricMetadata := generateDeltaMetricMetadata(false, "foo", false) cumulativeDeltaMetricMetadata := generateDeltaMetricMetadata(true, "foo", false) testCases := []struct { name string - isPrometheusMetrics bool + receiver string metric pmetric.Metrics expectedDatapointSlice dataPoints expectedAttributes map[string]interface{} }{ { name: "Int gauge", - isPrometheusMetrics: false, + receiver: "", metric: generateTestGaugeMetric("foo", intValueType), - expectedDatapointSlice: numberDataPointSlice{normalDeltraMetricMetadata, pmetric.NumberDataPointSlice{}}, + expectedDatapointSlice: numberDataPointSlice{normalDeltaMetricMetadata, pmetric.NumberDataPointSlice{}}, expectedAttributes: map[string]interface{}{"label1": "value1"}, }, { name: "Double sum", - isPrometheusMetrics: false, + receiver: "", metric: generateTestSumMetric("foo", doubleValueType), expectedDatapointSlice: numberDataPointSlice{cumulativeDeltaMetricMetadata, pmetric.NumberDataPointSlice{}}, expectedAttributes: map[string]interface{}{"label1": "value1"}, }, { name: "Histogram", - isPrometheusMetrics: false, + receiver: "", + metric: generateTestHistogramMetric("foo"), + expectedDatapointSlice: histogramDataPointSlice{normalDeltaMetricMetadata, pmetric.HistogramDataPointSlice{}}, + expectedAttributes: map[string]interface{}{"label1": "value1"}, + }, + { + name: "Histogram from ContainerInsights", + receiver: containerInsightsReceiver, metric: generateTestHistogramMetric("foo"), expectedDatapointSlice: histogramDataPointSlice{cumulativeDeltaMetricMetadata, pmetric.HistogramDataPointSlice{}}, expectedAttributes: map[string]interface{}{"label1": "value1"}, }, + { + name: "Histogram from Prometheus", + receiver: prometheusReceiver, + metric: generateTestHistogramMetric("foo"), + expectedDatapointSlice: histogramDataPointSlice{normalDeltaMetricMetadata, pmetric.HistogramDataPointSlice{}}, + expectedAttributes: map[string]interface{}{"label1": "value1"}, + }, { name: "ExponentialHistogram", - isPrometheusMetrics: false, + receiver: "", metric: generateTestExponentialHistogramMetric("foo"), - expectedDatapointSlice: exponentialHistogramDataPointSlice{cumulativeDeltaMetricMetadata, pmetric.ExponentialHistogramDataPointSlice{}}, + expectedDatapointSlice: exponentialHistogramDataPointSlice{normalDeltaMetricMetadata, pmetric.ExponentialHistogramDataPointSlice{}}, expectedAttributes: map[string]interface{}{"label1": "value1"}, }, { name: "Summary from SDK", - isPrometheusMetrics: false, + receiver: "", metric: generateTestSummaryMetric("foo"), - expectedDatapointSlice: summaryDataPointSlice{normalDeltraMetricMetadata, pmetric.SummaryDataPointSlice{}}, + expectedDatapointSlice: summaryDataPointSlice{normalDeltaMetricMetadata, pmetric.SummaryDataPointSlice{}}, expectedAttributes: map[string]interface{}{"label1": "value1"}, }, { name: "Summary from Prometheus", - isPrometheusMetrics: true, + receiver: prometheusReceiver, + metric: generateTestSummaryMetric("foo"), + expectedDatapointSlice: summaryDataPointSlice{cumulativeDeltaMetricMetadata, pmetric.SummaryDataPointSlice{}}, + expectedAttributes: map[string]interface{}{"label1": "value1"}, + }, + { + name: "Summary from ContainerInsights", + receiver: containerInsightsReceiver, metric: generateTestSummaryMetric("foo"), expectedDatapointSlice: summaryDataPointSlice{cumulativeDeltaMetricMetadata, pmetric.SummaryDataPointSlice{}}, expectedAttributes: map[string]interface{}{"label1": "value1"}, @@ -661,13 +724,7 @@ func TestGetDataPoints(t *testing.T) { metadata := generateTestMetricMetadata("namespace", time.Now().UnixNano()/int64(time.Millisecond), "log-group", "log-stream", "cloudwatch-otel", metric.Type()) t.Run(tc.name, func(t *testing.T) { - - if tc.isPrometheusMetrics { - metadata.receiver = prometheusReceiver - } else { - metadata.receiver = "" - } - + metadata.receiver = tc.receiver dps := getDataPoints(metric, metadata, logger) assert.NotNil(t, dps) assert.Equal(t, reflect.TypeOf(tc.expectedDatapointSlice), reflect.TypeOf(dps)) @@ -675,6 +732,7 @@ func TestGetDataPoints(t *testing.T) { case numberDataPointSlice: expectedDPS := tc.expectedDatapointSlice.(numberDataPointSlice) assert.Equal(t, expectedDPS.deltaMetricMetadata, convertedDPS.deltaMetricMetadata) + assert.Equal(t, expectedDPS.adjustToDelta, convertedDPS.adjustToDelta) assert.Equal(t, 1, convertedDPS.Len()) dp := convertedDPS.NumberDataPointSlice.At(0) switch dp.ValueType() { @@ -685,6 +743,8 @@ func TestGetDataPoints(t *testing.T) { } assert.Equal(t, tc.expectedAttributes, dp.Attributes().AsRaw()) case histogramDataPointSlice: + expectedDPS := tc.expectedDatapointSlice.(histogramDataPointSlice) + assert.Equal(t, expectedDPS.adjustToDelta, convertedDPS.adjustToDelta) assert.Equal(t, 1, convertedDPS.Len()) dp := convertedDPS.HistogramDataPointSlice.At(0) assert.Equal(t, 35.0, dp.Sum()) @@ -692,6 +752,8 @@ func TestGetDataPoints(t *testing.T) { assert.Equal(t, []float64{0, 10}, dp.ExplicitBounds().AsRaw()) assert.Equal(t, tc.expectedAttributes, dp.Attributes().AsRaw()) case exponentialHistogramDataPointSlice: + expectedDPS := tc.expectedDatapointSlice.(exponentialHistogramDataPointSlice) + assert.Equal(t, expectedDPS.adjustToDelta, convertedDPS.adjustToDelta) assert.Equal(t, 1, convertedDPS.Len()) dp := convertedDPS.ExponentialHistogramDataPointSlice.At(0) assert.Equal(t, float64(0), dp.Sum()) @@ -703,6 +765,7 @@ func TestGetDataPoints(t *testing.T) { case summaryDataPointSlice: expectedDPS := tc.expectedDatapointSlice.(summaryDataPointSlice) assert.Equal(t, expectedDPS.deltaMetricMetadata, convertedDPS.deltaMetricMetadata) + assert.Equal(t, expectedDPS.adjustToDelta, convertedDPS.adjustToDelta) assert.Equal(t, 1, convertedDPS.Len()) dp := convertedDPS.SummaryDataPointSlice.At(0) assert.Equal(t, 15.0, dp.Sum()) diff --git a/exporter/awsemfexporter/metric_translator.go b/exporter/awsemfexporter/metric_translator.go index ea795bd2a3ef..d2128c196f52 100644 --- a/exporter/awsemfexporter/metric_translator.go +++ b/exporter/awsemfexporter/metric_translator.go @@ -7,6 +7,7 @@ import ( "encoding/json" "fmt" "reflect" + "strings" "time" "go.opentelemetry.io/collector/pdata/pmetric" @@ -27,6 +28,7 @@ const ( singleDimensionRollupOnly = "SingleDimensionRollupOnly" prometheusReceiver = "prometheus" + containerInsightsReceiver = "awscontainerinsight" attributeReceiver = "receiver" fieldPrometheusMetricType = "prom_metric_type" ) @@ -124,6 +126,14 @@ func (mt metricTranslator) translateOTelToGroupedMetric(rm pmetric.ResourceMetri if receiver, ok := rm.Resource().Attributes().Get(attributeReceiver); ok { metricReceiver = receiver.Str() } + + if serviceName, ok := rm.Resource().Attributes().Get("service.name"); ok { + if strings.HasPrefix(serviceName.Str(), "containerInsightsKubeAPIServerScraper") { + // the prometheus metrics that come from the container insight receiver need to be clearly tagged as coming from container insights + metricReceiver = containerInsightsReceiver + } + } + for j := 0; j < ilms.Len(); j++ { ilm := ilms.At(j) if ilm.Scope().Name() != "" { diff --git a/exporter/awsemfexporter/metric_translator_test.go b/exporter/awsemfexporter/metric_translator_test.go index 5e5b7b3997be..92aec3885a85 100644 --- a/exporter/awsemfexporter/metric_translator_test.go +++ b/exporter/awsemfexporter/metric_translator_test.go @@ -5,6 +5,7 @@ package awsemfexporter import ( "fmt" + "math" "reflect" "sort" "testing" @@ -22,7 +23,13 @@ import ( "github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal/occonventions" ) +const defaultNumberOfTestMetrics = 3 + func createTestResourceMetrics() pmetric.ResourceMetrics { + return createTestResourceMetricsHelper(defaultNumberOfTestMetrics) +} + +func createTestResourceMetricsHelper(numMetrics int) pmetric.ResourceMetrics { rm := pmetric.NewResourceMetrics() rm.Resource().Attributes().PutStr(occonventions.AttributeExporterVersion, "SomeVersion") rm.Resource().Attributes().PutStr(conventions.AttributeServiceName, "myServiceName") @@ -79,7 +86,7 @@ func createTestResourceMetrics() pmetric.ResourceMetrics { q2.SetQuantile(1) q2.SetValue(5) - for i := 0; i < 2; i++ { + for i := 1; i < numMetrics; i++ { m = sm.Metrics().AppendEmpty() m.SetName("spanCounter") m.SetDescription("Counting all the spans") @@ -268,6 +275,10 @@ func TestTranslateOtToGroupedMetric(t *testing.T) { noNamespaceMetric.Resource().Attributes().Remove(conventions.AttributeServiceNamespace) noNamespaceMetric.Resource().Attributes().Remove(conventions.AttributeServiceName) + // need to have 1 more metric than the default because the first is not going to be retained because it is a delta metric + containerInsightMetric := createTestResourceMetricsHelper(defaultNumberOfTestMetrics + 1) + containerInsightMetric.Resource().Attributes().PutStr(conventions.AttributeServiceName, "containerInsightsKubeAPIServerScraper") + counterSumMetrics := map[string]*metricInfo{ "spanCounter": { value: float64(1), @@ -304,6 +315,7 @@ func TestTranslateOtToGroupedMetric(t *testing.T) { counterLabels map[string]string timerLabels map[string]string expectedNamespace string + expectedReceiver string }{ { "w/ instrumentation library and namespace", @@ -318,6 +330,7 @@ func TestTranslateOtToGroupedMetric(t *testing.T) { "spanName": "testSpan", }, "myServiceNS/myServiceName", + "prometheus", }, { "w/o instrumentation library, w/ namespace", @@ -330,6 +343,7 @@ func TestTranslateOtToGroupedMetric(t *testing.T) { "spanName": "testSpan", }, "myServiceNS/myServiceName", + prometheusReceiver, }, { "w/o instrumentation library and namespace", @@ -342,20 +356,43 @@ func TestTranslateOtToGroupedMetric(t *testing.T) { "spanName": "testSpan", }, defaultNamespace, + prometheusReceiver, + }, + { + "container insights receiver", + containerInsightMetric, + map[string]string{ + "isItAnError": "false", + "spanName": "testSpan", + }, + map[string]string{ + (oTellibDimensionKey): "cloudwatch-lib", + "spanName": "testSpan", + }, + "myServiceNS/containerInsightsKubeAPIServerScraper", + containerInsightsReceiver, }, } for _, tc := range testCases { t.Run(tc.testName, func(t *testing.T) { - groupedMetrics := make(map[interface{}]*groupedMetric) err := translator.translateOTelToGroupedMetric(tc.metric, groupedMetrics, config) assert.Nil(t, err) assert.NotNil(t, groupedMetrics) - assert.Equal(t, 3, len(groupedMetrics)) + assert.Equal(t, defaultNumberOfTestMetrics, len(groupedMetrics)) for _, v := range groupedMetrics { assert.Equal(t, tc.expectedNamespace, v.metadata.namespace) + assert.Equal(t, tc.expectedReceiver, v.metadata.receiver) + + for _, metric := range v.metrics { + if mv, ok := metric.value.(float64); ok { + // round the metrics, the floats can get off by a very small amount + metric.value = math.Round(mv*100000) / 100000 + } + } + switch { case v.metadata.metricDataType == pmetric.MetricTypeSum: assert.Equal(t, 2, len(v.metrics)) @@ -1456,22 +1493,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{ diff --git a/receiver/awscontainerinsightreceiver/internal/k8sapiserver/prometheus_scraper.go b/receiver/awscontainerinsightreceiver/internal/k8sapiserver/prometheus_scraper.go index 83c3500cc9c7..483a9357388d 100644 --- a/receiver/awscontainerinsightreceiver/internal/k8sapiserver/prometheus_scraper.go +++ b/receiver/awscontainerinsightreceiver/internal/k8sapiserver/prometheus_scraper.go @@ -28,6 +28,8 @@ import ( const ( caFile = "/var/run/secrets/kubernetes.io/serviceaccount/ca.crt" collectionInterval = 60 * time.Second + // needs to start with "containerInsightsKubeAPIServerScraper" for histogram deltas in the emf exporter + jobName = "containerInsightsKubeAPIServerScraper" ) var ( @@ -45,9 +47,9 @@ var ( "^apiserver_requested_deprecated_apis$", "^apiserver_storage_list_duration_seconds_(bucket|sum|count)$", "^apiserver_storage_objects$", - "^apiserver_storage_db_total_size_in_bytes_(bucket|sum|count)$", - "^apiserver_storage_size_bytes_(bucket|sum|count)$", - "^etcd_db_total_size_in_bytes_(bucket|sum|count)$", + "^apiserver_storage_db_total_size_in_bytes$", + "^apiserver_storage_size_bytes$", + "^etcd_db_total_size_in_bytes$", "^etcd_request_duration_seconds_(bucket|sum|count)$", "^rest_client_request_duration_seconds_(bucket|sum|count)$", "^rest_client_requests_total$", @@ -104,7 +106,7 @@ func NewPrometheusScraper(opts PrometheusScraperOpts) (*PrometheusScraper, error }, ScrapeInterval: model.Duration(collectionInterval), ScrapeTimeout: model.Duration(collectionInterval), - JobName: fmt.Sprintf("%s/%s", "containerInsightsKubeAPIServerScraper", opts.Endpoint), + JobName: fmt.Sprintf("%s/%s", jobName, opts.Endpoint), HonorTimestamps: true, Scheme: "https", MetricsPath: "/metrics", diff --git a/receiver/awscontainerinsightreceiver/internal/k8sapiserver/prometheus_scraper_test.go b/receiver/awscontainerinsightreceiver/internal/k8sapiserver/prometheus_scraper_test.go index 540ceb976db8..33dc4ba57071 100644 --- a/receiver/awscontainerinsightreceiver/internal/k8sapiserver/prometheus_scraper_test.go +++ b/receiver/awscontainerinsightreceiver/internal/k8sapiserver/prometheus_scraper_test.go @@ -198,7 +198,7 @@ func TestNewPrometheusScraperEndToEnd(t *testing.T) { }, ScrapeInterval: cfg.ScrapeConfigs[0].ScrapeInterval, ScrapeTimeout: cfg.ScrapeConfigs[0].ScrapeInterval, - JobName: fmt.Sprintf("%s/%s", "containerInsightsKubeAPIServerScraper", cfg.ScrapeConfigs[0].MetricsPath), + JobName: fmt.Sprintf("%s/%s", jobName, cfg.ScrapeConfigs[0].MetricsPath), HonorTimestamps: true, Scheme: "http", MetricsPath: cfg.ScrapeConfigs[0].MetricsPath, @@ -269,3 +269,8 @@ func TestNewPrometheusScraperEndToEnd(t *testing.T) { assert.True(t, *consumer.relabeled) assert.False(t, *consumer.rpcDurationTotal) // this will get filtered out by our metric relabel config } + +func TestPrometheusScraperJobName(t *testing.T) { + // needs to start with containerInsights + assert.True(t, strings.HasPrefix(jobName, "containerInsightsKubeAPIServerScraper")) +} diff --git a/receiver/awscontainerinsightreceiver/internal/stores/podstore.go b/receiver/awscontainerinsightreceiver/internal/stores/podstore.go index a14817a8c2aa..a90b2a70e207 100644 --- a/receiver/awscontainerinsightreceiver/internal/stores/podstore.go +++ b/receiver/awscontainerinsightreceiver/internal/stores/podstore.go @@ -608,11 +608,7 @@ func (p *PodStore) addPodContainerStatusMetrics(metric CIMetric, pod *corev1.Pod reason := containerStatus.State.Waiting.Reason if reason != "" { if val, ok := ci.WaitingReasonLookup[reason]; ok { - if _, foundStatus := possibleStatuses[val]; foundStatus { - possibleStatuses[val]++ - } else { - possibleStatuses[val] = 1 - } + possibleStatuses[val]++ } } case containerStatus.State.Terminated != nil: @@ -624,11 +620,7 @@ func (p *PodStore) addPodContainerStatusMetrics(metric CIMetric, pod *corev1.Pod if containerStatus.LastTerminationState.Terminated != nil && containerStatus.LastTerminationState.Terminated.Reason != "" { if strings.Contains(containerStatus.LastTerminationState.Terminated.Reason, "OOMKilled") { - if _, foundStatus := possibleStatuses[ci.StatusContainerTerminatedReasonOOMKilled]; foundStatus { - possibleStatuses[ci.StatusContainerTerminatedReasonOOMKilled]++ - } else { - possibleStatuses[ci.StatusContainerTerminatedReasonOOMKilled] = 1 - } + possibleStatuses[ci.StatusContainerTerminatedReasonOOMKilled]++ } } } diff --git a/receiver/awscontainerinsightreceiver/internal/stores/podstore_test.go b/receiver/awscontainerinsightreceiver/internal/stores/podstore_test.go index 367ee59f8dbf..dff67bfe8dca 100644 --- a/receiver/awscontainerinsightreceiver/internal/stores/podstore_test.go +++ b/receiver/awscontainerinsightreceiver/internal/stores/podstore_test.go @@ -720,7 +720,6 @@ func TestPodStore_addStatus_enhanced_metrics(t *testing.T) { metric = generateMetric(fields, tags) podStore.addStatus(metric, pod) - //assert.Equal(t, "Waiting", metric.GetTag(ci.ContainerStatus)) assert.Equal(t, 2, metric.GetField(ci.MetricName(ci.TypePod, ci.StatusContainerWaiting))) assert.Equal(t, 2, metric.GetField(ci.MetricName(ci.TypePod, ci.StatusContainerWaitingReasonCrashLoopBackOff))) // sparse metrics