Skip to content
This repository was archived by the owner on Oct 3, 2023. It is now read-only.

Commit 42e7e58

Browse files
authored
Add staggering between identical start and end times in metric in PushMetricsProto call (#290)
1 parent b7f4654 commit 42e7e58

File tree

13 files changed

+67
-61
lines changed

13 files changed

+67
-61
lines changed

metrics_proto.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -443,12 +443,18 @@ func fromProtoPoint(startTime *timestamppb.Timestamp, pt *metricspb.Point) (*mon
443443
return nil, err
444444
}
445445

446+
endTime := pt.Timestamp
447+
interval := &monitoringpb.TimeInterval{
448+
StartTime: startTime,
449+
EndTime: endTime,
450+
}
451+
if startTime != nil && endTime != nil {
452+
interval = toValidTimeIntervalpb(startTime.AsTime(), endTime.AsTime())
453+
}
454+
446455
return &monitoringpb.Point{
447-
Value: mptv,
448-
Interval: &monitoringpb.TimeInterval{
449-
StartTime: startTime,
450-
EndTime: pt.Timestamp,
451-
},
456+
Value: mptv,
457+
Interval: interval,
452458
}, nil
453459
}
454460

metrics_proto_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func TestExportTimeSeriesWithDifferentLabels(t *testing.T) {
6868
}
6969
endTimestamp := &timestamp.Timestamp{
7070
Seconds: 1543160298,
71-
Nanos: 100000997,
71+
Nanos: 101000090,
7272
}
7373

7474
// Generate the proto Metrics.
@@ -213,7 +213,7 @@ func TestProtoMetricToCreateTimeSeriesRequest(t *testing.T) {
213213
}
214214
endTimestamp := &timestamp.Timestamp{
215215
Seconds: 1543160298,
216-
Nanos: 100000997,
216+
Nanos: 101000090,
217217
}
218218

