mirror of
https://github.com/grafana/grafana.git
synced 2024-11-23 09:26:43 -06:00
stackdriver: reverse points array to be in ascending order
This commit is contained in:
parent
f4fe26c659
commit
df6b430405
@ -207,7 +207,10 @@ func (e *StackdriverExecutor) unmarshalResponse(res *http.Response) (StackDriver
|
||||
func (e *StackdriverExecutor) parseResponse(queryRes *tsdb.QueryResult, data StackDriverResponse) error {
|
||||
for _, series := range data.TimeSeries {
|
||||
points := make([]tsdb.TimePoint, 0)
|
||||
for _, point := range series.Points {
|
||||
|
||||
// reverse the order to be ascending
|
||||
for i := len(series.Points) - 1; i >= 0; i-- {
|
||||
point := series.Points[i]
|
||||
points = append(points, tsdb.NewTimePoint(null.FloatFrom(point.Value.DoubleValue), float64((point.Interval.EndTime).Unix())*1000))
|
||||
}
|
||||
metricName := series.Metric.Type
|
||||
|
@ -91,9 +91,16 @@ func TestStackdriver(t *testing.T) {
|
||||
So(res.Series[0].Name, ShouldEqual, "serviceruntime.googleapis.com/api/request_count")
|
||||
So(len(res.Series[0].Points), ShouldEqual, 3)
|
||||
|
||||
So(res.Series[0].Points[0][0].Float64, ShouldEqual, 1.0666666666667)
|
||||
So(res.Series[0].Points[1][0].Float64, ShouldEqual, 1.05)
|
||||
So(res.Series[0].Points[2][0].Float64, ShouldEqual, 0.05)
|
||||
Convey("timestamps should be in ascending order", func() {
|
||||
So(res.Series[0].Points[0][0].Float64, ShouldEqual, 0.05)
|
||||
So(res.Series[0].Points[0][1].Float64, ShouldEqual, 1536670020000)
|
||||
|
||||
So(res.Series[0].Points[1][0].Float64, ShouldEqual, 1.05)
|
||||
So(res.Series[0].Points[1][1].Float64, ShouldEqual, 1536670080000)
|
||||
|
||||
So(res.Series[0].Points[2][0].Float64, ShouldEqual, 1.0666666666667)
|
||||
So(res.Series[0].Points[2][1].Float64, ShouldEqual, 1536670260000)
|
||||
})
|
||||
})
|
||||
|
||||
Convey("when data from query with no aggregation", func() {
|
||||
@ -116,9 +123,9 @@ func TestStackdriver(t *testing.T) {
|
||||
So(res.Series[2].Name, ShouldEqual, "compute.googleapis.com/instance/cpu/usage_time collector-us-east-1")
|
||||
|
||||
So(len(res.Series[0].Points), ShouldEqual, 3)
|
||||
So(res.Series[0].Points[0][0].Float64, ShouldEqual, 9.7730520330369)
|
||||
So(res.Series[0].Points[0][0].Float64, ShouldEqual, 9.8566497180145)
|
||||
So(res.Series[0].Points[1][0].Float64, ShouldEqual, 9.7323568146676)
|
||||
So(res.Series[0].Points[2][0].Float64, ShouldEqual, 9.8566497180145)
|
||||
So(res.Series[0].Points[2][0].Float64, ShouldEqual, 9.7730520330369)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user