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
e2188373
Commit
e2188373
authored
Jan 09, 2017
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
began work on built in template variables, #7190
parent
e57c7644
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
30 additions
and
23 deletions
+30
-23
public/app/features/panel/metrics_panel_ctrl.ts
+8
-1
public/app/features/templating/specs/template_srv_specs.ts
+12
-0
public/app/features/templating/templateSrv.js
+3
-3
public/app/plugins/datasource/elasticsearch/datasource.js
+2
-14
public/app/plugins/datasource/elasticsearch/query_builder.js
+2
-2
public/app/plugins/datasource/influxdb/datasource.ts
+3
-3
No files found.
public/app/features/panel/metrics_panel_ctrl.ts
View file @
e2188373
...
...
@@ -191,6 +191,13 @@ class MetricsPanelCtrl extends PanelCtrl {
return
this
.
$q
.
when
([]);
}
// make shallow copy of scoped vars,
// and add built in variables interval and interval_ms
var
scopedVars
=
Object
.
assign
({},
this
.
panel
.
scopedVars
,
{
"__interval"
:
{
text
:
this
.
interval
,
value
:
this
.
interval
},
"__interval_ms"
:
{
text
:
this
.
intervalMs
,
value
:
this
.
intervalMs
},
});
var
metricsQuery
=
{
panelId
:
this
.
panel
.
id
,
range
:
this
.
range
,
...
...
@@ -200,7 +207,7 @@ class MetricsPanelCtrl extends PanelCtrl {
targets
:
this
.
panel
.
targets
,
format
:
this
.
panel
.
renderer
===
'png'
?
'png'
:
'json'
,
maxDataPoints
:
this
.
resolution
,
scopedVars
:
this
.
panel
.
scopedVars
,
scopedVars
:
scopedVars
,
cacheTimeout
:
this
.
panel
.
cacheTimeout
};
...
...
public/app/features/templating/specs/template_srv_specs.ts
View file @
e2188373
...
...
@@ -239,4 +239,16 @@ describe('templateSrv', function() {
expect
(
target
).
to
.
be
(
'Server: All, period: 13m'
);
});
});
describe
(
'built in interval variables'
,
function
()
{
beforeEach
(
function
()
{
initTemplateSrv
([]);
});
it
(
'should replace $interval_ms with interval milliseconds'
,
function
()
{
var
target
=
_templateSrv
.
replace
(
'10 * $interval_ms'
,
{
"interval_ms"
:
{
text
:
"100"
,
value
:
"100"
}});
expect
(
target
).
to
.
be
(
'10 * 100'
);
});
});
});
public/app/features/templating/templateSrv.js
View file @
e2188373
...
...
@@ -100,10 +100,10 @@ function (angular, _, kbn) {
return
this
.
distributeVariable
(
value
,
variable
.
name
);
}
default
:
{
if
(
typeof
value
===
'string'
)
{
return
value
;
if
(
_
.
isArray
(
value
)
)
{
return
'{'
+
value
.
join
(
','
)
+
'}'
;
}
return
'{'
+
value
.
join
(
','
)
+
'}'
;
return
value
;
}
}
};
...
...
public/app/plugins/datasource/elasticsearch/datasource.js
View file @
e2188373
...
...
@@ -197,15 +197,9 @@ function (angular, _, moment, kbn, ElasticQueryBuilder, IndexPattern, ElasticRes
target
=
options
.
targets
[
i
];
if
(
target
.
hide
)
{
continue
;}
var
queryObj
=
this
.
queryBuilder
.
build
(
target
,
adhocFilters
);
var
queryString
=
templateSrv
.
replace
(
target
.
query
||
'*'
,
options
.
scopedVars
,
'lucene'
);
var
queryObj
=
this
.
queryBuilder
.
build
(
target
,
adhocFilters
,
queryString
);
var
esQuery
=
angular
.
toJson
(
queryObj
);
var
luceneQuery
=
target
.
query
||
'*'
;
luceneQuery
=
templateSrv
.
replace
(
luceneQuery
,
options
.
scopedVars
,
'lucene'
);
luceneQuery
=
angular
.
toJson
(
luceneQuery
);
// remove inner quotes
luceneQuery
=
luceneQuery
.
substr
(
1
,
luceneQuery
.
length
-
2
);
esQuery
=
esQuery
.
replace
(
"$lucene_query"
,
luceneQuery
);
var
searchType
=
(
queryObj
.
size
===
0
&&
this
.
esVersion
<
5
)
?
'count'
:
'query_then_fetch'
;
var
header
=
this
.
getQueryHeader
(
searchType
,
options
.
range
.
from
,
options
.
range
.
to
);
...
...
@@ -219,12 +213,6 @@ function (angular, _, moment, kbn, ElasticQueryBuilder, IndexPattern, ElasticRes
return
$q
.
when
([]);
}
// intervalSec: interval in seconds
if
(
options
.
interval
&&
options
.
interval
.
match
(
kbn
.
interval_regex
))
{
payload
=
payload
.
replace
(
/
\$
intervalSec/g
,
kbn
.
interval_to_seconds
(
options
.
interval
));
payload
=
payload
.
replace
(
/
\$
intervalMs/g
,
kbn
.
interval_to_ms
(
options
.
interval
));
}
payload
=
payload
.
replace
(
/
\$
interval/g
,
options
.
interval
);
payload
=
payload
.
replace
(
/
\$
timeFrom/g
,
options
.
range
.
from
.
valueOf
());
payload
=
payload
.
replace
(
/
\$
timeTo/g
,
options
.
range
.
to
.
valueOf
());
payload
=
templateSrv
.
replace
(
payload
,
options
.
scopedVars
);
...
...
public/app/plugins/datasource/elasticsearch/query_builder.js
View file @
e2188373
...
...
@@ -121,7 +121,7 @@ function (queryDef) {
}
};
ElasticQueryBuilder
.
prototype
.
build
=
function
(
target
,
adhocFilters
)
{
ElasticQueryBuilder
.
prototype
.
build
=
function
(
target
,
adhocFilters
,
queryString
)
{
// make sure query has defaults;
target
.
metrics
=
target
.
metrics
||
[{
type
:
'count'
,
id
:
'1'
}];
target
.
dsType
=
'elasticsearch'
;
...
...
@@ -138,7 +138,7 @@ function (queryDef) {
{
"query_string"
:
{
"analyze_wildcard"
:
true
,
"query"
:
'$lucene_query'
"query"
:
queryString
,
}
}
]
...
...
public/app/plugins/datasource/influxdb/datasource.ts
View file @
e2188373
...
...
@@ -45,7 +45,7 @@ export default class InfluxDatasource {
query
(
options
)
{
var
timeFilter
=
this
.
getTimeFilter
(
options
);
var
scopedVars
=
options
.
scopedVars
?
_
.
cloneDeep
(
options
.
scopedVars
)
:
{}
;
var
scopedVars
=
options
.
scopedVars
;
var
targets
=
_
.
cloneDeep
(
options
.
targets
);
var
queryTargets
=
[];
var
queryModel
;
...
...
@@ -56,8 +56,8 @@ export default class InfluxDatasource {
queryTargets
.
push
(
target
);
// b
uild quer
y
scopedVars
.
interval
=
{
value
:
target
.
interval
||
options
.
interval
}
;
// b
ackward compatabilit
y
scopedVars
.
interval
=
scopedVars
.
__interval
;
queryModel
=
new
InfluxQuery
(
target
,
this
.
templateSrv
,
scopedVars
);
return
queryModel
.
render
(
true
);
...
...
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