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
0b285845
Commit
0b285845
authored
Dec 09, 2015
by
carl bergquist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
adds spec for query builder
parent
d3ff4bf7
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
49 additions
and
6 deletions
+49
-6
public/app/plugins/datasource/elasticsearch/metric_agg.js
+1
-1
public/app/plugins/datasource/elasticsearch/query_builder.js
+5
-1
public/app/plugins/datasource/elasticsearch/specs/query_builder_specs.ts
+43
-4
No files found.
public/app/plugins/datasource/elasticsearch/metric_agg.js
View file @
0b285845
...
...
@@ -37,7 +37,7 @@ function (angular, _, queryDef) {
$scope
.
settingsLinkText
=
''
;
$scope
.
aggDef
=
_
.
findWhere
(
$scope
.
metricAggTypes
,
{
value
:
$scope
.
agg
.
type
});
if
(
!
$scope
.
agg
.
field
&&
$scope
.
agg
.
type
!==
'moving_avg'
)
{
if
(
!
$scope
.
agg
.
field
)
{
$scope
.
agg
.
field
=
'select field'
;
}
...
...
public/app/plugins/datasource/elasticsearch/query_builder.js
View file @
0b285845
...
...
@@ -171,7 +171,11 @@ function () {
var
metricAgg
=
null
;
if
(
metric
.
type
===
'moving_avg'
)
{
metricAgg
=
{
buckets_path
:
"1"
};
if
(
metric
.
mavgSource
&&
/^
\d
*$/
.
test
(
metric
.
mavgSource
))
{
metricAgg
=
{
buckets_path
:
metric
.
mavgSource
};
}
else
{
continue
;
}
}
else
{
metricAgg
=
{
field
:
metric
.
field
};
}
...
...
public/app/plugins/datasource/elasticsearch/specs/query_builder_specs.ts
View file @
0b285845
...
...
@@ -159,10 +159,15 @@ describe('ElasticQueryBuilder', function() {
var
query
=
builder
.
build
({
metrics
:
[
{
id
:
'3'
,
type
:
'sum'
,
field
:
'@value'
},
{
id
:
'2'
,
type
:
'moving_avg'
,
field
:
'
@value
'
,
aggregation
:
'sum
'
field
:
'
3
'
,
mavgSource
:
'3
'
}
],
bucketAggs
:
[
...
...
@@ -171,9 +176,43 @@ describe('ElasticQueryBuilder', function() {
});
var
firstLevel
=
query
.
aggs
[
"3"
];
console
.
log
(
JSON
.
stringify
(
query
));
expect
(
firstLevel
.
aggs
[
"2"
]).
not
.
to
.
be
(
undefined
);
expect
(
firstLevel
.
aggs
[
"2"
].
moving_avg
).
not
.
to
.
be
(
undefined
);
expect
(
firstLevel
.
aggs
[
"2"
].
moving_avg
.
buckets_path
).
to
.
be
(
"99"
);
expect
(
firstLevel
.
aggs
[
"2"
].
moving_avg
.
buckets_path
).
to
.
be
(
"3"
);
});
it
(
'with broken moving average'
,
function
()
{
var
query
=
builder
.
build
({
metrics
:
[
{
id
:
'3'
,
type
:
'sum'
,
field
:
'@value'
},
{
id
:
'2'
,
type
:
'moving_avg'
,
field
:
'3'
,
mavgSource
:
'3'
},
{
id
:
'4'
,
type
:
'moving_avg'
,
field
:
'3'
,
mavgSource
:
'Metric to apply moving average'
}
],
bucketAggs
:
[
{
type
:
'date_histogram'
,
field
:
'@timestamp'
,
id
:
'3'
}
],
});
var
firstLevel
=
query
.
aggs
[
"3"
];
expect
(
firstLevel
.
aggs
[
"2"
]).
not
.
to
.
be
(
undefined
);
expect
(
firstLevel
.
aggs
[
"2"
].
moving_avg
).
not
.
to
.
be
(
undefined
);
expect
(
firstLevel
.
aggs
[
"2"
].
moving_avg
.
buckets_path
).
to
.
be
(
"3"
);
expect
(
firstLevel
.
aggs
[
"4"
]).
to
.
be
(
undefined
);
});
});
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