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
c29c9d16
Commit
c29c9d16
authored
Dec 21, 2018
by
Clément MATHIEU
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support for InfluxDB's time zone clause (backend)
parent
41eb0ba5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
29 additions
and
0 deletions
+29
-0
pkg/tsdb/influxdb/model_parser.go
+2
-0
pkg/tsdb/influxdb/model_parser_test.go
+2
-0
pkg/tsdb/influxdb/models.go
+1
-0
pkg/tsdb/influxdb/query.go
+10
-0
pkg/tsdb/influxdb/query_test.go
+14
-0
No files found.
pkg/tsdb/influxdb/model_parser.go
View file @
c29c9d16
...
...
@@ -16,6 +16,7 @@ func (qp *InfluxdbQueryParser) Parse(model *simplejson.Json, dsInfo *models.Data
rawQuery
:=
model
.
Get
(
"query"
)
.
MustString
(
""
)
useRawQuery
:=
model
.
Get
(
"rawQuery"
)
.
MustBool
(
false
)
alias
:=
model
.
Get
(
"alias"
)
.
MustString
(
""
)
tz
:=
model
.
Get
(
"tz"
)
.
MustString
(
""
)
measurement
:=
model
.
Get
(
"measurement"
)
.
MustString
(
""
)
...
...
@@ -55,6 +56,7 @@ func (qp *InfluxdbQueryParser) Parse(model *simplejson.Json, dsInfo *models.Data
Interval
:
parsedInterval
,
Alias
:
alias
,
UseRawQuery
:
useRawQuery
,
Tz
:
tz
,
},
nil
}
...
...
pkg/tsdb/influxdb/model_parser_test.go
View file @
c29c9d16
...
...
@@ -41,6 +41,7 @@ func TestInfluxdbQueryParser(t *testing.T) {
}
],
"measurement": "logins.count",
"tz": "Europe/Paris",
"policy": "default",
"refId": "B",
"resultFormat": "time_series",
...
...
@@ -115,6 +116,7 @@ func TestInfluxdbQueryParser(t *testing.T) {
So
(
len
(
res
.
GroupBy
),
ShouldEqual
,
3
)
So
(
len
(
res
.
Selects
),
ShouldEqual
,
3
)
So
(
len
(
res
.
Tags
),
ShouldEqual
,
2
)
So
(
res
.
Tz
,
ShouldEqual
,
"Europe/Paris"
)
So
(
res
.
Interval
,
ShouldEqual
,
time
.
Second
*
20
)
So
(
res
.
Alias
,
ShouldEqual
,
"serie alias"
)
})
...
...
pkg/tsdb/influxdb/models.go
View file @
c29c9d16
...
...
@@ -13,6 +13,7 @@ type Query struct {
UseRawQuery
bool
Alias
string
Interval
time
.
Duration
Tz
string
}
type
Tag
struct
{
...
...
pkg/tsdb/influxdb/query.go
View file @
c29c9d16
...
...
@@ -26,6 +26,7 @@ func (query *Query) Build(queryContext *tsdb.TsdbQuery) (string, error) {
res
+=
query
.
renderWhereClause
()
res
+=
query
.
renderTimeFilter
(
queryContext
)
res
+=
query
.
renderGroupBy
(
queryContext
)
res
+=
query
.
renderTz
()
}
calculator
:=
tsdb
.
NewIntervalCalculator
(
&
tsdb
.
IntervalOptions
{})
...
...
@@ -154,3 +155,12 @@ func (query *Query) renderGroupBy(queryContext *tsdb.TsdbQuery) string {
return
groupBy
}
func
(
query
*
Query
)
renderTz
()
string
{
tz
:=
query
.
Tz
if
tz
==
""
{
return
""
}
else
{
return
fmt
.
Sprintf
(
" tz('%s')"
,
tz
)
}
}
pkg/tsdb/influxdb/query_test.go
View file @
c29c9d16
...
...
@@ -47,6 +47,20 @@ func TestInfluxdbQueryBuilder(t *testing.T) {
So
(
rawQuery
,
ShouldEqual
,
`SELECT mean("value") FROM "policy"."cpu" WHERE time > now() - 5m GROUP BY time(10s) fill(null)`
)
})
Convey
(
"can build query with tz"
,
func
()
{
query
:=
&
Query
{
Selects
:
[]
*
Select
{{
*
qp1
,
*
qp2
}},
Measurement
:
"cpu"
,
GroupBy
:
[]
*
QueryPart
{
groupBy1
},
Tz
:
"Europe/Paris"
,
Interval
:
time
.
Second
*
5
,
}
rawQuery
,
err
:=
query
.
Build
(
queryContext
)
So
(
err
,
ShouldBeNil
)
So
(
rawQuery
,
ShouldEqual
,
`SELECT mean("value") FROM "cpu" WHERE time > now() - 5m GROUP BY time(5s) tz('Europe/Paris')`
)
})
Convey
(
"can build query with group bys"
,
func
()
{
query
:=
&
Query
{
Selects
:
[]
*
Select
{{
*
qp1
,
*
qp2
}},
...
...
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