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
a01836e8
Commit
a01836e8
authored
Sep 21, 2016
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(adhoc filters): basic implementation for ad hoc filters for elasticsearch, #6038
parent
1b02632d
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
46 additions
and
5 deletions
+46
-5
public/app/features/templating/editor_ctrl.ts
+1
-1
public/app/plugins/datasource/elasticsearch/datasource.js
+12
-1
public/app/plugins/datasource/elasticsearch/query_builder.js
+19
-1
public/app/plugins/datasource/elasticsearch/specs/query_builder_specs.ts
+12
-0
public/app/plugins/datasource/influxdb/datasource.ts
+1
-2
public/test/specs/helpers.js
+1
-0
No files found.
public/app/features/templating/editor_ctrl.ts
View file @
a01836e8
...
@@ -84,7 +84,7 @@ export class VariableEditorCtrl {
...
@@ -84,7 +84,7 @@ export class VariableEditorCtrl {
if
(
$scope
.
current
.
type
===
'adhoc'
&&
$scope
.
current
.
datasource
!==
null
)
{
if
(
$scope
.
current
.
type
===
'adhoc'
&&
$scope
.
current
.
datasource
!==
null
)
{
$scope
.
infoText
=
'Adhoc filters are applied automatically to all queries that target this datasource'
;
$scope
.
infoText
=
'Adhoc filters are applied automatically to all queries that target this datasource'
;
datasourceSrv
.
get
(
$scope
.
current
.
datasource
).
then
(
ds
=>
{
datasourceSrv
.
get
(
$scope
.
current
.
datasource
).
then
(
ds
=>
{
if
(
!
ds
.
supportAdhocFilter
s
)
{
if
(
!
ds
.
getTagKey
s
)
{
$scope
.
infoText
=
'This datasource does not support adhoc filters yet.'
;
$scope
.
infoText
=
'This datasource does not support adhoc filters yet.'
;
}
}
});
});
...
...
public/app/plugins/datasource/elasticsearch/datasource.js
View file @
a01836e8
...
@@ -177,11 +177,14 @@ function (angular, _, moment, kbn, ElasticQueryBuilder, IndexPattern, ElasticRes
...
@@ -177,11 +177,14 @@ function (angular, _, moment, kbn, ElasticQueryBuilder, IndexPattern, ElasticRes
var
target
;
var
target
;
var
sentTargets
=
[];
var
sentTargets
=
[];
// add global adhoc filters to timeFilter
var
adhocFilters
=
templateSrv
.
getAdhocFilters
(
this
.
name
);
for
(
var
i
=
0
;
i
<
options
.
targets
.
length
;
i
++
)
{
for
(
var
i
=
0
;
i
<
options
.
targets
.
length
;
i
++
)
{
target
=
options
.
targets
[
i
];
target
=
options
.
targets
[
i
];
if
(
target
.
hide
)
{
continue
;}
if
(
target
.
hide
)
{
continue
;}
var
queryObj
=
this
.
queryBuilder
.
build
(
target
);
var
queryObj
=
this
.
queryBuilder
.
build
(
target
,
adhocFilters
);
var
esQuery
=
angular
.
toJson
(
queryObj
);
var
esQuery
=
angular
.
toJson
(
queryObj
);
var
luceneQuery
=
target
.
query
||
'*'
;
var
luceneQuery
=
target
.
query
||
'*'
;
luceneQuery
=
templateSrv
.
replace
(
luceneQuery
,
options
.
scopedVars
,
'lucene'
);
luceneQuery
=
templateSrv
.
replace
(
luceneQuery
,
options
.
scopedVars
,
'lucene'
);
...
@@ -314,6 +317,14 @@ function (angular, _, moment, kbn, ElasticQueryBuilder, IndexPattern, ElasticRes
...
@@ -314,6 +317,14 @@ function (angular, _, moment, kbn, ElasticQueryBuilder, IndexPattern, ElasticRes
return
this
.
getTerms
(
query
);
return
this
.
getTerms
(
query
);
}
}
};
};
this
.
getTagKeys
=
function
()
{
return
this
.
getFields
({});
};
this
.
getTagValues
=
function
(
options
)
{
return
this
.
getTerms
({
field
:
options
.
key
,
query
:
'*'
});
};
}
}
return
{
return
{
...
...
public/app/plugins/datasource/elasticsearch/query_builder.js
View file @
a01836e8
...
@@ -98,7 +98,23 @@ function (queryDef) {
...
@@ -98,7 +98,23 @@ function (queryDef) {
return
query
;
return
query
;
};
};
ElasticQueryBuilder
.
prototype
.
build
=
function
(
target
)
{
ElasticQueryBuilder
.
prototype
.
addAdhocFilters
=
function
(
query
,
adhocFilters
)
{
if
(
!
adhocFilters
)
{
return
;
}
var
i
,
filter
,
condition
;
var
must
=
query
.
query
.
filtered
.
filter
.
bool
.
must
;
for
(
i
=
0
;
i
<
adhocFilters
.
length
;
i
++
)
{
filter
=
adhocFilters
[
i
];
condition
=
{};
condition
[
filter
.
key
]
=
filter
.
value
;
must
.
push
({
"term"
:
condition
});
}
};
ElasticQueryBuilder
.
prototype
.
build
=
function
(
target
,
adhocFilters
)
{
// make sure query has defaults;
// make sure query has defaults;
target
.
metrics
=
target
.
metrics
||
[{
type
:
'count'
,
id
:
'1'
}];
target
.
metrics
=
target
.
metrics
||
[{
type
:
'count'
,
id
:
'1'
}];
target
.
dsType
=
'elasticsearch'
;
target
.
dsType
=
'elasticsearch'
;
...
@@ -125,6 +141,8 @@ function (queryDef) {
...
@@ -125,6 +141,8 @@ function (queryDef) {
}
}
};
};
this
.
addAdhocFilters
(
query
,
adhocFilters
);
// handle document query
// handle document query
if
(
target
.
bucketAggs
.
length
===
0
)
{
if
(
target
.
bucketAggs
.
length
===
0
)
{
metric
=
target
.
metrics
[
0
];
metric
=
target
.
metrics
[
0
];
...
...
public/app/plugins/datasource/elasticsearch/specs/query_builder_specs.ts
View file @
a01836e8
...
@@ -238,4 +238,16 @@ describe('ElasticQueryBuilder', function() {
...
@@ -238,4 +238,16 @@ describe('ElasticQueryBuilder', function() {
expect
(
firstLevel
.
aggs
[
"2"
].
derivative
.
buckets_path
).
to
.
be
(
"3"
);
expect
(
firstLevel
.
aggs
[
"2"
].
derivative
.
buckets_path
).
to
.
be
(
"3"
);
});
});
it
(
'with adhoc filters'
,
function
()
{
var
query
=
builder
.
build
({
metrics
:
[{
type
:
'Count'
,
id
:
'0'
}],
timeField
:
'@timestamp'
,
bucketAggs
:
[{
type
:
'date_histogram'
,
field
:
'@timestamp'
,
id
:
'3'
}],
},
[
{
key
:
'key1'
,
operator
:
'='
,
value
:
'value1'
}
]);
expect
(
query
.
query
.
filtered
.
filter
.
bool
.
must
[
1
].
term
[
"key1"
]).
to
.
be
(
"value1"
);
});
});
});
public/app/plugins/datasource/influxdb/datasource.ts
View file @
a01836e8
...
@@ -9,6 +9,7 @@ import InfluxQuery from './influx_query';
...
@@ -9,6 +9,7 @@ import InfluxQuery from './influx_query';
import
ResponseParser
from
'./response_parser'
;
import
ResponseParser
from
'./response_parser'
;
import
InfluxQueryBuilder
from
'./query_builder'
;
import
InfluxQueryBuilder
from
'./query_builder'
;
export
default
class
InfluxDatasource
{
export
default
class
InfluxDatasource
{
type
:
string
;
type
:
string
;
urls
:
any
;
urls
:
any
;
...
@@ -21,7 +22,6 @@ export default class InfluxDatasource {
...
@@ -21,7 +22,6 @@ export default class InfluxDatasource {
interval
:
any
;
interval
:
any
;
supportAnnotations
:
boolean
;
supportAnnotations
:
boolean
;
supportMetrics
:
boolean
;
supportMetrics
:
boolean
;
supportAdhocFilters
:
boolean
;
responseParser
:
any
;
responseParser
:
any
;
/** @ngInject */
/** @ngInject */
...
@@ -40,7 +40,6 @@ export default class InfluxDatasource {
...
@@ -40,7 +40,6 @@ export default class InfluxDatasource {
this
.
interval
=
(
instanceSettings
.
jsonData
||
{}).
timeInterval
;
this
.
interval
=
(
instanceSettings
.
jsonData
||
{}).
timeInterval
;
this
.
supportAnnotations
=
true
;
this
.
supportAnnotations
=
true
;
this
.
supportMetrics
=
true
;
this
.
supportMetrics
=
true
;
this
.
supportAdhocFilters
=
true
;
this
.
responseParser
=
new
ResponseParser
();
this
.
responseParser
=
new
ResponseParser
();
}
}
...
...
public/test/specs/helpers.js
View file @
a01836e8
...
@@ -158,6 +158,7 @@ define([
...
@@ -158,6 +158,7 @@ define([
return
_
.
template
(
text
,
this
.
templateSettings
)(
this
.
data
);
return
_
.
template
(
text
,
this
.
templateSettings
)(
this
.
data
);
};
};
this
.
init
=
function
()
{};
this
.
init
=
function
()
{};
this
.
getAdhocFilters
=
function
()
{
return
[];
};
this
.
fillVariableValuesForUrl
=
function
()
{};
this
.
fillVariableValuesForUrl
=
function
()
{};
this
.
updateTemplateData
=
function
()
{
};
this
.
updateTemplateData
=
function
()
{
};
this
.
variableExists
=
function
()
{
return
false
;
};
this
.
variableExists
=
function
()
{
return
false
;
};
...
...
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