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
2205ce53
Commit
2205ce53
authored
Jun 20, 2016
by
Leandro Piccilli
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add some tests for ES 5.x
parent
0d34740a
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
122 additions
and
1 deletions
+122
-1
public/app/plugins/datasource/elasticsearch/specs/datasource_specs.ts
+72
-1
public/app/plugins/datasource/elasticsearch/specs/query_builder_specs.ts
+44
-0
public/app/plugins/datasource/elasticsearch/specs/query_def_specs.ts
+6
-0
No files found.
public/app/plugins/datasource/elasticsearch/specs/datasource_specs.ts
View file @
2205ce53
...
...
@@ -11,7 +11,7 @@ describe('ElasticDatasource', function() {
beforeEach
(
angularMocks
.
module
(
'grafana.core'
));
beforeEach
(
angularMocks
.
module
(
'grafana.services'
));
beforeEach
(
ctx
.
providePhase
([
'templateSrv'
,
'backendSrv'
]));
beforeEach
(
ctx
.
providePhase
([
'templateSrv'
,
'backendSrv'
,
'timeSrv'
]));
beforeEach
(
angularMocks
.
inject
(
function
(
$q
,
$rootScope
,
$httpBackend
,
$injector
)
{
ctx
.
$q
=
$q
;
...
...
@@ -112,4 +112,75 @@ describe('ElasticDatasource', function() {
});
});
describe
(
'When issuing aggregation query on es5.x'
,
function
()
{
var
requestOptions
,
parts
,
header
;
beforeEach
(
function
()
{
createDatasource
({
url
:
'http://es.com'
,
index
:
'test'
,
jsonData
:
{
esVersion
:
'5'
}});
ctx
.
backendSrv
.
datasourceRequest
=
function
(
options
)
{
requestOptions
=
options
;
return
ctx
.
$q
.
when
({
data
:
{
responses
:
[]}});
};
ctx
.
ds
.
query
({
range
:
{
from
:
moment
([
2015
,
4
,
30
,
10
]),
to
:
moment
([
2015
,
5
,
1
,
10
])
},
targets
:
[{
bucketAggs
:
[
{
type
:
'date_histogram'
,
field
:
'@timestamp'
,
id
:
'2'
}
],
metrics
:
[
{
type
:
'count'
}],
query
:
'test'
}
]
});
ctx
.
$rootScope
.
$apply
();
parts
=
requestOptions
.
data
.
split
(
'
\
n'
);
header
=
angular
.
fromJson
(
parts
[
0
]);
});
it
(
'should not set search type to count'
,
function
()
{
expect
(
header
.
search_type
).
to
.
not
.
eql
(
'count'
);
});
it
(
'should set size to 0'
,
function
()
{
var
body
=
angular
.
fromJson
(
parts
[
1
]);
expect
(
body
.
size
).
to
.
be
(
0
);
});
});
describe
(
'When issuing metricFind query on es5.x'
,
function
()
{
var
requestOptions
,
parts
,
header
;
beforeEach
(
function
()
{
createDatasource
({
url
:
'http://es.com'
,
index
:
'test'
,
jsonData
:
{
esVersion
:
'5'
}});
ctx
.
backendSrv
.
datasourceRequest
=
function
(
options
)
{
requestOptions
=
options
;
return
ctx
.
$q
.
when
({
data
:
{
responses
:
[{
aggregations
:
{
"1"
:
[{
buckets
:
{
text
:
'test'
,
value
:
'1'
}}]}}]
}
});
};
ctx
.
ds
.
metricFindQuery
(
'{"find": "terms", "field": "test"}'
);
ctx
.
$rootScope
.
$apply
();
parts
=
requestOptions
.
data
.
split
(
'
\
n'
);
header
=
angular
.
fromJson
(
parts
[
0
]);
});
it
(
'should not set search type to count'
,
function
()
{
expect
(
header
.
search_type
).
to
.
not
.
eql
(
'count'
);
});
it
(
'should set size to 0'
,
function
()
{
var
body
=
angular
.
fromJson
(
parts
[
1
]);
expect
(
body
.
size
).
to
.
be
(
0
);
});
});
});
public/app/plugins/datasource/elasticsearch/specs/query_builder_specs.ts
View file @
2205ce53
...
...
@@ -20,6 +20,22 @@ describe('ElasticQueryBuilder', function() {
expect
(
query
.
aggs
[
"1"
].
date_histogram
.
extended_bounds
.
min
).
to
.
be
(
"$timeFrom"
);
});
it
(
'with defaults on es5.x'
,
function
()
{
var
builder_5x
=
new
ElasticQueryBuilder
({
timeField
:
'@timestamp'
,
esVersion
:
5
});
var
query
=
builder_5x
.
build
({
metrics
:
[{
type
:
'Count'
,
id
:
'0'
}],
timeField
:
'@timestamp'
,
bucketAggs
:
[{
type
:
'date_histogram'
,
field
:
'@timestamp'
,
id
:
'1'
}],
});
expect
(
query
.
query
.
bool
.
must
[
0
].
range
[
"@timestamp"
].
gte
).
to
.
be
(
"$timeFrom"
);
expect
(
query
.
aggs
[
"1"
].
date_histogram
.
extended_bounds
.
min
).
to
.
be
(
"$timeFrom"
);
});
it
(
'with multiple bucket aggs'
,
function
()
{
var
query
=
builder
.
build
({
metrics
:
[{
type
:
'count'
,
id
:
'1'
}],
...
...
@@ -143,6 +159,34 @@ describe('ElasticQueryBuilder', function() {
expect
(
query
.
aggs
[
"2"
].
aggs
[
"4"
].
date_histogram
.
field
).
to
.
be
(
"@timestamp"
);
});
it
(
'with filters aggs on es5.x'
,
function
()
{
var
builder_5x
=
new
ElasticQueryBuilder
({
timeField
:
'@timestamp'
,
esVersion
:
5
});
var
query
=
builder_5x
.
build
({
metrics
:
[{
type
:
'count'
,
id
:
'1'
}],
timeField
:
'@timestamp'
,
bucketAggs
:
[
{
id
:
'2'
,
type
:
'filters'
,
settings
:
{
filters
:
[
{
query
:
'@metric:cpu'
},
{
query
:
'@metric:logins.count'
},
]
}
},
{
type
:
'date_histogram'
,
field
:
'@timestamp'
,
id
:
'4'
}
],
});
expect
(
query
.
aggs
[
"2"
].
filters
.
filters
[
"@metric:cpu"
].
query_string
.
query
).
to
.
be
(
"@metric:cpu"
);
expect
(
query
.
aggs
[
"2"
].
filters
.
filters
[
"@metric:logins.count"
].
query_string
.
query
).
to
.
be
(
"@metric:logins.count"
);
expect
(
query
.
aggs
[
"2"
].
aggs
[
"4"
].
date_histogram
.
field
).
to
.
be
(
"@timestamp"
);
});
it
(
'with raw_document metric'
,
function
()
{
var
query
=
builder
.
build
({
metrics
:
[{
type
:
'raw_document'
,
id
:
'1'
}],
...
...
public/app/plugins/datasource/elasticsearch/specs/query_def_specs.ts
View file @
2205ce53
...
...
@@ -95,5 +95,11 @@ describe('ElasticQueryDef', function() {
expect
(
queryDef
.
getMetricAggTypes
(
2
).
length
).
to
.
be
(
11
);
});
});
describe
(
'using esversion 5'
,
function
()
{
it
(
'should get pipeline aggs'
,
function
()
{
expect
(
queryDef
.
getMetricAggTypes
(
5
).
length
).
to
.
be
(
11
);
});
});
});
});
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