mirror of
https://github.com/grafana/grafana.git
synced 2026-08-13 06:34:55 -05:00
change fillmode from last to previous
This commit is contained in:
@@ -102,8 +102,8 @@ func (m *msSqlMacroEngine) evaluateMacro(name string, args []string) (string, er
|
||||
switch args[2] {
|
||||
case "NULL":
|
||||
m.query.Model.Set("fillMode", "null")
|
||||
case "last":
|
||||
m.query.Model.Set("fillMode", "last")
|
||||
case "previous":
|
||||
m.query.Model.Set("fillMode", "previous")
|
||||
default:
|
||||
m.query.Model.Set("fillMode", "value")
|
||||
floatVal, err := strconv.ParseFloat(args[2], 64)
|
||||
|
||||
@@ -85,8 +85,8 @@ func TestMacroEngine(t *testing.T) {
|
||||
So(fillInterval, ShouldEqual, 5*time.Minute.Seconds())
|
||||
})
|
||||
|
||||
Convey("interpolate __timeGroup function with fill (value = last)", func() {
|
||||
_, err := engine.Interpolate(query, timeRange, "GROUP BY $__timeGroup(time_column,'5m', last)")
|
||||
Convey("interpolate __timeGroup function with fill (value = previous)", func() {
|
||||
_, err := engine.Interpolate(query, timeRange, "GROUP BY $__timeGroup(time_column,'5m', previous)")
|
||||
|
||||
fill := query.Model.Get("fill").MustBool()
|
||||
fillMode := query.Model.Get("fillMode").MustString()
|
||||
@@ -94,7 +94,7 @@ func TestMacroEngine(t *testing.T) {
|
||||
|
||||
So(err, ShouldBeNil)
|
||||
So(fill, ShouldBeTrue)
|
||||
So(fillMode, ShouldEqual, "last")
|
||||
So(fillMode, ShouldEqual, "previous")
|
||||
So(fillInterval, ShouldEqual, 5*time.Minute.Seconds())
|
||||
})
|
||||
|
||||
|
||||
@@ -97,8 +97,8 @@ func (m *mySqlMacroEngine) evaluateMacro(name string, args []string) (string, er
|
||||
switch args[2] {
|
||||
case "NULL":
|
||||
m.query.Model.Set("fillMode", "null")
|
||||
case "last":
|
||||
m.query.Model.Set("fillMode", "last")
|
||||
case "previous":
|
||||
m.query.Model.Set("fillMode", "previous")
|
||||
default:
|
||||
m.query.Model.Set("fillMode", "value")
|
||||
floatVal, err := strconv.ParseFloat(args[2], 64)
|
||||
|
||||
@@ -321,12 +321,12 @@ func TestMySQL(t *testing.T) {
|
||||
So(points[3][0].Float64, ShouldEqual, 1.5)
|
||||
})
|
||||
|
||||
Convey("When doing a metric query using timeGroup with last fill enabled", func() {
|
||||
Convey("When doing a metric query using timeGroup with previous fill enabled", func() {
|
||||
query := &tsdb.TsdbQuery{
|
||||
Queries: []*tsdb.Query{
|
||||
{
|
||||
Model: simplejson.NewFromAny(map[string]interface{}{
|
||||
"rawSql": "SELECT $__timeGroup(time, '5m', last) as time_sec, avg(value) as value FROM metric GROUP BY 1 ORDER BY 1",
|
||||
"rawSql": "SELECT $__timeGroup(time, '5m', previous) as time_sec, avg(value) as value FROM metric GROUP BY 1 ORDER BY 1",
|
||||
"format": "time_series",
|
||||
}),
|
||||
RefId: "A",
|
||||
|
||||
@@ -119,8 +119,8 @@ func (m *postgresMacroEngine) evaluateMacro(name string, args []string) (string,
|
||||
switch args[2] {
|
||||
case "NULL":
|
||||
m.query.Model.Set("fillMode", "null")
|
||||
case "last":
|
||||
m.query.Model.Set("fillMode", "last")
|
||||
case "previous":
|
||||
m.query.Model.Set("fillMode", "previous")
|
||||
default:
|
||||
m.query.Model.Set("fillMode", "value")
|
||||
floatVal, err := strconv.ParseFloat(args[2], 64)
|
||||
|
||||
@@ -303,12 +303,12 @@ func TestPostgres(t *testing.T) {
|
||||
})
|
||||
})
|
||||
|
||||
Convey("When doing a metric query using timeGroup with last fill enabled", func() {
|
||||
Convey("When doing a metric query using timeGroup with previous 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",
|
||||
"rawSql": "SELECT $__timeGroup(time, '5m', previous), avg(value) as value FROM metric GROUP BY 1 ORDER BY 1",
|
||||
"format": "time_series",
|
||||
}),
|
||||
RefId: "A",
|
||||
|
||||
@@ -274,14 +274,14 @@ func (e *sqlQueryEndpoint) transformToTimeSeries(query *Query, rows *core.Rows,
|
||||
fillMissing := query.Model.Get("fill").MustBool(false)
|
||||
var fillInterval float64
|
||||
fillValue := null.Float{}
|
||||
fillLast := false
|
||||
fillPrevious := false
|
||||
|
||||
if fillMissing {
|
||||
fillInterval = query.Model.Get("fillInterval").MustFloat64() * 1000
|
||||
switch query.Model.Get("fillMode").MustString() {
|
||||
case "null":
|
||||
case "last":
|
||||
fillLast = true
|
||||
case "previous":
|
||||
fillPrevious = true
|
||||
case "value":
|
||||
fillValue.Float64 = query.Model.Get("fillValue").MustFloat64()
|
||||
fillValue.Valid = true
|
||||
@@ -358,7 +358,7 @@ func (e *sqlQueryEndpoint) transformToTimeSeries(query *Query, rows *core.Rows,
|
||||
intervalStart = series.Points[len(series.Points)-1][1].Float64 + fillInterval
|
||||
}
|
||||
|
||||
if fillLast {
|
||||
if fillPrevious {
|
||||
if len(series.Points) > 0 {
|
||||
fillValue = series.Points[len(series.Points)-1][0]
|
||||
} else {
|
||||
@@ -391,7 +391,7 @@ func (e *sqlQueryEndpoint) transformToTimeSeries(query *Query, rows *core.Rows,
|
||||
intervalStart := series.Points[len(series.Points)-1][1].Float64
|
||||
intervalEnd := float64(tsdbQuery.TimeRange.MustGetTo().UnixNano() / 1e6)
|
||||
|
||||
if fillLast {
|
||||
if fillPrevious {
|
||||
if len(series.Points) > 0 {
|
||||
fillValue = series.Points[len(series.Points)-1][0]
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user