Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove delta adjustment from summaries by default in EMF exporter #3408

Merged
merged 1 commit into from
May 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion exporter/awsemfexporter/datapoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,13 @@ func getDataPoints(pmd *pdata.Metric, metadata CWMetricMetadata, logger *zap.Log
}
case pdata.MetricDataTypeSummary:
metric := pmd.Summary()
adjusterMetadata.adjustToDelta = true
// For summaries coming from the prometheus receiver, the sum and count are cumulative, whereas for summaries
// coming from other sources, e.g. SDK, the sum and count are delta by being accumulated and reset periodically.
// In order to ensure metrics are sent as deltas, we check the receiver attribute (which can be injected by
// 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
adjusterMetadata.adjustToDelta = metadata.receiver == prometheusReceiver
dps = SummaryDataPointSlice{
metadata.InstrumentationLibraryName,
adjusterMetadata,
Expand Down
34 changes: 29 additions & 5 deletions exporter/awsemfexporter/datapoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ func TestSummaryDataPointSliceAt(t *testing.T) {
assert.Equal(t, expectedMetricStats.Max, actualMetricsStats.Max)
assert.Equal(t, expectedMetricStats.Min, actualMetricsStats.Min)
assert.InDelta(t, expectedMetricStats.Count, actualMetricsStats.Count, 0.1)
assert.True(t, expectedMetricStats.Sum-actualMetricsStats.Sum < float64(0.02))
assert.InDelta(t, expectedMetricStats.Sum, actualMetricsStats.Sum, 0.02)
})
}
}
Expand Down Expand Up @@ -536,12 +536,14 @@ func TestGetDataPoints(t *testing.T) {
"log-stream",
}
testCases := []struct {
testName string
metric *metricspb.Metric
expectedDataPoints DataPoints
testName string
isPrometheusMetrics bool
metric *metricspb.Metric
expectedDataPoints DataPoints
}{
{
"Int gauge",
false,
generateTestIntGauge("foo"),
IntDataPointSlice{
metadata.InstrumentationLibraryName,
Expand All @@ -551,6 +553,7 @@ func TestGetDataPoints(t *testing.T) {
},
{
"Double gauge",
false,
generateTestDoubleGauge("foo"),
DoubleDataPointSlice{
metadata.InstrumentationLibraryName,
Expand All @@ -560,6 +563,7 @@ func TestGetDataPoints(t *testing.T) {
},
{
"Int sum",
false,
generateTestIntSum("foo"),
IntDataPointSlice{
metadata.InstrumentationLibraryName,
Expand All @@ -569,6 +573,7 @@ func TestGetDataPoints(t *testing.T) {
},
{
"Double sum",
false,
generateTestDoubleSum("foo"),
DoubleDataPointSlice{
metadata.InstrumentationLibraryName,
Expand All @@ -578,14 +583,26 @@ func TestGetDataPoints(t *testing.T) {
},
{
"Double histogram",
false,
generateTestHistogram("foo"),
HistogramDataPointSlice{
metadata.InstrumentationLibraryName,
pdata.HistogramDataPointSlice{},
},
},
{
"Summary",
"Summary from SDK",
false,
generateTestSummary("foo"),
SummaryDataPointSlice{
metadata.InstrumentationLibraryName,
dmm,
pdata.SummaryDataPointSlice{},
},
},
{
"Summary from Prometheus",
true,
generateTestSummary("foo"),
SummaryDataPointSlice{
metadata.InstrumentationLibraryName,
Expand All @@ -607,6 +624,11 @@ func TestGetDataPoints(t *testing.T) {
expectedLabels := pdata.NewStringMap().InitFromMap(map[string]string{"label1": "value1"})

t.Run(tc.testName, func(t *testing.T) {
if tc.isPrometheusMetrics {
metadata.receiver = prometheusReceiver
} else {
metadata.receiver = ""
}
dps := getDataPoints(&metric, metadata, logger)
assert.NotNil(t, dps)
assert.Equal(t, reflect.TypeOf(tc.expectedDataPoints), reflect.TypeOf(dps))
Expand Down Expand Up @@ -636,7 +658,9 @@ func TestGetDataPoints(t *testing.T) {
assert.Equal(t, []float64{0, 10}, dp.ExplicitBounds())
assert.Equal(t, expectedLabels, dp.LabelsMap())
case SummaryDataPointSlice:
expectedDPS := tc.expectedDataPoints.(SummaryDataPointSlice)
assert.Equal(t, metadata.InstrumentationLibraryName, convertedDPS.instrumentationLibraryName)
assert.Equal(t, expectedDPS.deltaMetricMetadata, convertedDPS.deltaMetricMetadata)
assert.Equal(t, 1, convertedDPS.Len())
dp := convertedDPS.SummaryDataPointSlice.At(0)
assert.Equal(t, 15.0, dp.Sum())
Expand Down