testdata: added manual entry mode to test data
This commit is contained in:
Vendored
+40
@@ -1,6 +1,7 @@
|
||||
package testdata
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"math/rand"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -142,6 +143,45 @@ func init() {
|
||||
},
|
||||
})
|
||||
|
||||
registerScenario(&Scenario{
|
||||
Id: "manual_entry",
|
||||
Name: "Manual Entry",
|
||||
Handler: func(query *tsdb.Query, context *tsdb.TsdbQuery) *tsdb.QueryResult {
|
||||
queryRes := tsdb.NewQueryResult()
|
||||
|
||||
points := query.Model.Get("points").MustArray()
|
||||
|
||||
series := newSeriesForQuery(query)
|
||||
startTime := context.TimeRange.GetFromAsMsEpoch()
|
||||
endTime := context.TimeRange.GetToAsMsEpoch()
|
||||
|
||||
for _, val := range points {
|
||||
pointValues := val.([]interface{})
|
||||
|
||||
var value null.Float
|
||||
var time int64
|
||||
|
||||
if valueFloat, err := strconv.ParseFloat(string(pointValues[0].(json.Number)), 64); err == nil {
|
||||
value = null.FloatFrom(valueFloat)
|
||||
}
|
||||
|
||||
if timeInt, err := strconv.ParseInt(string(pointValues[1].(json.Number)), 10, 64); err != nil {
|
||||
continue
|
||||
} else {
|
||||
time = timeInt
|
||||
}
|
||||
|
||||
if time >= startTime && time <= endTime {
|
||||
series.Points = append(series.Points, tsdb.NewTimePoint(value, float64(time)))
|
||||
}
|
||||
}
|
||||
|
||||
queryRes.Series = append(queryRes.Series, series)
|
||||
|
||||
return queryRes
|
||||
},
|
||||
})
|
||||
|
||||
registerScenario(&Scenario{
|
||||
Id: "csv_metric_values",
|
||||
Name: "CSV Metric Values",
|
||||
|
||||
Reference in New Issue
Block a user