219219
tests := []struct {
@@ -403,7 +403,7 @@ func TestProtoMetricWithDifferentResource(t *testing.T) {
403403
}
404404
endTimestamp := &timestamp.Timestamp{
405405
Seconds: 1543160298,
406-
Nanos: 100000997,
406+
Nanos: 101000090,
407407
}
408408

409409
seenResources := make(map[*resourcepb.Resource]*monitoredrespb.MonitoredResource)
@@ -677,7 +677,7 @@ func TestProtoMetricsToMonitoringMetrics_fromProtoPoint(t *testing.T) {
677677
}
678678
endTimestamp := &timestamp.Timestamp{
679679
Seconds: 1543160298,
680-
Nanos: 100000997,
680+
Nanos: 101000090,
681681
}
682682

683683
tests := []struct {
@@ -890,7 +890,7 @@ func TestConvertSummaryMetrics(t *testing.T) {
890890
}
891891
endTimestamp := &timestamp.Timestamp{
892892
Seconds: 1543160298,
893-
Nanos: 100000997,
893+
Nanos: 101000090,
894894
}
895895

896896
res := &resourcepb.Resource{

metrics_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ func TestMetricToCreateTimeSeriesRequest(t *testing.T) {
9494
startTime, _ := ptypes.Timestamp(startTimestamp)
9595
endTimestamp := &timestamp.Timestamp{
9696
Seconds: 1543160298,
97-
Nanos: 100000997,
97+
Nanos: 101000090,
9898
}
9999
endTime, _ := ptypes.Timestamp(endTimestamp)
100100

@@ -435,7 +435,7 @@ func TestMetricsToMonitoringMetrics_fromProtoPoint(t *testing.T) {
435435
startTime, _ := ptypes.Timestamp(startTimestamp)
436436
endTimestamp := &timestamp.Timestamp{
437437
Seconds: 1543160298,
438-
Nanos: 100000997,
438+
Nanos: 101000090,
439439
}
440440
endTime, _ := ptypes.Timestamp(endTimestamp)
441441

@@ -569,7 +569,7 @@ func TestResourceByDescriptor(t *testing.T) {
569569
startTime, _ := ptypes.Timestamp(startTimestamp)
570570
endTimestamp := &timestamp.Timestamp{
571571
Seconds: 1543160298,
572-
Nanos: 100000997,
572+
Nanos: 101000090,
573573
}
574574
endTime, _ := ptypes.Timestamp(endTimestamp)
575575

testdata/BuiltInMetrics/inMetrics.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ timeseries: <
2525
points: <
2626
timestamp: <
2727
seconds: 1543160298
28-
nanos: 100000997
28+
nanos: 101000090
2929
>
3030
int64_value: 1
3131
>
@@ -58,7 +58,7 @@ timeseries: <
5858
points: <
5959
timestamp: <
6060
seconds: 1543160298
61-
nanos: 100000997
61+
nanos: 101000090
6262
>
6363
int64_value: 1
6464
>
@@ -91,7 +91,7 @@ timeseries: <
9191
points: <
9292
timestamp: <
9393
seconds: 1543160298
94-
nanos: 100000997
94+
nanos: 101000090
9595
>
9696
int64_value: 1
9797
>

testdata/BuiltInMetrics/outTSR.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ time_series: <
2020
interval: <
2121
end_time: <
2222
seconds: 1543160298
23-
nanos: 100000997
23+
nanos: 101000090
2424
>
2525
start_time: <
2626
seconds: 1543160298
@@ -53,7 +53,7 @@ time_series: <
5353
interval: <
5454
end_time: <
5555
seconds: 1543160298
56-
nanos: 100000997
56+
nanos: 101000090
5757
>
5858
start_time: <
5959
seconds: 1543160298
@@ -86,7 +86,7 @@ time_series: <
8686
interval: <
8787
end_time: <
8888
seconds: 1543160298
89-
nanos: 100000997
89+
nanos: 101000090
9090
>
9191
start_time: <
9292
seconds: 1543160298
@@ -97,4 +97,4 @@ time_series: <
9797
int64_value: 1
9898
>
9999
>
100-
>
100+
>

testdata/ExportLabels/inMetrics.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ timeseries: <
2525
points: <
2626
timestamp: <
2727
seconds: 1543160298
28-
nanos: 100000997
28+
nanos: 101000090
2929
>
3030
int64_value: 1
3131
>
@@ -45,7 +45,7 @@ timeseries: <
4545
points: <
4646
timestamp: <
4747
seconds: 1543160298
48-
nanos: 100000997
48+
nanos: 101000090
4949
>
5050
int64_value: 1
5151
>
@@ -64,7 +64,7 @@ timeseries: <
6464
points: <
6565
timestamp: <
6666
seconds: 1543160298
67-
nanos: 100000997
67+
nanos: 101000090
6868
>
6969
int64_value: 1
7070
>
@@ -82,7 +82,7 @@ timeseries: <
8282
points: <
8383
timestamp: <
8484
seconds: 1543160298
85-
nanos: 100000997
85+
nanos: 101000090
8686
>
8787
int64_value: 1
8888
>

testdata/ExportLabels/outTSR.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ time_series: <
2020
interval: <
2121
end_time: <
2222
seconds: 1543160298
23-
nanos: 100000997
23+
nanos: 101000090
2424
>
2525
start_time: <
2626
seconds: 1543160298
@@ -53,7 +53,7 @@ time_series: <
5353
interval: <
5454
end_time: <
5555
seconds: 1543160298
56-
nanos: 100000997
56+
nanos: 101000090
5757
>
5858
start_time: <
5959
seconds: 1543160298
@@ -82,7 +82,7 @@ time_series: <
8282
interval: <
8383
end_time: <
8484
seconds: 1543160298
85-
nanos: 100000997
85+
nanos: 101000090
8686
>
8787
start_time: <
8888
seconds: 1543160298
@@ -111,7 +111,7 @@ time_series: <
111111
interval: <
112112
end_time: <
113113
seconds: 1543160298
114-
nanos: 100000997
114+
nanos: 101000090
115115
>
116116
start_time: <
117117
seconds: 1543160298

testdata/ExportMetricsOfAllTypes/inMetrics.txt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ timeseries: <
2525
points: <
2626
timestamp: <
2727
seconds: 1543160298
28-
nanos: 100000997
28+
nanos: 101000090
2929
>
3030
double_value: 35.5
3131
>
@@ -54,7 +54,7 @@ timeseries: <
5454
points: <
5555
timestamp: <
5656
seconds: 1543160298
57-
nanos: 100000997
57+
nanos: 101000090
5858
>
5959
double_value: 35.5
6060
>
@@ -87,7 +87,7 @@ timeseries: <
8787
points: <
8888
timestamp: <
8989
seconds: 1543160298
90-
nanos: 100000997
90+
nanos: 101000090
9191
>
9292
int64_value: 1
9393
>
@@ -116,7 +116,7 @@ timeseries: <
116116
points: <
117117
timestamp: <
118118
seconds: 1543160298
119-
nanos: 100000997
119+
nanos: 101000090
120120
>
121121
int64_value: 1
122122
>
@@ -149,7 +149,7 @@ timeseries: <
149149
points: <
150150
timestamp: <
151151
seconds: 1543160298
152-
nanos: 100000997
152+
nanos: 101000090
153153
>
154154
distribution_value: <
155155
count: 1
@@ -202,7 +202,7 @@ timeseries: <
202202
points: <
203203
timestamp: <
204204
seconds: 1543160298
205-
nanos: 100000997
205+
nanos: 101000090
206206
>
207207
distribution_value: <
208208
count: 1
@@ -255,7 +255,7 @@ timeseries: <
255255
points: <
256256
timestamp: <
257257
seconds: 1543160298
258-
nanos: 100000997
258+
nanos: 101000090
259259
>
260260
summary_value: <
261261
count: <
@@ -300,7 +300,7 @@ timeseries: <
300300
points: <
301301
timestamp: <
302302
seconds: 1543160298
303-
nanos: 100000997
303+
nanos: 101000090
304304
>
305305
summary_value: <
306306
count: <

0 commit comments

Comments
 (0)