From 72d44a0c632a42924723c51106f013bd46aca29e Mon Sep 17 00:00:00 2001 From: James Date: Mon, 10 Jul 2023 11:45:50 +0800 Subject: [PATCH 1/2] Propagate retain initial value of delta metric in OTelToGroupedMetric --- exporter/awsemfexporter/metric_translator.go | 12 ++++---- .../awsemfexporter/metric_translator_test.go | 30 +++++++++++++++++++ 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/exporter/awsemfexporter/metric_translator.go b/exporter/awsemfexporter/metric_translator.go index e1fd70a5bdf6..f131018ef054 100644 --- a/exporter/awsemfexporter/metric_translator.go +++ b/exporter/awsemfexporter/metric_translator.go @@ -103,6 +103,7 @@ func (mt metricTranslator) translateOTelToGroupedMetric(rm pmetric.ResourceMetri var instrumentationScopeName string cWNamespace := getNamespace(rm, config.Namespace) logGroup, logStream, patternReplaceSucceeded := getLogInfo(rm, cWNamespace, config) + deltaInitialValue := config.RetainInitialValueOfDeltaMetric ilms := rm.ScopeMetrics() var metricReceiver string @@ -120,11 +121,12 @@ func (mt metricTranslator) translateOTelToGroupedMetric(rm pmetric.ResourceMetri metric := metrics.At(k) metadata := cWMetricMetadata{ groupedMetricMetadata: groupedMetricMetadata{ - namespace: cWNamespace, - timestampMs: timestamp, - logGroup: logGroup, - logStream: logStream, - metricDataType: metric.Type(), + namespace: cWNamespace, + timestampMs: timestamp, + logGroup: logGroup, + logStream: logStream, + metricDataType: metric.Type(), + retainInitialValueForDelta: deltaInitialValue, }, instrumentationScopeName: instrumentationScopeName, receiver: metricReceiver, diff --git a/exporter/awsemfexporter/metric_translator_test.go b/exporter/awsemfexporter/metric_translator_test.go index 0cafd832331b..845d9d8a65d4 100644 --- a/exporter/awsemfexporter/metric_translator_test.go +++ b/exporter/awsemfexporter/metric_translator_test.go @@ -2509,6 +2509,36 @@ func TestTranslateOtToGroupedMetricForLogGroupAndStream(t *testing.T) { } } +func TestTranslateOtToGroupedMetricForInitialDeltaValue(t *testing.T) { + for _, test := range logGroupStreamTestCases { + t.Run(test.name, func(t *testing.T) { + config := &Config{ + Namespace: "", + LogGroupName: test.inLogGroupName, + LogStreamName: test.inLogStreamName, + DimensionRollupOption: zeroAndSingleDimensionRollup, + logger: zap.NewNop(), + RetainInitialValueOfDeltaMetric: true, + } + + translator := newMetricTranslator(*config) + + groupedMetrics := make(map[interface{}]*groupedMetric) + + rm := test.inputMetrics.ResourceMetrics().At(0) + err := translator.translateOTelToGroupedMetric(rm, groupedMetrics, config) + assert.Nil(t, err) + + assert.NotNil(t, groupedMetrics) + assert.Equal(t, 1, len(groupedMetrics)) + + for _, actual := range groupedMetrics { + assert.True(t, actual.metadata.retainInitialValueForDelta) + } + }) + } +} + func generateTestMetrics(tm testMetric) pmetric.Metrics { md := pmetric.NewMetrics() now := time.Now() From 4dcca7bd3d79f0803bdaa108e4bb0e0eda030504 Mon Sep 17 00:00:00 2001 From: James Date: Mon, 24 Jul 2023 11:07:48 +0800 Subject: [PATCH 2/2] Update changelogs --- ...wsemfexporter-publish-initial-metrics.yaml | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100755 .chloggen/awsemfexporter-publish-initial-metrics.yaml diff --git a/.chloggen/awsemfexporter-publish-initial-metrics.yaml b/.chloggen/awsemfexporter-publish-initial-metrics.yaml new file mode 100755 index 000000000000..3edd8e0132ac --- /dev/null +++ b/.chloggen/awsemfexporter-publish-initial-metrics.yaml @@ -0,0 +1,20 @@ +# Use this changelog template to create an entry for release notes. +# If your change doesn't affect end users, such as a test fix or a tooling change, +# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: bug_fix + +# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) +component: awsemfexporter + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Add retain_initial_value_of_delta_metric to translateOTelToGroupedMetric, allowing the initial set of metrics to be published + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +issues: [24051] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: