add fillmode "last" to sql datasource

This adds a new fill mode last (last observation carried forward) for grafana
to the sql datasources. This fill mode will fill in the last seen value in a
series when a timepoint is missing or NULL if no value for that series has
been seen yet.
This commit is contained in:
Sven Klemm
2018-07-30 11:04:04 +02:00
parent 72af8a7044
commit bfc66a7ed0
13 changed files with 136 additions and 20 deletions

View File

@ -276,7 +276,7 @@ func TestPostgres(t *testing.T) {
})
Convey("When doing a metric query using timeGroup with float fill enabled", func() {
Convey("When doing a metric query using timeGroup with value fill enabled", func() {
query := &tsdb.TsdbQuery{
Queries: []*tsdb.Query{
{
@ -303,6 +303,34 @@ func TestPostgres(t *testing.T) {
})
})
Convey("When doing a metric query using timeGroup with last fill enabled", func() {
query := &tsdb.TsdbQuery{
Queries: []*tsdb.Query{
{
Model: simplejson.NewFromAny(map[string]interface{}{
"rawSql": "SELECT $__timeGroup(time, '5m', last), avg(value) as value FROM metric GROUP BY 1 ORDER BY 1",
"format": "time_series",
}),
RefId: "A",
},
},
TimeRange: &tsdb.TimeRange{
From: fmt.Sprintf("%v", fromStart.Unix()*1000),
To: fmt.Sprintf("%v", fromStart.Add(34*time.Minute).Unix()*1000),
},
}
resp, err := endpoint.Query(nil, nil, query)
So(err, ShouldBeNil)
queryResult := resp.Results["A"]
So(queryResult.Error, ShouldBeNil)
points := queryResult.Series[0].Points
So(points[2][0].Float64, ShouldEqual, 15.0)
So(points[3][0].Float64, ShouldEqual, 15.0)
So(points[6][0].Float64, ShouldEqual, 20.0)
})
Convey("Given a table with metrics having multiple values and measurements", func() {
type metric_values struct {
Time time.Time