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
525724cc
Commit
525724cc
authored
Sep 03, 2015
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(elasticsearch): lots of work on elasticsearch metrics query editor, #1034
parent
b3bda020
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
92 additions
and
57 deletions
+92
-57
public/app/plugins/datasource/elasticsearch/partials/query.editor.html
+1
-1
public/app/plugins/datasource/elasticsearch/queryBuilder.js
+1
-15
public/app/plugins/datasource/elasticsearch/queryCtrl.js
+90
-41
No files found.
public/app/plugins/datasource/elasticsearch/partials/query.editor.html
View file @
525724cc
...
@@ -65,7 +65,7 @@
...
@@ -65,7 +65,7 @@
Select
Select
</li>
</li>
<li
ng-repeat=
"segment in selectSegments"
>
<li
ng-repeat=
"segment in selectSegments"
>
<metric-segment
segment=
"segment"
get-alt-segments=
"getSelectSegments(segment, $index)"
on-value-changed=
"select
SegmentChanged(
)"
></metric-segment>
<metric-segment
segment=
"segment"
get-alt-segments=
"getSelectSegments(segment, $index)"
on-value-changed=
"select
Changed(segment, $index
)"
></metric-segment>
</li>
</li>
</ul>
</ul>
...
...
public/app/plugins/datasource/elasticsearch/queryBuilder.js
View file @
525724cc
...
@@ -72,20 +72,6 @@ function () {
...
@@ -72,20 +72,6 @@ function () {
return
query
;
return
query
;
};
};
ElasticQueryBuilder
.
prototype
.
_buildRangeFilter
=
function
(
target
)
{
var
filter
=
{
"range"
:{}};
filter
[
"range"
][
target
.
timestampField
]
=
{
"gte"
:
"$rangeFrom"
,
"lte"
:
"$rangeTo"
};
return
filter
;
};
ElasticQueryBuilder
.
prototype
.
_buildTermFilter
=
function
(
target
)
{
var
filter
=
{
"term"
:{}};
filter
[
"term"
][
target
.
termKey
]
=
target
.
termValue
;
return
filter
;
};
return
ElasticQueryBuilder
;
return
ElasticQueryBuilder
;
});
});
public/app/plugins/datasource/elasticsearch/queryCtrl.js
View file @
525724cc
...
@@ -22,7 +22,7 @@ function (angular, _, ElasticQueryBuilder) {
...
@@ -22,7 +22,7 @@ function (angular, _, ElasticQueryBuilder) {
var
target
=
$scope
.
target
;
var
target
=
$scope
.
target
;
target
.
function
=
target
.
function
||
'mean'
;
target
.
function
=
target
.
function
||
'mean'
;
target
.
timeField
=
target
.
timeField
||
'@timestamp'
;
target
.
timeField
=
target
.
timeField
||
'@timestamp'
;
target
.
select
=
target
.
select
||
[{
agg
:
'
c
ount'
}];
target
.
select
=
target
.
select
||
[{
agg
:
'
C
ount'
}];
target
.
groupByFields
=
target
.
groupByFields
||
[];
target
.
groupByFields
=
target
.
groupByFields
||
[];
$scope
.
timeSegment
=
uiSegmentSrv
.
newSegment
(
target
.
timeField
);
$scope
.
timeSegment
=
uiSegmentSrv
.
newSegment
(
target
.
timeField
);
...
@@ -31,32 +31,95 @@ function (angular, _, ElasticQueryBuilder) {
...
@@ -31,32 +31,95 @@ function (angular, _, ElasticQueryBuilder) {
return
uiSegmentSrv
.
newSegment
(
group
.
field
);
return
uiSegmentSrv
.
newSegment
(
group
.
field
);
});
});
$scope
.
selectSegments
=
_
.
map
(
target
.
select
,
function
(
select
)
{
$scope
.
selectSegments
=
[];
return
uiSegmentSrv
.
newSegment
(
select
.
agg
);
_
.
each
(
target
.
select
,
function
(
select
)
{
if
(
$scope
.
selectSegments
.
length
>
0
)
{
$scope
.
selectSegments
.
push
(
uiSegmentSrv
.
newCondition
(
" and "
));
}
if
(
select
.
agg
===
'Count'
)
{
$scope
.
selectSegments
.
push
(
uiSegmentSrv
.
newSegment
({
value
:
select
.
agg
,
type
:
'agg'
}));
}
else
{
$scope
.
selectSegments
.
push
(
uiSegmentSrv
.
newSegment
({
value
:
select
.
agg
,
type
:
'agg'
}));
$scope
.
selectSegments
.
push
(
uiSegmentSrv
.
newSegment
({
value
:
select
.
field
,
type
:
'field'
}));
}
});
});
$scope
.
groupBySegments
.
push
(
uiSegmentSrv
.
newPlusButton
());
$scope
.
groupBySegments
.
push
(
uiSegmentSrv
.
newPlusButton
());
$scope
.
selectSegments
.
push
(
uiSegmentSrv
.
newPlusButton
());
$scope
.
removeSelectSegment
=
uiSegmentSrv
.
newSegment
({
fake
:
true
,
value
:
'-- remove select --'
});
$scope
.
removeSelectSegment
=
uiSegmentSrv
.
newSegment
({
fake
:
true
,
value
:
'-- remove select --'
});
$scope
.
removeGroupBySegment
=
uiSegmentSrv
.
newSegment
({
fake
:
true
,
value
:
'-- remove group by --'
});
$scope
.
removeGroupBySegment
=
uiSegmentSrv
.
newSegment
({
fake
:
true
,
value
:
'-- remove group by --'
});
};
};
$scope
.
getFields
=
function
()
{
$scope
.
getSelectSegments
=
function
(
segment
,
index
)
{
return
$scope
.
datasource
.
metricFindQuery
(
'fields()'
).
then
(
$scope
.
transformToSegments
(
true
));
if
(
segment
.
type
===
'agg'
||
segment
.
type
===
'plus-button'
)
{
var
options
=
[
uiSegmentSrv
.
newSegment
({
value
:
'Count'
,
type
:
'agg'
}),
uiSegmentSrv
.
newSegment
({
value
:
'Min'
,
type
:
'agg'
}),
uiSegmentSrv
.
newSegment
({
value
:
'Max'
,
type
:
'agg'
}),
uiSegmentSrv
.
newSegment
({
value
:
'Avg'
,
type
:
'agg'
}),
];
if
(
index
>
0
)
{
options
.
splice
(
0
,
0
,
angular
.
copy
(
$scope
.
removeSelectSegment
));
}
return
$q
.
when
(
options
);
}
return
$scope
.
datasource
.
metricFindQuery
(
'fields()'
)
.
then
(
$scope
.
transformToSegments
(
false
))
.
then
(
null
,
$scope
.
handleQueryError
);
};
};
$scope
.
transformToSegments
=
function
(
addTemplateVars
)
{
$scope
.
selectChanged
=
function
(
segment
,
index
)
{
return
function
(
results
)
{
if
(
segment
.
value
===
$scope
.
removeSelectSegment
.
value
)
{
var
segments
=
_
.
map
(
results
,
function
(
segment
)
{
var
nextSegment
=
$scope
.
selectSegments
[
index
+
1
];
return
uiSegmentSrv
.
newSegment
({
value
:
segment
.
text
,
expandable
:
segment
.
expandable
});
var
remove
=
2
;
});
if
(
nextSegment
&&
nextSegment
.
type
===
'field'
)
{
remove
+=
1
;
}
$scope
.
selectSegments
.
splice
(
index
-
1
,
remove
);
$scope
.
rebuildTargetSelects
();
return
;
}
if
(
addTemplateVars
)
{
if
(
segment
.
type
===
'plus-button'
&&
index
>
0
)
{
_
.
each
(
templateSrv
.
variables
,
function
(
variable
)
{
$scope
.
selectSegments
.
splice
(
index
,
0
,
uiSegmentSrv
.
newCondition
(
' And '
));
segments
.
unshift
(
uiSegmentSrv
.
newSegment
({
type
:
'template'
,
value
:
'$'
+
variable
.
name
,
expandable
:
true
}));
segment
.
type
=
'agg'
;
});
index
+=
1
;
}
if
(
segment
.
type
===
'agg'
)
{
var
nextSegment
=
$scope
.
selectSegments
[
index
+
1
];
if
(
segment
.
value
===
'Count'
)
{
if
(
nextSegment
&&
nextSegment
.
type
===
'field'
)
{
$scope
.
selectSegments
.
splice
(
index
+
1
,
1
);
}
}
else
if
(
!
nextSegment
||
nextSegment
.
type
!==
'field'
)
{
$scope
.
selectSegments
.
splice
(
index
+
1
,
0
,
uiSegmentSrv
.
newSegment
({
value
:
'select field'
,
fake
:
true
,
type
:
'field'
}));
}
}
}
return
segments
;
if
((
index
+
1
)
===
$scope
.
selectSegments
.
length
)
{
$scope
.
selectSegments
.
push
(
uiSegmentSrv
.
newPlusButton
());
}
$scope
.
rebuildTargetSelects
();
};
$scope
.
rebuildTargetSelects
=
function
()
{
$scope
.
target
.
select
=
[];
for
(
var
i
=
0
;
i
<
$scope
.
selectSegments
.
length
;
i
++
)
{
var
segment
=
$scope
.
selectSegments
[
i
];
var
select
=
{
agg
:
segment
.
value
};
if
(
segment
.
type
===
'agg'
&&
segment
.
value
!==
'Count'
)
{
select
.
field
=
$scope
.
selectSegments
[
i
+
1
].
value
;
i
+=
2
;
}
else
{
i
+=
1
;
}
$scope
.
target
.
select
.
push
(
select
);
};
};
};
};
...
@@ -90,34 +153,20 @@ function (angular, _, ElasticQueryBuilder) {
...
@@ -90,34 +153,20 @@ function (angular, _, ElasticQueryBuilder) {
$scope
.
$parent
.
get_data
();
$scope
.
$parent
.
get_data
();
};
};
$scope
.
valueFieldChanged
=
function
()
{
$scope
.
transformToSegments
=
function
(
addTemplateVars
)
{
$scope
.
target
.
valueField
=
$scope
.
valueFieldSegment
.
value
;
return
function
(
results
)
{
$scope
.
$parent
.
get_data
();
var
segments
=
_
.
map
(
results
,
function
(
segment
)
{
};
return
uiSegmentSrv
.
newSegment
({
value
:
segment
.
text
,
expandable
:
segment
.
expandable
});
});
$scope
.
keyFieldChanged
=
function
()
{
$scope
.
target
.
keyField
=
$scope
.
keyFieldSegment
.
value
;
$scope
.
$parent
.
get_data
();
};
$scope
.
termValueSegmentChanged
=
function
()
{
$scope
.
target
.
termValue
=
$scope
.
termValueSegment
.
value
;
$scope
.
$parent
.
get_data
();
};
$scope
.
termKeySegmentChanged
=
function
()
{
$scope
.
target
.
termKey
=
$scope
.
termKeySegment
.
value
;
$scope
.
$parent
.
get_data
();
};
$scope
.
groupByFieldChanged
=
function
()
{
if
(
addTemplateVars
)
{
$scope
.
target
.
groupBy
=
$scope
.
groupByFieldSegment
.
value
;
_
.
each
(
templateSrv
.
variables
,
function
(
variable
)
{
$scope
.
$parent
.
get_data
();
segments
.
unshift
(
uiSegmentSrv
.
newSegment
({
type
:
'template'
,
value
:
'$'
+
variable
.
name
,
expandable
:
true
}));
};
});
}
$scope
.
changeFunction
=
function
(
func
)
{
return
segments
;
$scope
.
target
.
function
=
func
;
};
$scope
.
$parent
.
get_data
();
};
};
$scope
.
handleQueryError
=
function
(
err
)
{
$scope
.
handleQueryError
=
function
(
err
)
{
...
...
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