Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
d81a23be
Commit
d81a23be
authored
Aug 12, 2018
by
Sven Klemm
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor setting fillmode
This adds SetupFillmode to the tsdb package to be used by the sql datasources.
parent
1f88bfd2
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
30 additions
and
46 deletions
+30
-46
pkg/tsdb/mssql/macros.go
+3
-16
pkg/tsdb/mysql/macros.go
+3
-15
pkg/tsdb/postgres/macros.go
+3
-15
pkg/tsdb/sql_engine.go
+21
-0
No files found.
pkg/tsdb/mssql/macros.go
View file @
d81a23be
...
...
@@ -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
...
...
pkg/tsdb/mysql/macros.go
View file @
d81a23be
...
...
@@ -3,7 +3,6 @@ package mysql
import
(
"fmt"
"regexp"
"strconv"
"strings"
"time"
...
...
@@ -92,20 +91,9 @@ func (m *mySqlMacroEngine) 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
(
"UNIX_TIMESTAMP(%s) DIV %.0f * %.0f"
,
args
[
0
],
interval
.
Seconds
(),
interval
.
Seconds
()),
nil
...
...
pkg/tsdb/postgres/macros.go
View file @
d81a23be
...
...
@@ -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
...
...
pkg/tsdb/sql_engine.go
View file @
d81a23be
...
...
@@ -6,6 +6,7 @@ import (
"database/sql"
"fmt"
"math"
"strconv"
"strings"
"sync"
"time"
...
...
@@ -568,3 +569,23 @@ func ConvertSqlValueColumnToFloat(columnName string, columnValue interface{}) (n
return
value
,
nil
}
func
SetupFillmode
(
query
*
Query
,
interval
time
.
Duration
,
fillmode
string
)
error
{
query
.
Model
.
Set
(
"fill"
,
true
)
query
.
Model
.
Set
(
"fillInterval"
,
interval
.
Seconds
())
switch
fillmode
{
case
"NULL"
:
query
.
Model
.
Set
(
"fillMode"
,
"null"
)
case
"previous"
:
query
.
Model
.
Set
(
"fillMode"
,
"previous"
)
default
:
query
.
Model
.
Set
(
"fillMode"
,
"value"
)
floatVal
,
err
:=
strconv
.
ParseFloat
(
fillmode
,
64
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"error parsing fill value %v"
,
fillmode
)
}
query
.
Model
.
Set
(
"fillValue"
,
floatVal
)
}
return
nil
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment