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
dc22e246
Commit
dc22e246
authored
Aug 01, 2018
by
Sven Klemm
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add compatibility code to handle pre 5.3 usage
parent
42f18928
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
3 deletions
+33
-3
pkg/tsdb/postgres/macros.go
+17
-0
pkg/tsdb/postgres/macros_test.go
+16
-3
No files found.
pkg/tsdb/postgres/macros.go
View file @
dc22e246
...
@@ -30,6 +30,23 @@ func (m *postgresMacroEngine) Interpolate(query *tsdb.Query, timeRange *tsdb.Tim
...
@@ -30,6 +30,23 @@ func (m *postgresMacroEngine) Interpolate(query *tsdb.Query, timeRange *tsdb.Tim
var
macroError
error
var
macroError
error
sql
=
replaceAllStringSubmatchFunc
(
rExp
,
sql
,
func
(
groups
[]
string
)
string
{
sql
=
replaceAllStringSubmatchFunc
(
rExp
,
sql
,
func
(
groups
[]
string
)
string
{
// detect if $__timeGroup is supposed to add AS time for pre 5.3 compatibility
// if there is a ',' directly after the macro call $__timeGroup is probably used
// in the old way. Inside window function ORDER BY $__timeGroup will be followed
// by ')'
if
groups
[
1
]
==
"__timeGroup"
{
if
index
:=
strings
.
Index
(
sql
,
groups
[
0
]);
index
>=
0
{
index
+=
len
(
groups
[
0
])
if
len
(
sql
)
>
index
{
// check for character after macro expression
if
sql
[
index
]
==
','
{
groups
[
1
]
=
"__timeGroupAlias"
}
}
}
}
args
:=
strings
.
Split
(
groups
[
2
],
","
)
args
:=
strings
.
Split
(
groups
[
2
],
","
)
for
i
,
arg
:=
range
args
{
for
i
,
arg
:=
range
args
{
args
[
i
]
=
strings
.
Trim
(
arg
,
" "
)
args
[
i
]
=
strings
.
Trim
(
arg
,
" "
)
...
...
pkg/tsdb/postgres/macros_test.go
View file @
dc22e246
...
@@ -48,14 +48,27 @@ func TestMacroEngine(t *testing.T) {
...
@@ -48,14 +48,27 @@ func TestMacroEngine(t *testing.T) {
So
(
sql
,
ShouldEqual
,
fmt
.
Sprintf
(
"select '%s'"
,
from
.
Format
(
time
.
RFC3339
)))
So
(
sql
,
ShouldEqual
,
fmt
.
Sprintf
(
"select '%s'"
,
from
.
Format
(
time
.
RFC3339
)))
})
})
Convey
(
"interpolate __timeGroup function pre 5.3 compatibility"
,
func
()
{
sql
,
err
:=
engine
.
Interpolate
(
query
,
timeRange
,
"SELECT $__timeGroup(time_column,'5m'), value"
)
So
(
err
,
ShouldBeNil
)
So
(
sql
,
ShouldEqual
,
"SELECT floor(extract(epoch from time_column)/300)*300 AS
\"
time
\"
, value"
)
sql
,
err
=
engine
.
Interpolate
(
query
,
timeRange
,
"SELECT $__timeGroup(time_column,'5m') as time, value"
)
So
(
err
,
ShouldBeNil
)
So
(
sql
,
ShouldEqual
,
"SELECT floor(extract(epoch from time_column)/300)*300 as time, value"
)
})
Convey
(
"interpolate __timeGroup function"
,
func
()
{
Convey
(
"interpolate __timeGroup function"
,
func
()
{
sql
,
err
:=
engine
.
Interpolate
(
query
,
timeRange
,
"$__timeGroup(time_column,'5m')"
)
sql
,
err
:=
engine
.
Interpolate
(
query
,
timeRange
,
"
SELECT
$__timeGroup(time_column,'5m')"
)
So
(
err
,
ShouldBeNil
)
So
(
err
,
ShouldBeNil
)
sql2
,
err
:=
engine
.
Interpolate
(
query
,
timeRange
,
"$__timeGroupAlias(time_column,'5m')"
)
sql2
,
err
:=
engine
.
Interpolate
(
query
,
timeRange
,
"
SELECT
$__timeGroupAlias(time_column,'5m')"
)
So
(
err
,
ShouldBeNil
)
So
(
err
,
ShouldBeNil
)
So
(
sql
,
ShouldEqual
,
"floor(extract(epoch from time_column)/300)*300"
)
So
(
sql
,
ShouldEqual
,
"
SELECT
floor(extract(epoch from time_column)/300)*300"
)
So
(
sql2
,
ShouldEqual
,
sql
+
" AS
\"
time
\"
"
)
So
(
sql2
,
ShouldEqual
,
sql
+
" AS
\"
time
\"
"
)
})
})
...
...
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