Refactor setting fillmode

This adds SetupFillmode to the tsdb package to be used by the sql
datasources.
This commit is contained in:
Sven Klemm
2018-08-12 10:51:58 +02:00
parent 1f88bfd2bc
commit d81a23becf
4 changed files with 30 additions and 46 deletions

View File

@@ -6,8 +6,6 @@ import (
"strings"
"time"
"strconv"
"github.com/grafana/grafana/pkg/tsdb"
)
@@ -97,20 +95,9 @@ func (m *msSqlMacroEngine) evaluateMacro(name string, args []string) (string, er
return "", fmt.Errorf("error parsing interval %v", args[1])
}
if len(args) == 3 {
m.query.Model.Set("fill", true)
m.query.Model.Set("fillInterval", interval.Seconds())
switch args[2] {
case "NULL":
m.query.Model.Set("fillMode", "null")
case "previous":
m.query.Model.Set("fillMode", "previous")
default:
m.query.Model.Set("fillMode", "value")
floatVal, err := strconv.ParseFloat(args[2], 64)
if err != nil {
return "", fmt.Errorf("error parsing fill value %v", args[2])
}
m.query.Model.Set("fillValue", floatVal)
err := tsdb.SetupFillmode(m.query, interval, args[2])
if err != nil {
return "", err
}
}
return fmt.Sprintf("FLOOR(DATEDIFF(second, '1970-01-01', %s)/%.0f)*%.0f", args[0], interval.Seconds(), interval.Seconds()), nil