Skip to content

Commit

Permalink
Report raw summary metric values by default in emf exporter (open-tel…
Browse files Browse the repository at this point in the history
  • Loading branch information
bjrara committed May 21, 2021
1 parent 2e21d93 commit eb5d360
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
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

0 comments on commit eb5d360

Please sign in to comment.