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
e33d1870
Unverified
Commit
e33d1870
authored
Jun 15, 2018
by
Carl Bergquist
Committed by
GitHub
Jun 15, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #12287 from bergquist/fix_12286
Influxdb: add mode functions
parents
f0254c20
c63533f0
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
78 deletions
+33
-78
pkg/tsdb/influxdb/query_part.go
+1
-0
pkg/tsdb/influxdb/query_part_test.go
+32
-78
No files found.
pkg/tsdb/influxdb/query_part.go
View file @
e33d1870
...
...
@@ -31,6 +31,7 @@ func init() {
renders
[
"mean"
]
=
QueryDefinition
{
Renderer
:
functionRenderer
}
renders
[
"median"
]
=
QueryDefinition
{
Renderer
:
functionRenderer
}
renders
[
"sum"
]
=
QueryDefinition
{
Renderer
:
functionRenderer
}
renders
[
"mode"
]
=
QueryDefinition
{
Renderer
:
functionRenderer
}
renders
[
"holt_winters"
]
=
QueryDefinition
{
Renderer
:
functionRenderer
,
...
...
pkg/tsdb/influxdb/query_part_test.go
View file @
e33d1870
...
...
@@ -4,85 +4,39 @@ import (
"testing"
"github.com/grafana/grafana/pkg/tsdb"
.
"github.com/smartystreets/goconvey/convey"
)
func
TestInfluxdbQueryPart
(
t
*
testing
.
T
)
{
Convey
(
"Influxdb query parts"
,
t
,
func
()
{
queryContext
:=
&
tsdb
.
TsdbQuery
{
TimeRange
:
tsdb
.
NewTimeRange
(
"5m"
,
"now"
)}
query
:=
&
Query
{}
Convey
(
"render field "
,
func
()
{
part
,
err
:=
NewQueryPart
(
"field"
,
[]
string
{
"value"
})
So
(
err
,
ShouldBeNil
)
res
:=
part
.
Render
(
query
,
queryContext
,
"value"
)
So
(
res
,
ShouldEqual
,
`"value"`
)
})
Convey
(
"render nested part"
,
func
()
{
part
,
err
:=
NewQueryPart
(
"derivative"
,
[]
string
{
"10s"
})
So
(
err
,
ShouldBeNil
)
res
:=
part
.
Render
(
query
,
queryContext
,
"mean(value)"
)
So
(
res
,
ShouldEqual
,
"derivative(mean(value), 10s)"
)
})
Convey
(
"render bottom"
,
func
()
{
part
,
err
:=
NewQueryPart
(
"bottom"
,
[]
string
{
"3"
})
So
(
err
,
ShouldBeNil
)
res
:=
part
.
Render
(
query
,
queryContext
,
"value"
)
So
(
res
,
ShouldEqual
,
"bottom(value, 3)"
)
})
Convey
(
"render time with $interval"
,
func
()
{
part
,
err
:=
NewQueryPart
(
"time"
,
[]
string
{
"$interval"
})
So
(
err
,
ShouldBeNil
)
res
:=
part
.
Render
(
query
,
queryContext
,
""
)
So
(
res
,
ShouldEqual
,
"time($interval)"
)
})
Convey
(
"render time with auto"
,
func
()
{
part
,
err
:=
NewQueryPart
(
"time"
,
[]
string
{
"auto"
})
So
(
err
,
ShouldBeNil
)
res
:=
part
.
Render
(
query
,
queryContext
,
""
)
So
(
res
,
ShouldEqual
,
"time($__interval)"
)
})
Convey
(
"render spread"
,
func
()
{
part
,
err
:=
NewQueryPart
(
"spread"
,
[]
string
{})
So
(
err
,
ShouldBeNil
)
res
:=
part
.
Render
(
query
,
queryContext
,
"value"
)
So
(
res
,
ShouldEqual
,
`spread(value)`
)
})
Convey
(
"render suffix"
,
func
()
{
part
,
err
:=
NewQueryPart
(
"math"
,
[]
string
{
"/ 100"
})
So
(
err
,
ShouldBeNil
)
res
:=
part
.
Render
(
query
,
queryContext
,
"mean(value)"
)
So
(
res
,
ShouldEqual
,
"mean(value) / 100"
)
})
Convey
(
"render alias"
,
func
()
{
part
,
err
:=
NewQueryPart
(
"alias"
,
[]
string
{
"test"
})
So
(
err
,
ShouldBeNil
)
res
:=
part
.
Render
(
query
,
queryContext
,
"mean(value)"
)
So
(
res
,
ShouldEqual
,
`mean(value) AS "test"`
)
})
Convey
(
"render count distinct"
,
func
()
{
part
,
err
:=
NewQueryPart
(
"count"
,
[]
string
{})
So
(
err
,
ShouldBeNil
)
res
:=
part
.
Render
(
query
,
queryContext
,
"distinct(value)"
)
So
(
res
,
ShouldEqual
,
`count(distinct(value))`
)
})
})
tcs
:=
[]
struct
{
mode
string
input
string
params
[]
string
expected
string
}{
{
mode
:
"field"
,
params
:
[]
string
{
"value"
},
input
:
"value"
,
expected
:
`"value"`
},
{
mode
:
"derivative"
,
params
:
[]
string
{
"10s"
},
input
:
"mean(value)"
,
expected
:
`derivative(mean(value), 10s)`
},
{
mode
:
"bottom"
,
params
:
[]
string
{
"3"
},
input
:
"value"
,
expected
:
`bottom(value, 3)`
},
{
mode
:
"time"
,
params
:
[]
string
{
"$interval"
},
input
:
""
,
expected
:
`time($interval)`
},
{
mode
:
"time"
,
params
:
[]
string
{
"auto"
},
input
:
""
,
expected
:
`time($__interval)`
},
{
mode
:
"spread"
,
params
:
[]
string
{},
input
:
"value"
,
expected
:
`spread(value)`
},
{
mode
:
"math"
,
params
:
[]
string
{
"/ 100"
},
input
:
"mean(value)"
,
expected
:
`mean(value) / 100`
},
{
mode
:
"alias"
,
params
:
[]
string
{
"test"
},
input
:
"mean(value)"
,
expected
:
`mean(value) AS "test"`
},
{
mode
:
"count"
,
params
:
[]
string
{},
input
:
"distinct(value)"
,
expected
:
`count(distinct(value))`
},
{
mode
:
"mode"
,
params
:
[]
string
{},
input
:
"value"
,
expected
:
`mode(value)`
},
}
queryContext
:=
&
tsdb
.
TsdbQuery
{
TimeRange
:
tsdb
.
NewTimeRange
(
"5m"
,
"now"
)}
query
:=
&
Query
{}
for
_
,
tc
:=
range
tcs
{
part
,
err
:=
NewQueryPart
(
tc
.
mode
,
tc
.
params
)
if
err
!=
nil
{
t
.
Errorf
(
"Expected NewQueryPart to not return an error. error: %v"
,
err
)
}
res
:=
part
.
Render
(
query
,
queryContext
,
tc
.
input
)
if
res
!=
tc
.
expected
{
t
.
Errorf
(
"expected %v to render into %s"
,
tc
,
tc
.
expected
)
}
}
}
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