Skip to content

Commit

Permalink
[receiver/redis] Set start timestamp uniformly for gauge and sum metrics
Browse files Browse the repository at this point in the history
Currently start time of gauge metrics is set to 0. According to the specification https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/datamodel.md#gauge, start time should be set the timestamp when a metric collection system started.

The time when redis server started is already being used for Sum metrics. There is no reason to keep it inconsistent. This change applies the same timestamp value to both Gauge and Sum metrics uniformly.
  • Loading branch information
dmitryax committed Dec 29, 2021
1 parent 6b42249 commit c5dd48d
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- `datadogexporter`: Add compatibility with ECS Fargate semantic conventions (#6670)
- `k8s_observer`: discover k8s.node endpoints (#6820)
- `redisreceiver`: Add missing description fields to keyspace metrics (#6940)
- `redisreceiver`: Set start timestamp uniformly for gauge and sum metrics (#6941)
- `kafkaexporter`: Allow controlling Kafka acknowledgment behaviour (#6301)

## 🛑 Breaking changes 🛑
Expand Down
4 changes: 2 additions & 2 deletions receiver/redisreceiver/pdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ func initIntMetric(m *redisMetric, value int64, t *timeBundle, dest pdata.Metric
sum.SetIsMonotonic(m.isMonotonic)
sum.SetAggregationTemporality(pdata.MetricAggregationTemporalityCumulative)
pt = sum.DataPoints().AppendEmpty()
pt.SetStartTimestamp(pdata.NewTimestampFromTime(t.serverStart))
}
pt.SetIntVal(value)
pt.SetStartTimestamp(pdata.NewTimestampFromTime(t.serverStart))
pt.SetTimestamp(pdata.NewTimestampFromTime(t.current))
pdata.NewAttributeMapFromMap(m.labels).CopyTo(pt.Attributes())
}
Expand All @@ -87,9 +87,9 @@ func initDoubleMetric(m *redisMetric, value float64, t *timeBundle, dest pdata.M
sum.SetIsMonotonic(m.isMonotonic)
sum.SetAggregationTemporality(pdata.MetricAggregationTemporalityCumulative)
pt = sum.DataPoints().AppendEmpty()
pt.SetStartTimestamp(pdata.NewTimestampFromTime(t.serverStart))
}
pt.SetDoubleVal(value)
pt.SetStartTimestamp(pdata.NewTimestampFromTime(t.serverStart))
pt.SetTimestamp(pdata.NewTimestampFromTime(t.current))
pdata.NewAttributeMapFromMap(m.labels).CopyTo(pt.Attributes())
}
Expand Down
4 changes: 2 additions & 2 deletions receiver/redisreceiver/pdata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,15 @@ func TestNewPDM(t *testing.T) {

pdm := pdata.NewMetric()
initIntMetric(&redisMetric{pdType: pdata.MetricDataTypeGauge}, 0, tb, pdm)
assert.Equal(t, pdata.Timestamp(0), pdm.Gauge().DataPoints().At(0).StartTimestamp())
assert.Equal(t, serverStartTime, pdm.Gauge().DataPoints().At(0).StartTimestamp())

pdm = pdata.NewMetric()
initIntMetric(&redisMetric{pdType: pdata.MetricDataTypeSum}, 0, tb, pdm)
assert.Equal(t, serverStartTime, pdm.Sum().DataPoints().At(0).StartTimestamp())

pdm = pdata.NewMetric()
initDoubleMetric(&redisMetric{pdType: pdata.MetricDataTypeGauge}, 0, tb, pdm)
assert.Equal(t, pdata.Timestamp(0), pdm.Gauge().DataPoints().At(0).StartTimestamp())
assert.Equal(t, serverStartTime, pdm.Gauge().DataPoints().At(0).StartTimestamp())

pdm = pdata.NewMetric()
initDoubleMetric(&redisMetric{pdType: pdata.MetricDataTypeSum}, 0, tb, pdm)
Expand Down

0 comments on commit c5dd48d

Please sign in to comment.