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
4e826ff8
Commit
4e826ff8
authored
Mar 02, 2018
by
Sven Klemm
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove spaces around arguments of macros
parent
f1ba9137
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
3 deletions
+15
-3
pkg/tsdb/mysql/macros.go
+7
-3
pkg/tsdb/mysql/macros_test.go
+8
-0
No files found.
pkg/tsdb/mysql/macros.go
View file @
4e826ff8
...
@@ -30,7 +30,11 @@ func (m *MySqlMacroEngine) Interpolate(query *tsdb.Query, timeRange *tsdb.TimeRa
...
@@ -30,7 +30,11 @@ func (m *MySqlMacroEngine) Interpolate(query *tsdb.Query, timeRange *tsdb.TimeRa
var
macroError
error
var
macroError
error
sql
=
replaceAllStringSubmatchFunc
(
rExp
,
sql
,
func
(
groups
[]
string
)
string
{
sql
=
replaceAllStringSubmatchFunc
(
rExp
,
sql
,
func
(
groups
[]
string
)
string
{
res
,
err
:=
m
.
evaluateMacro
(
groups
[
1
],
strings
.
Split
(
groups
[
2
],
","
))
args
:=
strings
.
Split
(
groups
[
2
],
","
)
for
i
,
arg
:=
range
args
{
args
[
i
]
=
strings
.
Trim
(
arg
,
" "
)
}
res
,
err
:=
m
.
evaluateMacro
(
groups
[
1
],
args
)
if
err
!=
nil
&&
macroError
==
nil
{
if
err
!=
nil
&&
macroError
==
nil
{
macroError
=
err
macroError
=
err
return
"macro_error()"
return
"macro_error()"
...
@@ -82,14 +86,14 @@ func (m *MySqlMacroEngine) evaluateMacro(name string, args []string) (string, er
...
@@ -82,14 +86,14 @@ func (m *MySqlMacroEngine) evaluateMacro(name string, args []string) (string, er
if
len
(
args
)
<
2
{
if
len
(
args
)
<
2
{
return
""
,
fmt
.
Errorf
(
"macro %v needs time column and interval"
,
name
)
return
""
,
fmt
.
Errorf
(
"macro %v needs time column and interval"
,
name
)
}
}
interval
,
err
:=
time
.
ParseDuration
(
strings
.
Trim
(
args
[
1
],
`'"
`
))
interval
,
err
:=
time
.
ParseDuration
(
strings
.
Trim
(
args
[
1
],
`'"`
))
if
err
!=
nil
{
if
err
!=
nil
{
return
""
,
fmt
.
Errorf
(
"error parsing interval %v"
,
args
[
1
])
return
""
,
fmt
.
Errorf
(
"error parsing interval %v"
,
args
[
1
])
}
}
if
len
(
args
)
==
3
{
if
len
(
args
)
==
3
{
m
.
Query
.
Model
.
Set
(
"fill"
,
true
)
m
.
Query
.
Model
.
Set
(
"fill"
,
true
)
m
.
Query
.
Model
.
Set
(
"fillInterval"
,
interval
.
Seconds
())
m
.
Query
.
Model
.
Set
(
"fillInterval"
,
interval
.
Seconds
())
if
strings
.
Trim
(
args
[
2
],
" "
)
==
"NULL"
{
if
args
[
2
]
==
"NULL"
{
m
.
Query
.
Model
.
Set
(
"fillNull"
,
true
)
m
.
Query
.
Model
.
Set
(
"fillNull"
,
true
)
}
else
{
}
else
{
floatVal
,
err
:=
strconv
.
ParseFloat
(
args
[
2
],
64
)
floatVal
,
err
:=
strconv
.
ParseFloat
(
args
[
2
],
64
)
...
...
pkg/tsdb/mysql/macros_test.go
View file @
4e826ff8
...
@@ -49,6 +49,14 @@ func TestMacroEngine(t *testing.T) {
...
@@ -49,6 +49,14 @@ func TestMacroEngine(t *testing.T) {
So
(
sql
,
ShouldEqual
,
"GROUP BY cast(cast(UNIX_TIMESTAMP(time_column)/(300) as signed)*300 as signed)"
)
So
(
sql
,
ShouldEqual
,
"GROUP BY cast(cast(UNIX_TIMESTAMP(time_column)/(300) as signed)*300 as signed)"
)
})
})
Convey
(
"interpolate __timeGroup function with spaces around arguments"
,
func
()
{
sql
,
err
:=
engine
.
Interpolate
(
query
,
timeRange
,
"GROUP BY $__timeGroup(time_column , '5m')"
)
So
(
err
,
ShouldBeNil
)
So
(
sql
,
ShouldEqual
,
"GROUP BY cast(cast(UNIX_TIMESTAMP(time_column)/(300) as signed)*300 as signed)"
)
})
Convey
(
"interpolate __timeTo function"
,
func
()
{
Convey
(
"interpolate __timeTo function"
,
func
()
{
sql
,
err
:=
engine
.
Interpolate
(
query
,
timeRange
,
"select $__timeTo(time_column)"
)
sql
,
err
:=
engine
.
Interpolate
(
query
,
timeRange
,
"select $__timeTo(time_column)"
)
So
(
err
,
ShouldBeNil
)
So
(
err
,
ShouldBeNil
)
...
...
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