Skip to content

Commit

Permalink
[exporter/awsemfexporter] Propagate RetainInitialValueOfDeltaMetric t…
Browse files Browse the repository at this point in the history
…o 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
  • Loading branch information
jameshi16 authored Aug 11, 2023
1 parent 13614ec commit b7b4c81
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 5 deletions.
20 changes: 20 additions & 0 deletions .chloggen/awsemfexporter-publish-initial-metrics.yaml
Original file line number Diff line number Diff line change
@@ -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:
12 changes: 7 additions & 5 deletions exporter/awsemfexporter/metric_translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,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
Expand All @@ -134,11 +135,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,
Expand Down
30 changes: 30 additions & 0 deletions exporter/awsemfexporter/metric_translator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2343,6 +2343,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()
Expand Down

0 comments on commit b7b4c81

Please sign in to comment.