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
f4e0a924
Commit
f4e0a924
authored
Oct 14, 2016
by
bergquist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(influxdb): choose highest interval value
parent
4144eacc
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
4 deletions
+41
-4
pkg/tsdb/influxdb/query_part.go
+20
-4
pkg/tsdb/influxdb/query_part_test.go
+21
-0
No files found.
pkg/tsdb/influxdb/query_part.go
View file @
f4e0a924
...
@@ -3,6 +3,7 @@ package influxdb
...
@@ -3,6 +3,7 @@ package influxdb
import
(
import
(
"fmt"
"fmt"
"strings"
"strings"
"time"
"github.com/grafana/grafana/pkg/tsdb"
"github.com/grafana/grafana/pkg/tsdb"
)
)
...
@@ -92,12 +93,27 @@ func fieldRenderer(query *Query, queryContext *tsdb.QueryContext, part *QueryPar
...
@@ -92,12 +93,27 @@ func fieldRenderer(query *Query, queryContext *tsdb.QueryContext, part *QueryPar
return
fmt
.
Sprintf
(
`"%s"`
,
part
.
Params
[
0
])
return
fmt
.
Sprintf
(
`"%s"`
,
part
.
Params
[
0
])
}
}
func
getDefinedInterval
(
query
*
Query
,
queryContext
*
tsdb
.
QueryContext
)
string
{
setInterval
:=
strings
.
Replace
(
strings
.
Replace
(
query
.
Interval
,
"<"
,
""
,
1
),
">"
,
""
,
1
)
defaultInterval
:=
tsdb
.
CalculateInterval
(
queryContext
.
TimeRange
)
if
strings
.
Contains
(
query
.
Interval
,
">"
)
{
parsedDefaultInterval
,
err
:=
time
.
ParseDuration
(
defaultInterval
)
parsedSetInterval
,
err2
:=
time
.
ParseDuration
(
setInterval
)
if
err
==
nil
&&
err2
==
nil
&&
parsedDefaultInterval
>
parsedSetInterval
{
return
defaultInterval
}
}
return
setInterval
}
func
functionRenderer
(
query
*
Query
,
queryContext
*
tsdb
.
QueryContext
,
part
*
QueryPart
,
innerExpr
string
)
string
{
func
functionRenderer
(
query
*
Query
,
queryContext
*
tsdb
.
QueryContext
,
part
*
QueryPart
,
innerExpr
string
)
string
{
for
i
,
v
:=
range
part
.
Params
{
for
i
,
param
:=
range
part
.
Params
{
if
v
==
"$interval"
{
if
param
==
"$interval"
{
if
query
.
Interval
!=
""
{
if
query
.
Interval
!=
""
{
interval
:=
strings
.
Replace
(
strings
.
Replace
(
query
.
Interval
,
"<"
,
""
,
1
),
">"
,
""
,
1
)
part
.
Params
[
i
]
=
getDefinedInterval
(
query
,
queryContext
)
part
.
Params
[
i
]
=
interval
}
else
{
}
else
{
part
.
Params
[
i
]
=
tsdb
.
CalculateInterval
(
queryContext
.
TimeRange
)
part
.
Params
[
i
]
=
tsdb
.
CalculateInterval
(
queryContext
.
TimeRange
)
}
}
...
...
pkg/tsdb/influxdb/query_part_test.go
View file @
f4e0a924
...
@@ -45,6 +45,27 @@ func TestInfluxdbQueryPart(t *testing.T) {
...
@@ -45,6 +45,27 @@ func TestInfluxdbQueryPart(t *testing.T) {
So
(
res
,
ShouldEqual
,
"time(200ms)"
)
So
(
res
,
ShouldEqual
,
"time(200ms)"
)
})
})
Convey
(
"render time interval >10s"
,
func
()
{
part
,
err
:=
NewQueryPart
(
"time"
,
[]
string
{
"$interval"
})
So
(
err
,
ShouldBeNil
)
query
.
Interval
=
">10s"
res
:=
part
.
Render
(
query
,
queryContext
,
""
)
So
(
res
,
ShouldEqual
,
"time(10s)"
)
})
Convey
(
"render time interval >1s and higher interval calculation"
,
func
()
{
part
,
err
:=
NewQueryPart
(
"time"
,
[]
string
{
"$interval"
})
queryContext
:=
&
tsdb
.
QueryContext
{
TimeRange
:
tsdb
.
NewTimeRange
(
"1y"
,
"now"
)}
So
(
err
,
ShouldBeNil
)
query
.
Interval
=
">1s"
res
:=
part
.
Render
(
query
,
queryContext
,
""
)
So
(
res
,
ShouldEqual
,
"time(168h)"
)
})
Convey
(
"render spread"
,
func
()
{
Convey
(
"render spread"
,
func
()
{
part
,
err
:=
NewQueryPart
(
"spread"
,
[]
string
{})
part
,
err
:=
NewQueryPart
(
"spread"
,
[]
string
{})
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