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
dfe0f911
Commit
dfe0f911
authored
Sep 20, 2016
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(adhoc): adhoc filters progress
parent
6e429b85
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
96 additions
and
21 deletions
+96
-21
public/app/features/templating/adhoc_variable.ts
+3
-3
public/app/features/templating/specs/adhoc_variable_specs.ts
+40
-0
public/app/features/templating/templateSrv.js
+18
-0
public/app/plugins/datasource/influxdb/datasource.ts
+15
-18
public/app/plugins/datasource/influxdb/influx_query.ts
+7
-0
public/app/plugins/datasource/influxdb/specs/influx_query_specs.ts
+13
-0
No files found.
public/app/features/templating/adhoc_variable.ts
View file @
dfe0f911
...
...
@@ -18,7 +18,7 @@ export class AdhocVariable implements Variable {
};
/** @ngInject **/
constructor
(
private
model
,
private
timeSrv
,
private
templateSrv
,
private
variableSrv
)
{
constructor
(
private
model
)
{
assignModelProperties
(
this
,
model
,
this
.
defaults
);
}
...
...
@@ -68,7 +68,7 @@ export class AdhocVariable implements Variable {
}
variableTypes
[
'adhoc'
]
=
{
name
:
'Ad hoc'
,
name
:
'Ad hoc
filters
'
,
ctor
:
AdhocVariable
,
description
:
'Ad
hoc filters
'
,
description
:
'Ad
d key/value filters on the fly
'
,
};
public/app/features/templating/specs/adhoc_variable_specs.ts
0 → 100644
View file @
dfe0f911
import
{
describe
,
beforeEach
,
it
,
sinon
,
expect
,
angularMocks
}
from
'test/lib/common'
;
import
{
AdhocVariable
}
from
'../adhoc_variable'
;
describe
(
'AdhocVariable'
,
function
()
{
describe
(
'when serializing to url'
,
function
()
{
it
(
'should set return key value and op seperated by pipe'
,
function
()
{
var
variable
=
new
AdhocVariable
({
filters
:
[
{
key
:
'key1'
,
operator
:
'='
,
value
:
'value1'
},
{
key
:
'key2'
,
operator
:
'!='
,
value
:
'value2'
},
]
});
var
urlValue
=
variable
.
getValueForUrl
();
expect
(
urlValue
).
to
.
eql
([
"key1|=|value1"
,
"key2|!=|value2"
]);
});
});
describe
(
'when deserializing from url'
,
function
()
{
it
(
'should restore filters'
,
function
()
{
var
variable
=
new
AdhocVariable
({});
variable
.
setValueFromUrl
([
"key1|=|value1"
,
"key2|!=|value2"
]);
expect
(
variable
.
filters
[
0
].
key
).
to
.
be
(
'key1'
);
expect
(
variable
.
filters
[
0
].
operator
).
to
.
be
(
'='
);
expect
(
variable
.
filters
[
0
].
value
).
to
.
be
(
'value1'
);
expect
(
variable
.
filters
[
1
].
key
).
to
.
be
(
'key2'
);
expect
(
variable
.
filters
[
1
].
operator
).
to
.
be
(
'!='
);
expect
(
variable
.
filters
[
1
].
value
).
to
.
be
(
'value2'
);
});
});
});
public/app/features/templating/templateSrv.js
View file @
dfe0f911
...
...
@@ -15,6 +15,7 @@ function (angular, _, kbn) {
this
.
_index
=
{};
this
.
_texts
=
{};
this
.
_grafanaVariables
=
{};
this
.
_adhocVariables
=
{};
this
.
init
=
function
(
variables
)
{
this
.
variables
=
variables
;
...
...
@@ -23,16 +24,33 @@ function (angular, _, kbn) {
this
.
updateTemplateData
=
function
()
{
this
.
_index
=
{};
this
.
_filters
=
{};
for
(
var
i
=
0
;
i
<
this
.
variables
.
length
;
i
++
)
{
var
variable
=
this
.
variables
[
i
];
// add adhoc filters to it's own index
if
(
variable
.
type
===
'adhoc'
)
{
this
.
_adhocVariables
[
variable
.
datasource
]
=
variable
;
continue
;
}
if
(
!
variable
.
current
||
!
variable
.
current
.
isNone
&&
!
variable
.
current
.
value
)
{
continue
;
}
this
.
_index
[
variable
.
name
]
=
variable
;
}
};
this
.
getAdhocFilters
=
function
(
datasourceName
)
{
var
variable
=
this
.
_adhocVariables
[
datasourceName
];
if
(
variable
)
{
return
variable
.
filters
||
[];
}
return
[]
};
function
luceneEscape
(
value
)
{
return
value
.
replace
(
/
([\!\*\+\-\=
<>
\s\&\|\(\)\[\]\{\}\^\~\?\:\\/
"
])
/g
,
"
\\
$1"
);
}
...
...
public/app/plugins/datasource/influxdb/datasource.ts
View file @
dfe0f911
...
...
@@ -44,36 +44,23 @@ export default class InfluxDatasource {
query
(
options
)
{
var
timeFilter
=
this
.
getTimeFilter
(
options
);
var
scopedVars
=
_
.
extend
({},
options
.
scopedVars
)
;
var
scopedVars
=
options
.
scopedVars
?
_
.
cloneDeep
(
options
.
scopedVars
)
:
{}
;
var
targets
=
_
.
cloneDeep
(
options
.
targets
);
var
queryTargets
=
[];
var
queryModel
;
var
i
,
y
;
var
allQueries
=
_
.
map
(
targets
,
target
=>
{
if
(
target
.
hide
)
{
return
""
;
}
if
(
!
target
.
rawQuery
)
{
// apply add hoc filters
for
(
let
variable
of
this
.
templateSrv
.
variables
)
{
if
(
variable
.
type
===
'adhoc'
&&
variable
.
datasource
===
this
.
name
)
{
for
(
let
filter
of
variable
.
filters
)
{
if
(
filter
.
key
!==
undefined
&&
filter
.
value
!==
undefined
)
{
target
.
tags
.
push
({
key
:
filter
.
key
,
value
:
filter
.
value
,
condition
:
filter
.
condition
,
operator
:
filter
.
operator
});
}
}
}
}
}
queryTargets
.
push
(
target
);
// build query
scopedVars
.
interval
=
{
value
:
target
.
interval
||
options
.
interval
};
var
queryModel
=
new
InfluxQuery
(
target
,
this
.
templateSrv
,
scopedVars
);
var
query
=
queryModel
.
render
(
true
);
queryModel
=
new
InfluxQuery
(
target
,
this
.
templateSrv
,
scopedVars
);
return
queryModel
.
render
(
true
);
return
query
;
}).
reduce
((
acc
,
current
)
=>
{
if
(
current
!==
""
)
{
acc
+=
";"
+
current
;
...
...
@@ -81,6 +68,16 @@ export default class InfluxDatasource {
return
acc
;
});
if
(
allQueries
===
''
)
{
return
this
.
$q
.
when
({
data
:
[]});
}
// add global adhoc filters to timeFilter
var
adhocFilters
=
this
.
templateSrv
.
getAdhocFilters
(
this
.
name
);
if
(
adhocFilters
.
length
>
0
)
{
timeFilter
+=
' AND '
+
queryModel
.
renderAdhocFilters
(
adhocFilters
);
}
// replace grafana variables
scopedVars
.
timeFilter
=
{
value
:
timeFilter
};
...
...
@@ -120,7 +117,7 @@ export default class InfluxDatasource {
}
}
return
{
data
:
seriesList
};
return
{
data
:
seriesList
};
});
};
...
...
public/app/plugins/datasource/influxdb/influx_query.ts
View file @
dfe0f911
...
...
@@ -251,4 +251,11 @@ export default class InfluxQuery {
return query;
}
renderAdhocFilters(filters) {
var conditions = _.map(filters, (tag, index) => {
return this.renderTagCondition(tag, index, false);
});
return conditions.join(' ');
}
}
public/app/plugins/datasource/influxdb/specs/influx_query_specs.ts
View file @
dfe0f911
...
...
@@ -237,6 +237,19 @@ describe('InfluxQuery', function() {
expect
(
query
.
target
.
select
[
0
][
2
].
type
).
to
.
be
(
'math'
);
});
describe
(
'when render adhoc filters'
,
function
()
{
it
(
'should generate correct query segment'
,
function
()
{
var
query
=
new
InfluxQuery
({
measurement
:
'cpu'
,
},
templateSrv
,
{});
var
queryText
=
query
.
renderAdhocFilters
([
{
key
:
'key1'
,
operator
:
'='
,
value
:
'value1'
},
{
key
:
'key2'
,
operator
:
'!='
,
value
:
'value2'
},
]);
expect
(
queryText
).
to
.
be
(
'"key1" =
\'
value1
\'
AND "key2" !=
\'
value2
\'
'
);
});
});
});
});
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