Skip to content

Commit b7b4c81

Browse files
authored
[exporter/awsemfexporter] Propagate RetainInitialValueOfDeltaMetric to translateOTelToGroupedMetric (#24051)
**Description:** The config option `retain_initial_value_of_delta_metric` does not seem to be used in `translateOTelToGroupedMetric`, which prevents the initial value of a basic counter from being published during a Lambda cold boot. Please see the minimum project required to replicate the issue [here](https://github.com/jameshi16/delta-initial-value-minimum-project). **Link to tracking Issue:** The main issue related to this PR can be found [here](aws-observability/aws-otel-lambda#634). It seems like I had a predecessor fixing this issue (see #17988), but his changes does not work for my use case. **Testing:** An additional test ensures that if `retain_initial_value_of_delta_metric` is set, it will be propagated to the `cWMetricMetadata`. **Documentation:** None
1 parent 13614ec commit b7b4c81

File tree

3 files changed

+57
-5
lines changed

3 files changed

+57
-5
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Use this changelog template to create an entry for release notes.
2+
# If your change doesn't affect end users, such as a test fix or a tooling change,
3+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
4+
5+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
6+
change_type: bug_fix
7+
8+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
9+
component: awsemfexporter
10+
11+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
12+
note: Add retain_initial_value_of_delta_metric to translateOTelToGroupedMetric, allowing the initial set of metrics to be published
13+
14+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
15+
issues: [24051]
16+
17+
# (Optional) One or more lines of additional information to render under the primary note.
18+
# These lines will be padded with 2 spaces and then inserted directly into the document.
19+
# Use pipe (|) for multiline entries.
20+
subtext:

exporter/awsemfexporter/metric_translator.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ func (mt metricTranslator) translateOTelToGroupedMetric(rm pmetric.ResourceMetri
117117
var instrumentationScopeName string
118118
cWNamespace := getNamespace(rm, config.Namespace)
119119
logGroup, logStream, patternReplaceSucceeded := getLogInfo(rm, cWNamespace, config)
120+
deltaInitialValue := config.RetainInitialValueOfDeltaMetric
120121

121122
ilms := rm.ScopeMetrics()
122123
var metricReceiver string
@@ -134,11 +135,12 @@ func (mt metricTranslator) translateOTelToGroupedMetric(rm pmetric.ResourceMetri
134135
metric := metrics.At(k)
135136
metadata := cWMetricMetadata{
136137
groupedMetricMetadata: groupedMetricMetadata{
137-
namespace: cWNamespace,
138-
timestampMs: timestamp,
139-
logGroup: logGroup,
140-
logStream: logStream,
141-
metricDataType: metric.Type(),
138+
namespace: cWNamespace,
139+
timestampMs: timestamp,
140+
logGroup: logGroup,
141+
logStream: logStream,
142+
metricDataType: metric.Type(),
143+
retainInitialValueForDelta: deltaInitialValue,
142144
},
143145
instrumentationScopeName: instrumentationScopeName,
144146
receiver: metricReceiver,

exporter/awsemfexporter/metric_translator_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2343,6 +2343,36 @@ func TestTranslateOtToGroupedMetricForLogGroupAndStream(t *testing.T) {
23432343
}
23442344
}
23452345

2346+
func TestTranslateOtToGroupedMetricForInitialDeltaValue(t *testing.T) {
2347+
for _, test := range logGroupStreamTestCases {
2348+
t.Run(test.name, func(t *testing.T) {
2349+
config := &Config{
2350+
Namespace: "",
2351+
LogGroupName: test.inLogGroupName,
2352+
LogStreamName: test.inLogStreamName,
2353+
DimensionRollupOption: zeroAndSingleDimensionRollup,
2354+
logger: zap.NewNop(),
2355+
RetainInitialValueOfDeltaMetric: true,
2356+
}
2357+
2358+
translator := newMetricTranslator(*config)
2359+
2360+
groupedMetrics := make(map[interface{}]*groupedMetric)
2361+
2362+
rm := test.inputMetrics.ResourceMetrics().At(0)
2363+
err := translator.translateOTelToGroupedMetric(rm, groupedMetrics, config)
2364+
assert.Nil(t, err)
2365+
2366+
assert.NotNil(t, groupedMetrics)
2367+
assert.Equal(t, 1, len(groupedMetrics))
2368+
2369+
for _, actual := range groupedMetrics {
2370+
assert.True(t, actual.metadata.retainInitialValueForDelta)
2371+
}
2372+
})
2373+
}
2374+
}
2375+
23462376
func generateTestMetrics(tm testMetric) pmetric.Metrics {
23472377
md := pmetric.NewMetrics()
23482378
now := time.Now()

0 commit comments

Comments
 (0)