Skip to content

Commit 4921292

Browse files
perebajArthurSens
authored andcommitted
set start timestamp (open-telemetry#38765)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description This PR belongs to part of the Linux foundation mentee program. Here we are setting the start timestamp for data point attributes <!-- Issue number (e.g. open-telemetry#1234) or full URL to issue, if applicable. --> #### Link to tracking issue Fixes part of [open-telemetry#37277](open-telemetry#37277) --------- Co-authored-by: Arthur Silva Sens <[email protected]>
1 parent 3a58349 commit 4921292

File tree

3 files changed

+43
-11
lines changed

3 files changed

+43
-11
lines changed

.chloggen/set-start-timestamp.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: 'enhancement'
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: prometheusremotewritereceiver
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Use Created Timestamps to populate Datapoint's StartTimeUnixNano
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [37277]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext:
19+
20+
# If your change doesn't affect end users or the exported elements of any package,
21+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
22+
# Optional: The change log or logs in which this entry should be included.
23+
# e.g. '[user]' or '[user, api]'
24+
# Include 'user' if the change is relevant to end users.
25+
# Include 'api' if there is a change to a library API.
26+
# Default: '[user]'
27+
change_logs: [user]

receiver/prometheusremotewritereceiver/receiver.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,12 +314,11 @@ func parseJobAndInstance(dest pcommon.Map, job, instance string) {
314314
}
315315

316316
// addNumberDatapoints adds the labels to the datapoints attributes.
317-
// TODO: We're still not handling the StartTimestamp.
318317
func addNumberDatapoints(datapoints pmetric.NumberDataPointSlice, ls labels.Labels, ts writev2.TimeSeries) {
319318
// Add samples from the timeseries
320319
for _, sample := range ts.Samples {
321320
dp := datapoints.AppendEmpty()
322-
321+
dp.SetStartTimestamp(pcommon.Timestamp(ts.CreatedTimestamp * int64(time.Millisecond)))
323322
// Set timestamp in nanoseconds (Prometheus uses milliseconds)
324323
dp.SetTimestamp(pcommon.Timestamp(sample.Timestamp * int64(time.Millisecond)))
325324
dp.SetDoubleValue(sample.Value)

receiver/prometheusremotewritereceiver/receiver_test.go

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,22 @@ var writeV2RequestFixture = &writev2.Request{
3131
Symbols: []string{"", "__name__", "test_metric1", "job", "service-x/test", "instance", "107cn001", "d", "e", "foo", "bar", "f", "g", "h", "i", "Test gauge for test purposes", "Maybe op/sec who knows (:", "Test counter for test purposes"},
3232
Timeseries: []writev2.TimeSeries{
3333
{
34-
Metadata: writev2.Metadata{Type: writev2.Metadata_METRIC_TYPE_GAUGE},
35-
LabelsRefs: []uint32{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, // Symbolized writeRequestFixture.Timeseries[0].Labels
36-
Samples: []writev2.Sample{{Value: 1, Timestamp: 1}},
34+
Metadata: writev2.Metadata{Type: writev2.Metadata_METRIC_TYPE_GAUGE},
35+
LabelsRefs: []uint32{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, // Symbolized writeRequestFixture.Timeseries[0].Labels
36+
Samples: []writev2.Sample{{Value: 1, Timestamp: 1}},
37+
CreatedTimestamp: 1,
3738
},
3839
{
39-
Metadata: writev2.Metadata{Type: writev2.Metadata_METRIC_TYPE_GAUGE},
40-
LabelsRefs: []uint32{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, // Same series as first. Should use the same resource metrics.
41-
Samples: []writev2.Sample{{Value: 2, Timestamp: 2}},
40+
Metadata: writev2.Metadata{Type: writev2.Metadata_METRIC_TYPE_GAUGE},
41+
LabelsRefs: []uint32{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, // Same series as first. Should use the same resource metrics.
42+
Samples: []writev2.Sample{{Value: 2, Timestamp: 2}},
43+
CreatedTimestamp: 2,
4244
},
4345
{
44-
Metadata: writev2.Metadata{Type: writev2.Metadata_METRIC_TYPE_GAUGE},
45-
LabelsRefs: []uint32{1, 2, 3, 9, 5, 10, 7, 8, 9, 10}, // This series has different label values for job and instance.
46-
Samples: []writev2.Sample{{Value: 2, Timestamp: 2}},
46+
Metadata: writev2.Metadata{Type: writev2.Metadata_METRIC_TYPE_GAUGE},
47+
LabelsRefs: []uint32{1, 2, 3, 9, 5, 10, 7, 8, 9, 10}, // This series has different label values for job and instance.
48+
Samples: []writev2.Sample{{Value: 2, Timestamp: 2}},
49+
CreatedTimestamp: 2,
4750
},
4851
},
4952
}
@@ -211,12 +214,14 @@ func TestTranslateV2(t *testing.T) {
211214
dp1.SetDoubleValue(1.0)
212215
dp1.Attributes().PutStr("d", "e")
213216
dp1.Attributes().PutStr("foo", "bar")
217+
dp1.SetStartTimestamp(pcommon.Timestamp(1 * int64(time.Millisecond)))
214218

215219
dp2 := metrics1.Gauge().DataPoints().AppendEmpty()
216220
dp2.SetTimestamp(pcommon.Timestamp(2 * int64(time.Millisecond)))
217221
dp2.SetDoubleValue(2.0)
218222
dp2.Attributes().PutStr("d", "e")
219223
dp2.Attributes().PutStr("foo", "bar")
224+
dp2.SetStartTimestamp(pcommon.Timestamp(2 * int64(time.Millisecond)))
220225

221226
rm2 := expected.ResourceMetrics().AppendEmpty()
222227
rmAttributes2 := rm2.Resource().Attributes()
@@ -236,6 +241,7 @@ func TestTranslateV2(t *testing.T) {
236241
dp3.SetDoubleValue(2.0)
237242
dp3.Attributes().PutStr("d", "e")
238243
dp3.Attributes().PutStr("foo", "bar")
244+
dp3.SetStartTimestamp(pcommon.Timestamp(2 * int64(time.Millisecond)))
239245

240246
return expected
241247
}(),

0 commit comments

Comments
 (0)