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
9105625f
Commit
9105625f
authored
Jan 03, 2019
by
Ander Arguiñano
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added unixEpochNanoTo and unixEpochNanoFrom macros to postgresql
parent
4d8d2a96
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
0 deletions
+17
-0
pkg/tsdb/postgres/macros.go
+4
-0
pkg/tsdb/postgres/macros_test.go
+13
-0
No files found.
pkg/tsdb/postgres/macros.go
View file @
9105625f
...
@@ -127,6 +127,10 @@ func (m *postgresMacroEngine) evaluateMacro(name string, args []string) (string,
...
@@ -127,6 +127,10 @@ func (m *postgresMacroEngine) evaluateMacro(name string, args []string) (string,
return
""
,
fmt
.
Errorf
(
"missing time column argument for macro %v"
,
name
)
return
""
,
fmt
.
Errorf
(
"missing time column argument for macro %v"
,
name
)
}
}
return
fmt
.
Sprintf
(
"%s >= %d AND %s <= %d"
,
args
[
0
],
m
.
timeRange
.
GetFromAsTimeUTC
()
.
UnixNano
(),
args
[
0
],
m
.
timeRange
.
GetToAsTimeUTC
()
.
UnixNano
()),
nil
return
fmt
.
Sprintf
(
"%s >= %d AND %s <= %d"
,
args
[
0
],
m
.
timeRange
.
GetFromAsTimeUTC
()
.
UnixNano
(),
args
[
0
],
m
.
timeRange
.
GetToAsTimeUTC
()
.
UnixNano
()),
nil
case
"__unixEpochNanoFrom"
:
return
fmt
.
Sprintf
(
"'%d'"
,
m
.
timeRange
.
GetFromAsTimeUTC
()
.
UnixNano
()),
nil
case
"__unixEpochNanoTo"
:
return
fmt
.
Sprintf
(
"'%d'"
,
m
.
timeRange
.
GetToAsTimeUTC
()
.
UnixNano
()),
nil
case
"__unixEpochGroup"
:
case
"__unixEpochGroup"
:
if
len
(
args
)
<
2
{
if
len
(
args
)
<
2
{
return
""
,
fmt
.
Errorf
(
"macro %v needs time column and interval and optional fill value"
,
name
)
return
""
,
fmt
.
Errorf
(
"macro %v needs time column and interval and optional fill value"
,
name
)
...
...
pkg/tsdb/postgres/macros_test.go
View file @
9105625f
...
@@ -121,6 +121,19 @@ func TestMacroEngine(t *testing.T) {
...
@@ -121,6 +121,19 @@ func TestMacroEngine(t *testing.T) {
So
(
sql
,
ShouldEqual
,
fmt
.
Sprintf
(
"select time >= %d AND time <= %d"
,
from
.
UnixNano
(),
to
.
UnixNano
()))
So
(
sql
,
ShouldEqual
,
fmt
.
Sprintf
(
"select time >= %d AND time <= %d"
,
from
.
UnixNano
(),
to
.
UnixNano
()))
})
})
Convey
(
"interpolate __unixEpochNanoFrom function"
,
func
()
{
sql
,
err
:=
engine
.
Interpolate
(
query
,
timeRange
,
"select $__unixEpochNanoFrom()"
)
So
(
err
,
ShouldBeNil
)
So
(
sql
,
ShouldEqual
,
fmt
.
Sprintf
(
"select '%d'"
,
from
.
UnixNano
()))
})
Convey
(
"interpolate __unixEpochNanoTo function"
,
func
()
{
sql
,
err
:=
engine
.
Interpolate
(
query
,
timeRange
,
"select $__unixEpochNanoTo()"
)
So
(
err
,
ShouldBeNil
)
So
(
sql
,
ShouldEqual
,
fmt
.
Sprintf
(
"select '%d'"
,
to
.
UnixNano
()))
})
Convey
(
"interpolate __unixEpochGroup function"
,
func
()
{
Convey
(
"interpolate __unixEpochGroup 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