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
8b9c44be
Unverified
Commit
8b9c44be
authored
Mar 19, 2018
by
Daniel Lee
Committed by
GitHub
Mar 19, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #10369 from grafana/elastic-file-to-ts
migrated files to ts
parents
1f7235b3
328141e7
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
126 additions
and
108 deletions
+126
-108
public/app/plugins/datasource/elasticsearch/bucket_agg.ts
+61
-51
public/app/plugins/datasource/elasticsearch/metric_agg.ts
+65
-57
No files found.
public/app/plugins/datasource/elasticsearch/bucket_agg.
j
s
→
public/app/plugins/datasource/elasticsearch/bucket_agg.
t
s
View file @
8b9c44be
define
([
import
angular
from
'angular'
;
'angular'
,
import
_
from
'lodash'
;
'lodash'
,
import
*
as
queryDef
from
'./query_def'
;
'./query_def'
,
],
export
function
elasticBucketAgg
()
{
function
(
angular
,
_
,
queryDef
)
{
return
{
'use strict'
;
templateUrl
:
'public/app/plugins/datasource/elasticsearch/partials/bucket_agg.html'
,
controller
:
'ElasticBucketAggCtrl'
,
var
module
=
angular
.
module
(
'grafana.directives'
);
restrict
:
'E'
,
scope
:
{
module
.
directive
(
'elasticBucketAgg'
,
function
()
{
target
:
'='
,
return
{
index
:
'='
,
templateUrl
:
'public/app/plugins/datasource/elasticsearch/partials/bucket_agg.html'
,
onChange
:
'&'
,
controller
:
'ElasticBucketAggCtrl'
,
getFields
:
'&'
,
restrict
:
'E'
,
},
scope
:
{
};
target
:
"="
,
}
index
:
"="
,
onChange
:
"&"
,
export
class
ElasticBucketAggCtrl
{
getFields
:
"&"
,
/** @nginject */
}
constructor
(
$scope
,
uiSegmentSrv
,
$q
,
$rootScope
)
{
};
});
module
.
controller
(
'ElasticBucketAggCtrl'
,
function
(
$scope
,
uiSegmentSrv
,
$q
,
$rootScope
)
{
var
bucketAggs
=
$scope
.
target
.
bucketAggs
;
var
bucketAggs
=
$scope
.
target
.
bucketAggs
;
$scope
.
orderByOptions
=
[];
$scope
.
orderByOptions
=
[];
...
@@ -39,9 +35,13 @@ function (angular, _, queryDef) {
...
@@ -39,9 +35,13 @@ function (angular, _, queryDef) {
return
queryDef
.
sizeOptions
;
return
queryDef
.
sizeOptions
;
};
};
$rootScope
.
onAppEvent
(
'elastic-query-updated'
,
function
()
{
$rootScope
.
onAppEvent
(
$scope
.
validateModel
();
'elastic-query-updated'
,
},
$scope
);
function
()
{
$scope
.
validateModel
();
},
$scope
);
$scope
.
init
=
function
()
{
$scope
.
init
=
function
()
{
$scope
.
agg
=
bucketAggs
[
$scope
.
index
];
$scope
.
agg
=
bucketAggs
[
$scope
.
index
];
...
@@ -56,10 +56,10 @@ function (angular, _, queryDef) {
...
@@ -56,10 +56,10 @@ function (angular, _, queryDef) {
$scope
.
agg
.
settings
=
{};
$scope
.
agg
.
settings
=
{};
$scope
.
showOptions
=
false
;
$scope
.
showOptions
=
false
;
switch
(
$scope
.
agg
.
type
)
{
switch
(
$scope
.
agg
.
type
)
{
case
'date_histogram'
:
case
'date_histogram'
:
case
'histogram'
:
case
'histogram'
:
case
'terms'
:
{
case
'terms'
:
{
delete
$scope
.
agg
.
query
;
delete
$scope
.
agg
.
query
;
$scope
.
agg
.
field
=
'select field'
;
$scope
.
agg
.
field
=
'select field'
;
break
;
break
;
...
@@ -84,15 +84,15 @@ function (angular, _, queryDef) {
...
@@ -84,15 +84,15 @@ function (angular, _, queryDef) {
$scope
.
isFirst
=
$scope
.
index
===
0
;
$scope
.
isFirst
=
$scope
.
index
===
0
;
$scope
.
bucketAggCount
=
bucketAggs
.
length
;
$scope
.
bucketAggCount
=
bucketAggs
.
length
;
var
settingsLinkText
=
""
;
var
settingsLinkText
=
''
;
var
settings
=
$scope
.
agg
.
settings
||
{};
var
settings
=
$scope
.
agg
.
settings
||
{};
switch
(
$scope
.
agg
.
type
)
{
switch
(
$scope
.
agg
.
type
)
{
case
'terms'
:
{
case
'terms'
:
{
settings
.
order
=
settings
.
order
||
"desc"
;
settings
.
order
=
settings
.
order
||
'desc'
;
settings
.
size
=
settings
.
size
||
"10"
;
settings
.
size
=
settings
.
size
||
'10'
;
settings
.
min_doc_count
=
settings
.
min_doc_count
||
1
;
settings
.
min_doc_count
=
settings
.
min_doc_count
||
1
;
settings
.
orderBy
=
settings
.
orderBy
||
"_term"
;
settings
.
orderBy
=
settings
.
orderBy
||
'_term'
;
if
(
settings
.
size
!==
'0'
)
{
if
(
settings
.
size
!==
'0'
)
{
settingsLinkText
=
queryDef
.
describeOrder
(
settings
.
order
)
+
' '
+
settings
.
size
+
', '
;
settingsLinkText
=
queryDef
.
describeOrder
(
settings
.
order
)
+
' '
+
settings
.
size
+
', '
;
...
@@ -111,13 +111,17 @@ function (angular, _, queryDef) {
...
@@ -111,13 +111,17 @@ function (angular, _, queryDef) {
break
;
break
;
}
}
case
'filters'
:
{
case
'filters'
:
{
settings
.
filters
=
settings
.
filters
||
[{
query
:
'*'
}];
settings
.
filters
=
settings
.
filters
||
[{
query
:
'*'
}];
settingsLinkText
=
_
.
reduce
(
settings
.
filters
,
function
(
memo
,
value
,
index
)
{
settingsLinkText
=
_
.
reduce
(
memo
+=
'Q'
+
(
index
+
1
)
+
' = '
+
value
.
query
+
' '
;
settings
.
filters
,
return
memo
;
function
(
memo
,
value
,
index
)
{
},
''
);
memo
+=
'Q'
+
(
index
+
1
)
+
' = '
+
value
.
query
+
' '
;
return
memo
;
},
''
);
if
(
settingsLinkText
.
length
>
50
)
{
if
(
settingsLinkText
.
length
>
50
)
{
settingsLinkText
=
settingsLinkText
.
substr
(
0
,
50
)
+
"..."
;
settingsLinkText
=
settingsLinkText
.
substr
(
0
,
50
)
+
'...'
;
}
}
settingsLinkText
=
'Filter Queries ('
+
settings
.
filters
.
length
+
')'
;
settingsLinkText
=
'Filter Queries ('
+
settings
.
filters
.
length
+
')'
;
break
;
break
;
...
@@ -165,7 +169,7 @@ function (angular, _, queryDef) {
...
@@ -165,7 +169,7 @@ function (angular, _, queryDef) {
};
};
$scope
.
addFiltersQuery
=
function
()
{
$scope
.
addFiltersQuery
=
function
()
{
$scope
.
agg
.
settings
.
filters
.
push
({
query
:
'*'
});
$scope
.
agg
.
settings
.
filters
.
push
({
query
:
'*'
});
};
};
$scope
.
removeFiltersQuery
=
function
(
filter
)
{
$scope
.
removeFiltersQuery
=
function
(
filter
)
{
...
@@ -182,7 +186,7 @@ function (angular, _, queryDef) {
...
@@ -182,7 +186,7 @@ function (angular, _, queryDef) {
$scope
.
getFieldsInternal
=
function
()
{
$scope
.
getFieldsInternal
=
function
()
{
if
(
$scope
.
agg
.
type
===
'date_histogram'
)
{
if
(
$scope
.
agg
.
type
===
'date_histogram'
)
{
return
$scope
.
getFields
({
$fieldType
:
'date'
});
return
$scope
.
getFields
({
$fieldType
:
'date'
});
}
else
{
}
else
{
return
$scope
.
getFields
();
return
$scope
.
getFields
();
}
}
...
@@ -198,14 +202,18 @@ function (angular, _, queryDef) {
...
@@ -198,14 +202,18 @@ function (angular, _, queryDef) {
var
addIndex
=
bucketAggs
.
length
-
1
;
var
addIndex
=
bucketAggs
.
length
-
1
;
if
(
lastBucket
&&
lastBucket
.
type
===
'date_histogram'
)
{
if
(
lastBucket
&&
lastBucket
.
type
===
'date_histogram'
)
{
addIndex
-
1
;
addIndex
-
=
1
;
}
}
var
id
=
_
.
reduce
(
$scope
.
target
.
bucketAggs
.
concat
(
$scope
.
target
.
metrics
),
function
(
max
,
val
)
{
var
id
=
_
.
reduce
(
return
parseInt
(
val
.
id
)
>
max
?
parseInt
(
val
.
id
)
:
max
;
$scope
.
target
.
bucketAggs
.
concat
(
$scope
.
target
.
metrics
),
},
0
);
function
(
max
,
val
)
{
return
parseInt
(
val
.
id
)
>
max
?
parseInt
(
val
.
id
)
:
max
;
},
0
);
bucketAggs
.
splice
(
addIndex
,
0
,
{
type
:
"terms"
,
field
:
"select field"
,
id
:
(
id
+
1
).
toString
(),
fake
:
true
});
bucketAggs
.
splice
(
addIndex
,
0
,
{
type
:
'terms'
,
field
:
'select field'
,
id
:
(
id
+
1
).
toString
(),
fake
:
true
});
$scope
.
onChange
();
$scope
.
onChange
();
};
};
...
@@ -215,7 +223,9 @@ function (angular, _, queryDef) {
...
@@ -215,7 +223,9 @@ function (angular, _, queryDef) {
};
};
$scope
.
init
();
$scope
.
init
();
}
}
}
);
var
module
=
angular
.
module
(
'grafana.directives'
);
module
.
directive
(
'elasticBucketAgg'
,
elasticBucketAgg
);
}
);
module
.
controller
(
'ElasticBucketAggCtrl'
,
ElasticBucketAggCtrl
);
public/app/plugins/datasource/elasticsearch/metric_agg.
j
s
→
public/app/plugins/datasource/elasticsearch/metric_agg.
t
s
View file @
8b9c44be
define
([
import
angular
from
'angular'
;
'angular'
,
import
_
from
'lodash'
;
'lodash'
,
import
*
as
queryDef
from
'./query_def'
;
'./query_def'
],
export
function
elasticMetricAgg
()
{
function
(
angular
,
_
,
queryDef
)
{
return
{
'use strict'
;
templateUrl
:
'public/app/plugins/datasource/elasticsearch/partials/metric_agg.html'
,
controller
:
'ElasticMetricAggCtrl'
,
var
module
=
angular
.
module
(
'grafana.directives'
);
restrict
:
'E'
,
scope
:
{
module
.
directive
(
'elasticMetricAgg'
,
function
()
{
target
:
'='
,
return
{
index
:
'='
,
templateUrl
:
'public/app/plugins/datasource/elasticsearch/partials/metric_agg.html'
,
onChange
:
'&'
,
controller
:
'ElasticMetricAggCtrl'
,
getFields
:
'&'
,
restrict
:
'E'
,
esVersion
:
'='
,
scope
:
{
},
target
:
"="
,
};
index
:
"="
,
}
onChange
:
"&"
,
getFields
:
"&"
,
export
class
ElasticMetricAggCtrl
{
esVersion
:
'='
constructor
(
$scope
,
uiSegmentSrv
,
$q
,
$rootScope
)
{
}
};
});
module
.
controller
(
'ElasticMetricAggCtrl'
,
function
(
$scope
,
uiSegmentSrv
,
$q
,
$rootScope
)
{
var
metricAggs
=
$scope
.
target
.
metrics
;
var
metricAggs
=
$scope
.
target
.
metrics
;
$scope
.
metricAggTypes
=
queryDef
.
getMetricAggTypes
(
$scope
.
esVersion
);
$scope
.
metricAggTypes
=
queryDef
.
getMetricAggTypes
(
$scope
.
esVersion
);
$scope
.
extendedStats
=
queryDef
.
extendedStats
;
$scope
.
extendedStats
=
queryDef
.
extendedStats
;
$scope
.
pipelineAggOptions
=
[];
$scope
.
pipelineAggOptions
=
[];
...
@@ -41,17 +35,21 @@ function (angular, _, queryDef) {
...
@@ -41,17 +35,21 @@ function (angular, _, queryDef) {
$scope
.
pipelineAggOptions
=
queryDef
.
getPipelineAggOptions
(
$scope
.
target
);
$scope
.
pipelineAggOptions
=
queryDef
.
getPipelineAggOptions
(
$scope
.
target
);
};
};
$rootScope
.
onAppEvent
(
'elastic-query-updated'
,
function
()
{
$rootScope
.
onAppEvent
(
$scope
.
index
=
_
.
indexOf
(
metricAggs
,
$scope
.
agg
);
'elastic-query-updated'
,
$scope
.
updatePipelineAggOptions
();
function
()
{
$scope
.
validateModel
();
$scope
.
index
=
_
.
indexOf
(
metricAggs
,
$scope
.
agg
);
},
$scope
);
$scope
.
updatePipelineAggOptions
();
$scope
.
validateModel
();
},
$scope
);
$scope
.
validateModel
=
function
()
{
$scope
.
validateModel
=
function
()
{
$scope
.
isFirst
=
$scope
.
index
===
0
;
$scope
.
isFirst
=
$scope
.
index
===
0
;
$scope
.
isSingle
=
metricAggs
.
length
===
1
;
$scope
.
isSingle
=
metricAggs
.
length
===
1
;
$scope
.
settingsLinkText
=
''
;
$scope
.
settingsLinkText
=
''
;
$scope
.
aggDef
=
_
.
find
(
$scope
.
metricAggTypes
,
{
value
:
$scope
.
agg
.
type
});
$scope
.
aggDef
=
_
.
find
(
$scope
.
metricAggTypes
,
{
value
:
$scope
.
agg
.
type
});
if
(
queryDef
.
isPipelineAgg
(
$scope
.
agg
.
type
))
{
if
(
queryDef
.
isPipelineAgg
(
$scope
.
agg
.
type
))
{
$scope
.
agg
.
pipelineAgg
=
$scope
.
agg
.
pipelineAgg
||
'select metric'
;
$scope
.
agg
.
pipelineAgg
=
$scope
.
agg
.
pipelineAgg
||
'select metric'
;
...
@@ -67,30 +65,34 @@ function (angular, _, queryDef) {
...
@@ -67,30 +65,34 @@ function (angular, _, queryDef) {
}
else
if
(
!
$scope
.
agg
.
field
)
{
}
else
if
(
!
$scope
.
agg
.
field
)
{
$scope
.
agg
.
field
=
'select field'
;
$scope
.
agg
.
field
=
'select field'
;
}
}
switch
(
$scope
.
agg
.
type
)
{
switch
(
$scope
.
agg
.
type
)
{
case
'cardinality'
:
{
case
'cardinality'
:
{
var
precision_threshold
=
$scope
.
agg
.
settings
.
precision_threshold
||
''
;
var
precision_threshold
=
$scope
.
agg
.
settings
.
precision_threshold
||
''
;
$scope
.
settingsLinkText
=
'Precision threshold: '
+
precision_threshold
;
$scope
.
settingsLinkText
=
'Precision threshold: '
+
precision_threshold
;
break
;
break
;
}
}
case
'percentiles'
:
{
case
'percentiles'
:
{
$scope
.
agg
.
settings
.
percents
=
$scope
.
agg
.
settings
.
percents
||
[
25
,
50
,
75
,
95
,
99
];
$scope
.
agg
.
settings
.
percents
=
$scope
.
agg
.
settings
.
percents
||
[
25
,
50
,
75
,
95
,
99
];
$scope
.
settingsLinkText
=
'Values: '
+
$scope
.
agg
.
settings
.
percents
.
join
(
','
);
$scope
.
settingsLinkText
=
'Values: '
+
$scope
.
agg
.
settings
.
percents
.
join
(
','
);
break
;
break
;
}
}
case
'extended_stats'
:
{
case
'extended_stats'
:
{
if
(
_
.
keys
(
$scope
.
agg
.
meta
).
length
===
0
)
{
if
(
_
.
keys
(
$scope
.
agg
.
meta
).
length
===
0
)
{
$scope
.
agg
.
meta
.
std_deviation_bounds_lower
=
true
;
$scope
.
agg
.
meta
.
std_deviation_bounds_lower
=
true
;
$scope
.
agg
.
meta
.
std_deviation_bounds_upper
=
true
;
$scope
.
agg
.
meta
.
std_deviation_bounds_upper
=
true
;
}
}
var
stats
=
_
.
reduce
(
$scope
.
agg
.
meta
,
function
(
memo
,
val
,
key
)
{
var
stats
=
_
.
reduce
(
if
(
val
)
{
$scope
.
agg
.
meta
,
var
def
=
_
.
find
(
$scope
.
extendedStats
,
{
value
:
key
});
function
(
memo
,
val
,
key
)
{
memo
.
push
(
def
.
text
);
if
(
val
)
{
}
var
def
=
_
.
find
(
$scope
.
extendedStats
,
{
value
:
key
});
return
memo
;
memo
.
push
(
def
.
text
);
},
[]);
}
return
memo
;
},
[]
);
$scope
.
settingsLinkText
=
'Stats: '
+
stats
.
join
(
', '
);
$scope
.
settingsLinkText
=
'Stats: '
+
stats
.
join
(
', '
);
break
;
break
;
...
@@ -103,8 +105,8 @@ function (angular, _, queryDef) {
...
@@ -103,8 +105,8 @@ function (angular, _, queryDef) {
}
}
case
'raw_document'
:
{
case
'raw_document'
:
{
$scope
.
agg
.
settings
.
size
=
$scope
.
agg
.
settings
.
size
||
500
;
$scope
.
agg
.
settings
.
size
=
$scope
.
agg
.
settings
.
size
||
500
;
$scope
.
settingsLinkText
=
'Size: '
+
$scope
.
agg
.
settings
.
size
;
$scope
.
settingsLinkText
=
'Size: '
+
$scope
.
agg
.
settings
.
size
;
$scope
.
target
.
metrics
.
splice
(
0
,
$scope
.
target
.
metrics
.
length
,
$scope
.
agg
);
$scope
.
target
.
metrics
.
splice
(
0
,
$scope
.
target
.
metrics
.
length
,
$scope
.
agg
);
$scope
.
target
.
bucketAggs
=
[];
$scope
.
target
.
bucketAggs
=
[];
break
;
break
;
...
@@ -115,7 +117,7 @@ function (angular, _, queryDef) {
...
@@ -115,7 +117,7 @@ function (angular, _, queryDef) {
// but having it like this simplifes the query_builder
// but having it like this simplifes the query_builder
var
inlineScript
=
$scope
.
agg
.
inlineScript
;
var
inlineScript
=
$scope
.
agg
.
inlineScript
;
if
(
inlineScript
)
{
if
(
inlineScript
)
{
$scope
.
agg
.
settings
.
script
=
{
inline
:
inlineScript
};
$scope
.
agg
.
settings
.
script
=
{
inline
:
inlineScript
};
}
else
{
}
else
{
delete
$scope
.
agg
.
settings
.
script
;
delete
$scope
.
agg
.
settings
.
script
;
}
}
...
@@ -135,15 +137,15 @@ function (angular, _, queryDef) {
...
@@ -135,15 +137,15 @@ function (angular, _, queryDef) {
$scope
.
onChange
();
$scope
.
onChange
();
};
};
$scope
.
updateMovingAvgModelSettings
=
function
()
{
$scope
.
updateMovingAvgModelSettings
=
function
()
{
var
modelSettingsKeys
=
[];
var
modelSettingsKeys
=
[];
var
modelSettings
=
queryDef
.
getMovingAvgSettings
(
$scope
.
agg
.
settings
.
model
,
false
);
var
modelSettings
=
queryDef
.
getMovingAvgSettings
(
$scope
.
agg
.
settings
.
model
,
false
);
for
(
var
i
=
0
;
i
<
modelSettings
.
length
;
i
++
)
{
for
(
var
i
=
0
;
i
<
modelSettings
.
length
;
i
++
)
{
modelSettingsKeys
.
push
(
modelSettings
[
i
].
value
);
modelSettingsKeys
.
push
(
modelSettings
[
i
].
value
);
}
}
for
(
var
key
in
$scope
.
agg
.
settings
.
settings
)
{
for
(
var
key
in
$scope
.
agg
.
settings
.
settings
)
{
if
(
(
$scope
.
agg
.
settings
.
settings
[
key
]
===
null
)
||
(
modelSettingsKeys
.
indexOf
(
key
)
===
-
1
)
)
{
if
(
$scope
.
agg
.
settings
.
settings
[
key
]
===
null
||
modelSettingsKeys
.
indexOf
(
key
)
===
-
1
)
{
delete
$scope
.
agg
.
settings
.
settings
[
key
];
delete
$scope
.
agg
.
settings
.
settings
[
key
];
}
}
}
}
...
@@ -166,17 +168,21 @@ function (angular, _, queryDef) {
...
@@ -166,17 +168,21 @@ function (angular, _, queryDef) {
if
(
$scope
.
agg
.
type
===
'cardinality'
)
{
if
(
$scope
.
agg
.
type
===
'cardinality'
)
{
return
$scope
.
getFields
();
return
$scope
.
getFields
();
}
}
return
$scope
.
getFields
({
$fieldType
:
'number'
});
return
$scope
.
getFields
({
$fieldType
:
'number'
});
};
};
$scope
.
addMetricAgg
=
function
()
{
$scope
.
addMetricAgg
=
function
()
{
var
addIndex
=
metricAggs
.
length
;
var
addIndex
=
metricAggs
.
length
;
var
id
=
_
.
reduce
(
$scope
.
target
.
bucketAggs
.
concat
(
$scope
.
target
.
metrics
),
function
(
max
,
val
)
{
var
id
=
_
.
reduce
(
return
parseInt
(
val
.
id
)
>
max
?
parseInt
(
val
.
id
)
:
max
;
$scope
.
target
.
bucketAggs
.
concat
(
$scope
.
target
.
metrics
),
},
0
);
function
(
max
,
val
)
{
return
parseInt
(
val
.
id
)
>
max
?
parseInt
(
val
.
id
)
:
max
;
},
0
);
metricAggs
.
splice
(
addIndex
,
0
,
{
type
:
"count"
,
field
:
"select field"
,
id
:
(
id
+
1
).
toString
()
});
metricAggs
.
splice
(
addIndex
,
0
,
{
type
:
'count'
,
field
:
'select field'
,
id
:
(
id
+
1
).
toString
()
});
$scope
.
onChange
();
$scope
.
onChange
();
};
};
...
@@ -194,7 +200,9 @@ function (angular, _, queryDef) {
...
@@ -194,7 +200,9 @@ function (angular, _, queryDef) {
};
};
$scope
.
init
();
$scope
.
init
();
}
}
}
);
var
module
=
angular
.
module
(
'grafana.directives'
);
module
.
directive
(
'elasticMetricAgg'
,
elasticMetricAgg
);
}
);
module
.
controller
(
'ElasticMetricAggCtrl'
,
ElasticMetricAggCtrl
);
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