Skip to content

Commit

Permalink
[receiver/redis] Set start timestamp uniformly for gauge and sum metr…
Browse files Browse the repository at this point in the history
…ics (#6941)

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 authored Jan 5, 2022
1 parent fddf498 commit 514a904
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 @@ -10,6 +10,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)
- `lokiexporter`: Log the first part of the http body on failed pushes to loki (#6946)

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 514a904

Please sign in to comment.