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

Commit

Permalink
Add staggering between identical start and end times in metric in Pus…
Browse files Browse the repository at this point in the history
…hMetricsProto call (#290)
  • Loading branch information
kisieland authored Jun 14, 2021
1 parent b7f4654 commit 42e7e58
Show file tree
Hide file tree
Showing 13 changed files with 67 additions and 61 deletions.
16 changes: 11 additions & 5 deletions metrics_proto.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,12 +443,18 @@ func fromProtoPoint(startTime *timestamppb.Timestamp, pt *metricspb.Point) (*mon
return nil, err
}

endTime := pt.Timestamp
interval := &monitoringpb.TimeInterval{
StartTime: startTime,
EndTime: endTime,
}
if startTime != nil && endTime != nil {
interval = toValidTimeIntervalpb(startTime.AsTime(), endTime.AsTime())
}

return &monitoringpb.Point{
Value: mptv,
Interval: &monitoringpb.TimeInterval{
StartTime: startTime,
EndTime: pt.Timestamp,
},
Value: mptv,
Interval: interval,
}, nil
}

Expand Down
10 changes: 5 additions & 5 deletions metrics_proto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func TestExportTimeSeriesWithDifferentLabels(t *testing.T) {
}
endTimestamp := &timestamp.Timestamp{
Seconds: 1543160298,
Nanos: 100000997,
Nanos: 101000090,
}

// Generate the proto Metrics.
Expand Down Expand Up @@ -213,7 +213,7 @@ func TestProtoMetricToCreateTimeSeriesRequest(t *testing.T) {
}
endTimestamp := &timestamp.Timestamp{
Seconds: 1543160298,
Nanos: 100000997,
Nanos: 101000090,
}

