Skip to content

Commit

Permalink
Propagate retain initial value of delta metric in OTelToGroupedMetric
Browse files Browse the repository at this point in the history
  • Loading branch information
jameshi16 committed Jul 24, 2023
1 parent c55822f commit 72d44a0
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
12 changes: 7 additions & 5 deletions exporter/awsemfexporter/metric_translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
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 @@ -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()
Expand Down

0 comments on commit 72d44a0

Please sign in to comment.