Skip to content

Commit

Permalink
Merge pull request #7 from grafana/query-range-expected-matrix
Browse files Browse the repository at this point in the history
Return expected range query response from GenerateSeries.
  • Loading branch information
pracucci authored Nov 15, 2022
2 parents cffd2bb + 93af4ec commit fe4609f
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func TimeToMilliseconds(t time.Time) int64 {
return (int64(s) * 1e3) + (int64(ns * 1e3))
}

func GenerateSeries(name string, ts time.Time, additionalLabels ...prompb.Label) (series []prompb.TimeSeries, vector model.Vector) {
func GenerateSeries(name string, ts time.Time, additionalLabels ...prompb.Label) (series []prompb.TimeSeries, vector model.Vector, matrix model.Matrix) {
tsMillis := TimeToMilliseconds(ts)
value := rand.Float64()

Expand All @@ -149,7 +149,7 @@ func GenerateSeries(name string, ts time.Time, additionalLabels ...prompb.Label)
},
})

// Generate the expected vector when querying it
// Generate the expected vector and matrix when querying it
metric := model.Metric{}
metric[labels.MetricName] = model.LabelValue(name)
for _, lbl := range additionalLabels {
Expand All @@ -162,6 +162,16 @@ func GenerateSeries(name string, ts time.Time, additionalLabels ...prompb.Label)
Timestamp: model.Time(tsMillis),
})

matrix = append(matrix, &model.SampleStream{
Metric: metric,
Values: []model.SamplePair{
{
Timestamp: model.Time(tsMillis),
Value: model.SampleValue(value),
},
},
})

return
}

Expand Down

0 comments on commit fe4609f

Please sign in to comment.