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
80574334
Commit
80574334
authored
Sep 04, 2014
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Changed variable replacement works for InfluxDB, now , and
parent
dd4eaa07
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
16 additions
and
52 deletions
+16
-52
src/app/partials/influxdb/annotation_editor.html
+2
-2
src/app/services/influxdb/influxQueryBuilder.js
+2
-21
src/app/services/influxdb/influxdbDatasource.js
+6
-3
src/test/specs/influxQueryBuilder-specs.js
+4
-24
src/test/specs/influxdb-datasource-specs.js
+2
-2
No files found.
src/app/partials/influxdb/annotation_editor.html
View file @
80574334
<div
class=
"editor-row"
>
<div
class=
"editor-row"
>
<div
class=
"section"
>
<div
class=
"section"
>
<h5>
InfluxDB Query
<tip>
Example: select text from events where
[[$timeFilter]]
</tip></h5>
<h5>
InfluxDB Query
<tip>
Example: select text from events where
$timeFilter
</tip></h5>
<div
class=
"editor-option"
>
<div
class=
"editor-option"
>
<input
type=
"text"
class=
"span10"
ng-model=
'currentAnnotation.query'
placeholder=
"select text from events where
[[$timeFilter]]
"
></input>
<input
type=
"text"
class=
"span10"
ng-model=
'currentAnnotation.query'
placeholder=
"select text from events where
$timeFilter
"
></input>
</div>
</div>
</div>
</div>
</div>
</div>
...
...
src/app/services/influxdb/influxQueryBuilder.js
View file @
80574334
...
@@ -27,13 +27,13 @@ function () {
...
@@ -27,13 +27,13 @@ function () {
}
}
query
+=
target
.
function
+
'('
+
target
.
column
+
')'
;
query
+=
target
.
function
+
'('
+
target
.
column
+
')'
;
query
+=
' from '
+
seriesName
+
' where
[[$timeFilter]]
'
;
query
+=
' from '
+
seriesName
+
' where
$timeFilter
'
;
if
(
target
.
condition
)
{
if
(
target
.
condition
)
{
query
+=
' and '
+
target
.
condition
;
query
+=
' and '
+
target
.
condition
;
}
}
query
+=
' group by time(
[[$interval]]
)'
;
query
+=
' group by time(
$interval
)'
;
if
(
target
.
groupby_field
)
{
if
(
target
.
groupby_field
)
{
query
+=
', '
+
target
.
groupby_field
;
query
+=
', '
+
target
.
groupby_field
;
...
@@ -55,30 +55,11 @@ function () {
...
@@ -55,30 +55,11 @@ function () {
var
queryElements
=
query
.
split
(
" "
);
var
queryElements
=
query
.
split
(
" "
);
var
lowerCaseQueryElements
=
query
.
toLowerCase
().
split
(
" "
);
var
lowerCaseQueryElements
=
query
.
toLowerCase
().
split
(
" "
);
var
whereIndex
=
lowerCaseQueryElements
.
indexOf
(
"where"
);
var
groupByIndex
=
lowerCaseQueryElements
.
indexOf
(
"group"
);
var
orderIndex
=
lowerCaseQueryElements
.
indexOf
(
"order"
);
if
(
lowerCaseQueryElements
[
1
].
indexOf
(
','
)
!==
-
1
)
{
if
(
lowerCaseQueryElements
[
1
].
indexOf
(
','
)
!==
-
1
)
{
this
.
groupByField
=
lowerCaseQueryElements
[
1
].
replace
(
','
,
''
);
this
.
groupByField
=
lowerCaseQueryElements
[
1
].
replace
(
','
,
''
);
}
}
if
(
whereIndex
!==
-
1
)
{
queryElements
.
splice
(
whereIndex
+
1
,
0
,
'[[$timeFilter]]'
,
"and"
);
}
else
{
if
(
groupByIndex
!==
-
1
)
{
queryElements
.
splice
(
groupByIndex
,
0
,
"where"
,
'[[$timeFilter]]'
);
}
else
if
(
orderIndex
!==
-
1
)
{
queryElements
.
splice
(
orderIndex
,
0
,
"where"
,
'[[$timeFilter]]'
);
}
else
{
queryElements
.
push
(
"where"
);
queryElements
.
push
(
'[[$timeFilter]]'
);
}
}
return
queryElements
.
join
(
" "
);
return
queryElements
.
join
(
" "
);
};
};
...
...
src/app/services/influxdb/influxdbDatasource.js
View file @
80574334
...
@@ -44,9 +44,11 @@ function (angular, _, kbn, InfluxSeries, InfluxQueryBuilder) {
...
@@ -44,9 +44,11 @@ function (angular, _, kbn, InfluxSeries, InfluxQueryBuilder) {
var
queryBuilder
=
new
InfluxQueryBuilder
(
target
);
var
queryBuilder
=
new
InfluxQueryBuilder
(
target
);
var
query
=
queryBuilder
.
build
();
var
query
=
queryBuilder
.
build
();
// replace grafana variables
query
=
query
.
replace
(
'$timeFilter'
,
timeFilter
);
query
=
query
.
replace
(
'$interval'
,
(
target
.
interval
||
options
.
interval
));
// replace templated variables
// replace templated variables
templateSrv
.
setGrafanaVariable
(
'$timeFilter'
,
timeFilter
);
templateSrv
.
setGrafanaVariable
(
'$interval'
,
(
target
.
interval
||
options
.
interval
));
query
=
templateSrv
.
replace
(
query
);
query
=
templateSrv
.
replace
(
query
);
var
alias
=
target
.
alias
?
templateSrv
.
replace
(
target
.
alias
)
:
''
;
var
alias
=
target
.
alias
?
templateSrv
.
replace
(
target
.
alias
)
:
''
;
...
@@ -63,7 +65,8 @@ function (angular, _, kbn, InfluxSeries, InfluxQueryBuilder) {
...
@@ -63,7 +65,8 @@ function (angular, _, kbn, InfluxSeries, InfluxQueryBuilder) {
InfluxDatasource
.
prototype
.
annotationQuery
=
function
(
annotation
,
rangeUnparsed
)
{
InfluxDatasource
.
prototype
.
annotationQuery
=
function
(
annotation
,
rangeUnparsed
)
{
var
timeFilter
=
getTimeFilter
({
range
:
rangeUnparsed
});
var
timeFilter
=
getTimeFilter
({
range
:
rangeUnparsed
});
var
query
=
_
.
template
(
annotation
.
query
,
{
timeFilter
:
timeFilter
,
"$timeFilter"
:
timeFilter
},
this
.
templateSettings
);
var
query
=
annotation
.
query
.
replace
(
'$timeFilter'
,
timeFilter
);
query
=
templateSrv
.
replace
(
annotation
.
query
);
return
this
.
_seriesQuery
(
query
).
then
(
function
(
results
)
{
return
this
.
_seriesQuery
(
query
).
then
(
function
(
results
)
{
return
new
InfluxSeries
({
seriesList
:
results
,
annotation
:
annotation
}).
getAnnotations
();
return
new
InfluxSeries
({
seriesList
:
results
,
annotation
:
annotation
}).
getAnnotations
();
...
...
src/test/specs/influxQueryBuilder-specs.js
View file @
80574334
...
@@ -17,8 +17,8 @@ define([
...
@@ -17,8 +17,8 @@ define([
var
query
=
builder
.
build
();
var
query
=
builder
.
build
();
it
(
'should generate correct query'
,
function
()
{
it
(
'should generate correct query'
,
function
()
{
expect
(
query
).
to
.
be
(
'select code, mean(value) from "google.test" where
[[$timeFilter]]
and code=1 '
+
expect
(
query
).
to
.
be
(
'select code, mean(value) from "google.test" where
$timeFilter
and code=1 '
+
'group by time(
[[$interval]]
), code order asc'
);
'group by time(
$interval
), code order asc'
);
});
});
it
(
'should expose groupByFiled'
,
function
()
{
it
(
'should expose groupByFiled'
,
function
()
{
...
@@ -38,32 +38,12 @@ define([
...
@@ -38,32 +38,12 @@ define([
var
query
=
builder
.
build
();
var
query
=
builder
.
build
();
it
(
'should generate correct query'
,
function
()
{
it
(
'should generate correct query'
,
function
()
{
expect
(
query
).
to
.
be
(
'select mean(value) from "google.test" where
[[$timeFilter]]
'
+
expect
(
query
).
to
.
be
(
'select mean(value) from "google.test" where
$timeFilter
'
+
'group by time(
[[$interval]]
) fill(0) order asc'
);
'group by time(
$interval
) fill(0) order asc'
);
});
});
});
});
describe
(
'old style raw query'
,
function
()
{
var
builder
=
new
InfluxQueryBuilder
({
query
:
'select host, mean(value) from asd.asd where time > now() - 1h group by time(1s), code order asc'
,
rawQuery
:
true
});
var
query
=
builder
.
build
();
it
(
'should generate correct query'
,
function
()
{
expect
(
query
).
to
.
be
(
'select host, mean(value) from asd.asd where [[$timeFilter]] and time > now() - 1h '
+
'group by time(1s), code order asc'
);
});
it
(
'should expose groupByFiled'
,
function
()
{
expect
(
builder
.
groupByField
).
to
.
be
(
'host'
);
});
});
});
});
});
});
src/test/specs/influxdb-datasource-specs.js
View file @
80574334
...
@@ -50,10 +50,10 @@ define([
...
@@ -50,10 +50,10 @@ define([
describe
(
'When querying influxdb with one raw query'
,
function
()
{
describe
(
'When querying influxdb with one raw query'
,
function
()
{
var
results
;
var
results
;
var
urlExpected
=
"/series?p=mupp&q=select+value+from+series"
+
var
urlExpected
=
"/series?p=mupp&q=select+value+from+series"
+
"+where+time+%3E+now()+-+1h
+and+time+%3E+1
&time_precision=s"
;
"+where+time+%3E+now()+-+1h&time_precision=s"
;
var
query
=
{
var
query
=
{
range
:
{
from
:
'now-1h'
,
to
:
'now'
},
range
:
{
from
:
'now-1h'
,
to
:
'now'
},
targets
:
[{
query
:
"select value from series where
time > 1
"
,
rawQuery
:
true
}]
targets
:
[{
query
:
"select value from series where
$timeFilter
"
,
rawQuery
:
true
}]
};
};
var
response
=
[];
var
response
=
[];
...
...
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