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
5dc36afe
Commit
5dc36afe
authored
Apr 16, 2018
by
Sven Klemm
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
calculate datetime for timeFrom and timeTo macro in go
parent
a2a7d3d4
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
8 deletions
+8
-8
pkg/tsdb/postgres/macros.go
+2
-2
pkg/tsdb/postgres/macros_test.go
+6
-6
No files found.
pkg/tsdb/postgres/macros.go
View file @
5dc36afe
...
...
@@ -85,9 +85,9 @@ func (m *PostgresMacroEngine) evaluateMacro(name string, args []string) (string,
return
fmt
.
Sprintf
(
"%s BETWEEN '%s' AND '%s'"
,
args
[
0
],
m
.
TimeRange
.
GetFromAsTimeUTC
()
.
Format
(
time
.
RFC3339
),
m
.
TimeRange
.
GetToAsTimeUTC
()
.
Format
(
time
.
RFC3339
)),
nil
case
"__timeFrom"
:
return
fmt
.
Sprintf
(
"
to_timestamp(%d)"
,
m
.
TimeRange
.
GetFromAsSecondsEpoch
(
)),
nil
return
fmt
.
Sprintf
(
"
'%s'"
,
m
.
TimeRange
.
GetFromAsTimeUTC
()
.
Format
(
time
.
RFC3339
)),
nil
case
"__timeTo"
:
return
fmt
.
Sprintf
(
"
to_timestamp(%d)"
,
m
.
TimeRange
.
GetToAsSecondsEpoch
(
)),
nil
return
fmt
.
Sprintf
(
"
'%s'"
,
m
.
TimeRange
.
GetToAsTimeUTC
()
.
Format
(
time
.
RFC3339
)),
nil
case
"__timeGroup"
:
if
len
(
args
)
<
2
{
return
""
,
fmt
.
Errorf
(
"macro %v needs time column and interval and optional fill value"
,
name
)
...
...
pkg/tsdb/postgres/macros_test.go
View file @
5dc36afe
...
...
@@ -45,7 +45,7 @@ func TestMacroEngine(t *testing.T) {
sql
,
err
:=
engine
.
Interpolate
(
query
,
timeRange
,
"select $__timeFrom(time_column)"
)
So
(
err
,
ShouldBeNil
)
So
(
sql
,
ShouldEqual
,
fmt
.
Sprintf
(
"select
to_timestamp(%d)"
,
from
.
Unix
(
)))
So
(
sql
,
ShouldEqual
,
fmt
.
Sprintf
(
"select
'%s'"
,
from
.
Format
(
time
.
RFC3339
)))
})
Convey
(
"interpolate __timeGroup function"
,
func
()
{
...
...
@@ -68,7 +68,7 @@ func TestMacroEngine(t *testing.T) {
sql
,
err
:=
engine
.
Interpolate
(
query
,
timeRange
,
"select $__timeTo(time_column)"
)
So
(
err
,
ShouldBeNil
)
So
(
sql
,
ShouldEqual
,
fmt
.
Sprintf
(
"select
to_timestamp(%d)"
,
to
.
Unix
(
)))
So
(
sql
,
ShouldEqual
,
fmt
.
Sprintf
(
"select
'%s'"
,
to
.
Format
(
time
.
RFC3339
)))
})
Convey
(
"interpolate __unixEpochFilter function"
,
func
()
{
...
...
@@ -109,14 +109,14 @@ func TestMacroEngine(t *testing.T) {
sql
,
err
:=
engine
.
Interpolate
(
query
,
timeRange
,
"select $__timeFrom(time_column)"
)
So
(
err
,
ShouldBeNil
)
So
(
sql
,
ShouldEqual
,
fmt
.
Sprintf
(
"select
to_timestamp(%d)"
,
from
.
Unix
(
)))
So
(
sql
,
ShouldEqual
,
fmt
.
Sprintf
(
"select
'%s'"
,
from
.
Format
(
time
.
RFC3339
)))
})
Convey
(
"interpolate __timeTo function"
,
func
()
{
sql
,
err
:=
engine
.
Interpolate
(
query
,
timeRange
,
"select $__timeTo(time_column)"
)
So
(
err
,
ShouldBeNil
)
So
(
sql
,
ShouldEqual
,
fmt
.
Sprintf
(
"select
to_timestamp(%d)"
,
to
.
Unix
(
)))
So
(
sql
,
ShouldEqual
,
fmt
.
Sprintf
(
"select
'%s'"
,
to
.
Format
(
time
.
RFC3339
)))
})
Convey
(
"interpolate __unixEpochFilter function"
,
func
()
{
...
...
@@ -157,14 +157,14 @@ func TestMacroEngine(t *testing.T) {
sql
,
err
:=
engine
.
Interpolate
(
query
,
timeRange
,
"select $__timeFrom(time_column)"
)
So
(
err
,
ShouldBeNil
)
So
(
sql
,
ShouldEqual
,
fmt
.
Sprintf
(
"select
to_timestamp(%d)"
,
from
.
Unix
(
)))
So
(
sql
,
ShouldEqual
,
fmt
.
Sprintf
(
"select
'%s'"
,
from
.
Format
(
time
.
RFC3339
)))
})
Convey
(
"interpolate __timeTo function"
,
func
()
{
sql
,
err
:=
engine
.
Interpolate
(
query
,
timeRange
,
"select $__timeTo(time_column)"
)
So
(
err
,
ShouldBeNil
)
So
(
sql
,
ShouldEqual
,
fmt
.
Sprintf
(
"select
to_timestamp(%d)"
,
to
.
Unix
(
)))
So
(
sql
,
ShouldEqual
,
fmt
.
Sprintf
(
"select
'%s'"
,
to
.
Format
(
time
.
RFC3339
)))
})
Convey
(
"interpolate __unixEpochFilter function"
,
func
()
{
...
...
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