tests := []struct {
Expand Down Expand Up @@ -403,7 +403,7 @@ func TestProtoMetricWithDifferentResource(t *testing.T) {
}
endTimestamp := &timestamp.Timestamp{
Seconds: 1543160298,
Nanos: 100000997,
Nanos: 101000090,
}

seenResources := make(map[*resourcepb.Resource]*monitoredrespb.MonitoredResource)
Expand Down Expand Up @@ -677,7 +677,7 @@ func TestProtoMetricsToMonitoringMetrics_fromProtoPoint(t *testing.T) {
}
endTimestamp := &timestamp.Timestamp{
Seconds: 1543160298,
Nanos: 100000997,
Nanos: 101000090,
}

tests := []struct {
Expand Down Expand Up @@ -890,7 +890,7 @@ func TestConvertSummaryMetrics(t *testing.T) {
}
endTimestamp := &timestamp.Timestamp{
Seconds: 1543160298,
Nanos: 100000997,
Nanos: 101000090,
}

res := &resourcepb.Resource{
Expand Down
6 changes: 3 additions & 3 deletions metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func TestMetricToCreateTimeSeriesRequest(t *testing.T) {
startTime, _ := ptypes.Timestamp(startTimestamp)
endTimestamp := &timestamp.Timestamp{
Seconds: 1543160298,
Nanos: 100000997,
Nanos: 101000090,
}
endTime, _ := ptypes.Timestamp(endTimestamp)

Expand Down Expand Up @@ -435,7 +435,7 @@ func TestMetricsToMonitoringMetrics_fromProtoPoint(t *testing.T) {
startTime, _ := ptypes.Timestamp(startTimestamp)
endTimestamp := &timestamp.Timestamp{
Seconds: 1543160298,
Nanos: 100000997,
Nanos: 101000090,
}
endTime, _ := ptypes.Timestamp(endTimestamp)

Expand Down Expand Up @@ -569,7 +569,7 @@ func TestResourceByDescriptor(t *testing.T) {
startTime, _ := ptypes.Timestamp(startTimestamp)
endTimestamp := &timestamp.Timestamp{
Seconds: 1543160298,
Nanos: 100000997,
Nanos: 101000090,
}
endTime, _ := ptypes.Timestamp(endTimestamp)

Expand Down
6 changes: 3 additions & 3 deletions testdata/BuiltInMetrics/inMetrics.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ timeseries: <
points: <
timestamp: <
seconds: 1543160298
nanos: 100000997
nanos: 101000090
>
int64_value: 1
>
Expand Down Expand Up @@ -58,7 +58,7 @@ timeseries: <
points: <
timestamp: <
seconds: 1543160298
nanos: 100000997
nanos: 101000090
>
int64_value: 1
>
Expand Down Expand Up @@ -91,7 +91,7 @@ timeseries: <
points: <
timestamp: <
seconds: 1543160298
nanos: 100000997
nanos: 101000090
>
int64_value: 1
>
Expand Down
8 changes: 4 additions & 4 deletions testdata/BuiltInMetrics/outTSR.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ time_series: <
interval: <
end_time: <
seconds: 1543160298
nanos: 100000997
nanos: 101000090
>
start_time: <
seconds: 1543160298
Expand Down Expand Up @@ -53,7 +53,7 @@ time_series: <
interval: <
end_time: <
seconds: 1543160298
nanos: 100000997
nanos: 101000090
>
start_time: <
seconds: 1543160298
Expand Down Expand Up @@ -86,7 +86,7 @@ time_series: <
interval: <
end_time: <
seconds: 1543160298
nanos: 100000997
nanos: 101000090
>
start_time: <
seconds: 1543160298
Expand All @@ -97,4 +97,4 @@ time_series: <
int64_value: 1
>
>
>
>
8 changes: 4 additions & 4 deletions testdata/ExportLabels/inMetrics.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ timeseries: <
points: <
timestamp: <
seconds: 1543160298
nanos: 100000997
nanos: 101000090
>
int64_value: 1
>
Expand All @@ -45,7 +45,7 @@ timeseries: <
points: <
timestamp: <
seconds: 1543160298
nanos: 100000997
nanos: 101000090
>
int64_value: 1
>
Expand All @@ -64,7 +64,7 @@ timeseries: <
points: <
timestamp: <
seconds: 1543160298
nanos: 100000997
nanos: 101000090
>
int64_value: 1
>
Expand All @@ -82,7 +82,7 @@ timeseries: <
points: <
timestamp: <
seconds: 1543160298
nanos: 100000997
nanos: 101000090
>
int64_value: 1
>
Expand Down
8 changes: 4 additions & 4 deletions testdata/ExportLabels/outTSR.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ time_series: <
interval: <
end_time: <
seconds: 1543160298
nanos: 100000997
nanos: 101000090
>
start_time: <
seconds: 1543160298
Expand Down Expand Up @@ -53,7 +53,7 @@ time_series: <
interval: <
end_time: <
seconds: 1543160298
nanos: 100000997
nanos: 101000090
>
start_time: <
seconds: 1543160298
Expand Down Expand Up @@ -82,7 +82,7 @@ time_series: <
interval: <
end_time: <
seconds: 1543160298
nanos: 100000997
nanos: 101000090
>
start_time: <
seconds: 1543160298
Expand Down Expand Up @@ -111,7 +111,7 @@ time_series: <
interval: <
end_time: <
seconds: 1543160298
nanos: 100000997
nanos: 101000090
>
start_time: <
seconds: 1543160298
Expand Down
16 changes: 8 additions & 8 deletions testdata/ExportMetricsOfAllTypes/inMetrics.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ timeseries: <
points: <
timestamp: <
seconds: 1543160298
nanos: 100000997
nanos: 101000090
>
double_value: 35.5
>
Expand Down Expand Up @@ -54,7 +54,7 @@ timeseries: <
points: <
timestamp: <
seconds: 1543160298
nanos: 100000997
nanos: 101000090
>
double_value: 35.5
>
Expand Down Expand Up @@ -87,7 +87,7 @@ timeseries: <
points: <
timestamp: <
seconds: 1543160298
nanos: 100000997
nanos: 101000090
>
int64_value: 1
>
Expand Down Expand Up @@ -116,7 +116,7 @@ timeseries: <
points: <
timestamp: <
seconds: 1543160298
nanos: 100000997
nanos: 101000090
>
int64_value: 1
>
Expand Down Expand Up @@ -149,7 +149,7 @@ timeseries: <
points: <
timestamp: <
seconds: 1543160298
nanos: 100000997
nanos: 101000090
>
distribution_value: <
count: 1
Expand Down Expand Up @@ -202,7 +202,7 @@ timeseries: <
points: <
timestamp: <
seconds: 1543160298
nanos: 100000997
nanos: 101000090
>
distribution_value: <
count: 1
Expand Down Expand Up @@ -255,7 +255,7 @@ timeseries: <
points: <
timestamp: <
seconds: 1543160298
nanos: 100000997
nanos: 101000090
>
summary_value: <
count: <
Expand Down Expand Up @@ -300,7 +300,7 @@ timeseries: <
points: <
timestamp: <
seconds: 1543160298
nanos: 100000997
nanos: 101000090
>
summary_value: <
count: <
Expand Down
Loading

0 comments on commit 42e7e58

Please sign in to comment.