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
23a136d9
Commit
23a136d9
authored
Mar 01, 2016
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(templating): moved template interpolation into query building
parent
2d9a2506
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
30 additions
and
22 deletions
+30
-22
public/app/plugins/datasource/influxdb/datasource.ts
+2
-2
public/app/plugins/datasource/influxdb/influx_query.ts
+9
-2
public/app/plugins/datasource/influxdb/query_ctrl.ts
+1
-1
public/app/plugins/datasource/influxdb/specs/influx_query_specs.ts
+18
-17
No files found.
public/app/plugins/datasource/influxdb/datasource.ts
View file @
23a136d9
...
...
@@ -34,7 +34,7 @@ export function InfluxDatasource(instanceSettings, $q, backendSrv, templateSrv)
queryTargets
.
push
(
target
);
// build query
var
queryModel
=
new
InfluxQuery
(
target
);
var
queryModel
=
new
InfluxQuery
(
target
,
templateSrv
,
options
.
scopedVars
);
var
query
=
queryModel
.
render
();
query
=
query
.
replace
(
/
\$
interval/g
,
(
target
.
interval
||
options
.
interval
));
return
query
;
...
...
@@ -45,7 +45,7 @@ export function InfluxDatasource(instanceSettings, $q, backendSrv, templateSrv)
allQueries
=
allQueries
.
replace
(
/
\$
timeFilter/g
,
timeFilter
);
// replace templated variables
allQueries
=
templateSrv
.
replace
(
allQueries
,
options
.
scopedVars
,
'regex'
);
allQueries
=
templateSrv
.
replace
(
allQueries
,
options
.
scopedVars
);
return
this
.
_seriesQuery
(
allQueries
).
then
(
function
(
data
):
any
{
if
(
!
data
||
!
data
.
results
)
{
...
...
public/app/plugins/datasource/influxdb/influx_query.ts
View file @
23a136d9
...
...
@@ -8,9 +8,13 @@ export default class InfluxQuery {
selectModels
:
any
[];
queryBuilder
:
any
;
groupByParts
:
any
;
templateSrv
:
any
;
scopedVars
:
any
;
constructor
(
target
)
{
constructor
(
target
,
templateSrv
,
scopedVars
)
{
this
.
target
=
target
;
this
.
templateSrv
=
templateSrv
;
this
.
scopedVars
=
scopedVars
;
target
.
policy
=
target
.
policy
||
'default'
;
target
.
dsType
=
'influxdb'
;
...
...
@@ -135,7 +139,7 @@ export default class InfluxQuery {
}
if
(
!
operator
)
{
if
(
/^
\/
.*
\/
$/
.
test
(
tag
.
value
))
{
if
(
/^
\/
.*
\/
$/
.
test
(
value
))
{
operator
=
'=~'
;
}
else
{
operator
=
'='
;
...
...
@@ -144,7 +148,10 @@ export default class InfluxQuery {
// quote value unless regex
if
(
operator
!==
'=~'
&&
operator
!==
'!~'
)
{
value
=
this
.
templateSrv
.
replace
(
value
,
this
.
scopedVars
);
value
=
"'"
+
value
.
replace
(
'
\
\'
, '
\\\\
') + "'
";
} else {
value = this.templateSrv.replace(value, this.scopedVars, 'regex');
}
return str + '"
' + tag.key + '
" ' + operator + ' ' + value;
...
...
public/app/plugins/datasource/influxdb/query_ctrl.ts
View file @
23a136d9
...
...
@@ -28,7 +28,7 @@ export class InfluxQueryCtrl extends QueryCtrl {
super
(
$scope
,
$injector
);
this
.
target
=
this
.
target
;
this
.
queryModel
=
new
InfluxQuery
(
this
.
target
);
this
.
queryModel
=
new
InfluxQuery
(
this
.
target
,
templateSrv
,
this
.
panel
.
scopedVars
);
this
.
queryBuilder
=
new
InfluxQueryBuilder
(
this
.
target
,
this
.
datasource
.
database
);
this
.
groupBySegment
=
this
.
uiSegmentSrv
.
newPlusButton
();
this
.
resultFormats
=
[
...
...
public/app/plugins/datasource/influxdb/specs/influx_query_specs.ts
View file @
23a136d9
...
...
@@ -3,12 +3,13 @@ import {describe, beforeEach, it, sinon, expect} from 'test/lib/common';
import
InfluxQuery
from
'../influx_query'
;
describe
(
'InfluxQuery'
,
function
()
{
var
templateSrv
=
{
replace
:
val
=>
val
};
describe
(
'render series with mesurement only'
,
function
()
{
it
(
'should generate correct query'
,
function
()
{
var
query
=
new
InfluxQuery
({
measurement
:
'cpu'
,
});
}
,
templateSrv
,
{}
);
var
queryText
=
query
.
render
();
expect
(
queryText
).
to
.
be
(
'SELECT mean("value") FROM "cpu" WHERE $timeFilter GROUP BY time($interval) fill(null)'
);
...
...
@@ -20,7 +21,7 @@ describe('InfluxQuery', function() {
var
query
=
new
InfluxQuery
({
measurement
:
'cpu'
,
policy
:
'5m_avg'
});
}
,
templateSrv
,
{}
);
var
queryText
=
query
.
render
();
expect
(
queryText
).
to
.
be
(
'SELECT mean("value") FROM "5m_avg"."cpu" WHERE $timeFilter GROUP BY time($interval) fill(null)'
);
...
...
@@ -39,7 +40,7 @@ describe('InfluxQuery', function() {
{
type
:
'alias'
,
params
:
[
'text'
]},
]
]
});
}
,
templateSrv
,
{}
);
var
queryText
=
query
.
render
();
expect
(
queryText
).
to
.
be
(
'SELECT mean("value") /100 AS "text" FROM "cpu" WHERE $timeFilter GROUP BY time($interval) fill(null)'
);
...
...
@@ -52,7 +53,7 @@ describe('InfluxQuery', function() {
measurement
:
'cpu'
,
groupBy
:
[{
type
:
'time'
,
params
:
[
'auto'
]}],
tags
:
[{
key
:
'hostname'
,
value
:
'server
\\
1'
}]
});
}
,
templateSrv
,
{}
);
var
queryText
=
query
.
render
();
...
...
@@ -65,7 +66,7 @@ describe('InfluxQuery', function() {
measurement
:
'cpu'
,
groupBy
:
[{
type
:
'time'
,
params
:
[
'auto'
]}],
tags
:
[{
key
:
'app'
,
value
:
'/e.*/'
}]
});
}
,
templateSrv
,
{}
);
var
queryText
=
query
.
render
();
expect
(
queryText
).
to
.
be
(
'SELECT mean("value") FROM "cpu" WHERE "app" =~ /e.*/ AND $timeFilter GROUP BY time($interval)'
);
...
...
@@ -78,7 +79,7 @@ describe('InfluxQuery', function() {
measurement
:
'cpu'
,
groupBy
:
[{
type
:
'time'
,
params
:
[
'auto'
]}],
tags
:
[{
key
:
'hostname'
,
value
:
'server1'
},
{
key
:
'app'
,
value
:
'email'
,
condition
:
"AND"
}]
});
}
,
templateSrv
,
{}
);
var
queryText
=
query
.
render
();
expect
(
queryText
).
to
.
be
(
'SELECT mean("value") FROM "cpu" WHERE "hostname" =
\'
server1
\'
AND "app" =
\'
email
\'
AND '
+
...
...
@@ -92,7 +93,7 @@ describe('InfluxQuery', function() {
measurement
:
'cpu'
,
groupBy
:
[{
type
:
'time'
,
params
:
[
'auto'
]}],
tags
:
[{
key
:
'hostname'
,
value
:
'server1'
},
{
key
:
'hostname'
,
value
:
'server2'
,
condition
:
"OR"
}]
});
}
,
templateSrv
,
{}
);
var
queryText
=
query
.
render
();
expect
(
queryText
).
to
.
be
(
'SELECT mean("value") FROM "cpu" WHERE "hostname" =
\'
server1
\'
OR "hostname" =
\'
server2
\'
AND '
+
...
...
@@ -106,7 +107,7 @@ describe('InfluxQuery', function() {
measurement
:
'cpu'
,
tags
:
[],
groupBy
:
[{
type
:
'time'
,
interval
:
'auto'
},
{
type
:
'tag'
,
params
:
[
'host'
]}],
});
}
,
templateSrv
,
{}
);
var
queryText
=
query
.
render
();
expect
(
queryText
).
to
.
be
(
'SELECT mean("value") FROM "cpu" WHERE $timeFilter '
+
...
...
@@ -120,7 +121,7 @@ describe('InfluxQuery', function() {
measurement
:
'cpu'
,
select
:
[[{
type
:
'field'
,
params
:
[
'value'
]}]],
groupBy
:
[],
});
}
,
templateSrv
,
{}
);
var
queryText
=
query
.
render
();
expect
(
queryText
).
to
.
be
(
'SELECT "value" FROM "cpu" WHERE $timeFilter'
);
});
...
...
@@ -132,7 +133,7 @@ describe('InfluxQuery', function() {
measurement
:
'cpu'
,
select
:
[[{
type
:
'field'
,
params
:
[
'value'
]}]],
groupBy
:
[{
type
:
'time'
},
{
type
:
'fill'
,
params
:
[
'0'
]}],
});
}
,
templateSrv
,
{}
);
var
queryText
=
query
.
render
();
expect
(
queryText
).
to
.
be
(
'SELECT "value" FROM "cpu" WHERE $timeFilter GROUP BY time($interval) fill(0)'
);
});
...
...
@@ -144,7 +145,7 @@ describe('InfluxQuery', function() {
var
query
=
new
InfluxQuery
({
measurement
:
'cpu'
,
groupBy
:
[{
type
:
'time'
},
{
type
:
'fill'
}]
});
}
,
templateSrv
,
{}
);
query
.
addGroupBy
(
'tag(host)'
);
expect
(
query
.
target
.
groupBy
.
length
).
to
.
be
(
3
);
...
...
@@ -157,7 +158,7 @@ describe('InfluxQuery', function() {
var
query
=
new
InfluxQuery
({
measurement
:
'cpu'
,
groupBy
:
[]
});
}
,
templateSrv
,
{}
);
query
.
addGroupBy
(
'tag(host)'
);
expect
(
query
.
target
.
groupBy
.
length
).
to
.
be
(
1
);
...
...
@@ -172,7 +173,7 @@ describe('InfluxQuery', function() {
var
query
=
new
InfluxQuery
({
measurement
:
'cpu'
,
select
:
[[{
type
:
'field'
,
params
:
[
'value'
]}]]
});
}
,
templateSrv
,
{}
);
query
.
addSelectPart
(
query
.
selectModels
[
0
],
'mean'
);
expect
(
query
.
target
.
select
[
0
].
length
).
to
.
be
(
2
);
...
...
@@ -183,7 +184,7 @@ describe('InfluxQuery', function() {
var
query
=
new
InfluxQuery
({
measurement
:
'cpu'
,
select
:
[[{
type
:
'field'
,
params
:
[
'value'
]},
{
type
:
'mean'
}]]
});
}
,
templateSrv
,
{}
);
query
.
addSelectPart
(
query
.
selectModels
[
0
],
'sum'
);
expect
(
query
.
target
.
select
[
0
].
length
).
to
.
be
(
2
);
...
...
@@ -194,7 +195,7 @@ describe('InfluxQuery', function() {
var
query
=
new
InfluxQuery
({
measurement
:
'cpu'
,
select
:
[[{
type
:
'field'
,
params
:
[
'value'
]},
{
type
:
'mean'
},
{
type
:
'alias'
}]]
});
}
,
templateSrv
,
{}
);
query
.
addSelectPart
(
query
.
selectModels
[
0
],
'math'
);
expect
(
query
.
target
.
select
[
0
].
length
).
to
.
be
(
4
);
...
...
@@ -205,7 +206,7 @@ describe('InfluxQuery', function() {
var
query
=
new
InfluxQuery
({
measurement
:
'cpu'
,
select
:
[[{
type
:
'field'
,
params
:
[
'value'
]},
{
type
:
'mean'
}]]
});
}
,
templateSrv
,
{}
);
query
.
addSelectPart
(
query
.
selectModels
[
0
],
'math'
);
expect
(
query
.
target
.
select
[
0
].
length
).
to
.
be
(
3
);
...
...
@@ -216,7 +217,7 @@ describe('InfluxQuery', function() {
var
query
=
new
InfluxQuery
({
measurement
:
'cpu'
,
select
:
[[{
type
:
'field'
,
params
:
[
'value'
]},
{
type
:
'mean'
},
{
type
:
'math'
}]]
});
}
,
templateSrv
,
{}
);
query
.
addSelectPart
(
query
.
selectModels
[
0
],
'math'
);
expect
(
query
.
target
.
select
[
0
].
length
).
to
.
be
(
3
);
...
...
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