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

@ -3,7 +3,6 @@ package postgres
import (
"fmt"
"regexp"
"strconv"
"strings"
"time"
@ -114,20 +113,9 @@ func (m *postgresMacroEngine) evaluateMacro(name string, args []string) (string,
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(extract(epoch from %s)/%v)*%v", args[0], interval.Seconds(), interval.Seconds()), nil