Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions receiver/oxidemetricsreceiver/scraper.go
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,13 @@ func addHistogram(
) error {
timestamps := series.Points.Timestamps
startTimes := series.Points.StartTimes
if len(startTimes) > 0 && len(startTimes) != len(timestamps) {
return fmt.Errorf(
"invariant violated: number of start times %d must match number of timestamps %d",
len(startTimes),
len(timestamps),
)
}

switch v := metricValue.Values.Value.(type) {
case *oxide.ValueArrayIntegerDistribution:
Expand Down Expand Up @@ -695,6 +702,13 @@ func addPoint(
) error {
timestamps := series.Points.Timestamps
startTimes := series.Points.StartTimes
if len(startTimes) > 0 && len(startTimes) != len(timestamps) {
return fmt.Errorf(
"invariant violated: number of start times %d must match number of timestamps %d",
len(startTimes),
len(timestamps),
)
}
hasStartTimes := len(startTimes) > 0
switch v := metricValue.Values.Value.(type) {
case *oxide.ValueArrayInteger:
Expand Down
42 changes: 42 additions & 0 deletions receiver/oxidemetricsreceiver/scraper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,26 @@ func TestAddPoint(t *testing.T) {
}(),
},
},
// Error case: fewer start times than timestamps
{
name: "fewer start times than timestamps",
series: oxide.Timeseries{
Points: oxide.Points{
StartTimes: []time.Time{startTime},
Timestamps: []time.Time{now, now.Add(time.Second)},
Values: []oxide.Values{
{
Values: oxide.ValueArray{
Value: &oxide.ValueArrayInteger{
Values: []*int{oxide.NewPointer(1), oxide.NewPointer(2)},
},
},
},
},
},
},
wantErr: "number of start times 1 must match number of timestamps 2",
},
// Error case: unexpected type
{
name: "unexpected type",
Expand Down Expand Up @@ -456,6 +476,28 @@ func TestAddHistogram(t *testing.T) {
}(),
},
},
{
name: "fewer start times than timestamps",
series: oxide.Timeseries{
Points: oxide.Points{
StartTimes: []time.Time{startTime},
Timestamps: []time.Time{now, now.Add(time.Second)},
Values: []oxide.Values{
{
Values: oxide.ValueArray{
Value: &oxide.ValueArrayIntegerDistribution{
Values: []*oxide.Distributionint64{
{Bins: []int{0, 1}, Counts: []uint64{1, 2}},
{Bins: []int{0, 1}, Counts: []uint64{3, 4}},
},
},
},
},
},
},
},
wantErr: "number of start times 1 must match number of timestamps 2",
},
{
name: "unexpected type",
series: oxide.Timeseries{
Expand Down