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
4c42db9e
Unverified
Commit
4c42db9e
authored
Jan 10, 2019
by
Torkel Ödegaard
Committed by
GitHub
Jan 10, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #14804 from SamuelToh/4075_support_templatevar_on_alias_es_ds
4075: Interpolate tempvar on alias
parents
b25214bf
e1f6870f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
4 deletions
+21
-4
public/app/plugins/datasource/elasticsearch/datasource.ts
+4
-0
public/app/plugins/datasource/elasticsearch/specs/datasource.test.ts
+17
-4
No files found.
public/app/plugins/datasource/elasticsearch/datasource.ts
View file @
4c42db9e
...
...
@@ -254,6 +254,10 @@ export class ElasticDatasource {
continue
;
}
if
(
target
.
alias
)
{
target
.
alias
=
this
.
templateSrv
.
replace
(
target
.
alias
,
options
.
scopedVars
,
'lucene'
);
}
const
queryString
=
this
.
templateSrv
.
replace
(
target
.
query
||
'*'
,
options
.
scopedVars
,
'lucene'
);
const
queryObj
=
this
.
queryBuilder
.
build
(
target
,
adhocFilters
,
queryString
);
const
esQuery
=
angular
.
toJson
(
queryObj
);
...
...
public/app/plugins/datasource/elasticsearch/specs/datasource.test.ts
View file @
4c42db9e
...
...
@@ -16,7 +16,13 @@ describe('ElasticDatasource', function(this: any) {
};
const
templateSrv
=
{
replace
:
jest
.
fn
(
text
=>
text
),
replace
:
jest
.
fn
(
text
=>
{
if
(
text
.
startsWith
(
"$"
))
{
return
`resolvedVariable`
;
}
else
{
return
text
;
}
}),
getAdhocFilters
:
jest
.
fn
(()
=>
[]),
};
...
...
@@ -67,7 +73,7 @@ describe('ElasticDatasource', function(this: any) {
});
describe
(
'When issuing metric query with interval pattern'
,
()
=>
{
let
requestOptions
,
parts
,
header
;
let
requestOptions
,
parts
,
header
,
query
;
beforeEach
(()
=>
{
createDatasource
({
...
...
@@ -81,19 +87,22 @@ describe('ElasticDatasource', function(this: any) {
return
Promise
.
resolve
({
data
:
{
responses
:
[]
}
});
});
ctx
.
ds
.
query
(
{
query
=
{
range
:
{
from
:
moment
.
utc
([
2015
,
4
,
30
,
10
]),
to
:
moment
.
utc
([
2015
,
5
,
1
,
10
]),
},
targets
:
[
{
alias
:
"$varAlias"
,
bucketAggs
:
[],
metrics
:
[{
type
:
'raw_document'
}],
query
:
'escape
\\
:test'
,
},
],
});
};
ctx
.
ds
.
query
(
query
);
parts
=
requestOptions
.
data
.
split
(
'
\
n'
);
header
=
angular
.
fromJson
(
parts
[
0
]);
...
...
@@ -103,6 +112,10 @@ describe('ElasticDatasource', function(this: any) {
expect
(
header
.
index
).
toEqual
([
'asd-2015.05.30'
,
'asd-2015.05.31'
,
'asd-2015.06.01'
]);
});
it
(
'should resolve the alias variable'
,
()
=>
{
expect
(
query
.
targets
[
0
].
alias
).
toEqual
(
'resolvedVariable'
);
});
it
(
'should json escape lucene query'
,
()
=>
{
const
body
=
angular
.
fromJson
(
parts
[
1
]);
expect
(
body
.
query
.
bool
.
filter
[
1
].
query_string
.
query
).
toBe
(
'escape
\\
:test'
);
...
...
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