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
8a39b32b
Commit
8a39b32b
authored
Sep 28, 2015
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor: moved elasticsearch specs to plugin folder and to typescript
parent
7d2646f6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
222 additions
and
229 deletions
+222
-229
public/app/plugins/datasource/elasticsearch/bucket_agg.js
+1
-1
public/app/plugins/datasource/elasticsearch/datasource.js
+4
-4
public/app/plugins/datasource/elasticsearch/directives.js
+2
-2
public/app/plugins/datasource/elasticsearch/elastic_response.js
+1
-1
public/app/plugins/datasource/elasticsearch/index_pattern.js
+0
-0
public/app/plugins/datasource/elasticsearch/metric_agg.js
+1
-1
public/app/plugins/datasource/elasticsearch/query_builder.js
+0
-0
public/app/plugins/datasource/elasticsearch/query_ctrl.js
+0
-0
public/app/plugins/datasource/elasticsearch/query_def.js
+0
-0
public/app/plugins/datasource/elasticsearch/specs/datasource_specs.ts
+57
-60
public/app/plugins/datasource/elasticsearch/specs/elastic_response_specs.ts
+0
-0
public/app/plugins/datasource/elasticsearch/specs/index_pattern_specs.ts
+34
-35
public/app/plugins/datasource/elasticsearch/specs/query_builder_specs.ts
+100
-101
public/app/plugins/datasource/elasticsearch/specs/query_ctrl_specs.ts
+21
-23
public/app/plugins/datasource/influxdb/specs/query_builder_specs.ts
+1
-1
No files found.
public/app/plugins/datasource/elasticsearch/bucket
A
gg.js
→
public/app/plugins/datasource/elasticsearch/bucket
_a
gg.js
View file @
8a39b32b
define
([
'angular'
,
'lodash'
,
'./query
D
ef'
,
'./query
_d
ef'
,
],
function
(
angular
,
_
,
queryDef
)
{
'use strict'
;
...
...
public/app/plugins/datasource/elasticsearch/datasource.js
View file @
8a39b32b
...
...
@@ -3,10 +3,10 @@ define([
'lodash'
,
'moment'
,
'kbn'
,
'./query
B
uilder'
,
'./index
P
attern'
,
'./elastic
R
esponse'
,
'./query
C
trl'
,
'./query
_b
uilder'
,
'./index
_p
attern'
,
'./elastic
_r
esponse'
,
'./query
_c
trl'
,
'./directives'
],
function
(
angular
,
_
,
moment
,
kbn
,
ElasticQueryBuilder
,
IndexPattern
,
ElasticResponse
)
{
...
...
public/app/plugins/datasource/elasticsearch/directives.js
View file @
8a39b32b
define
([
'angular'
,
'./bucket
A
gg'
,
'./metric
A
gg'
,
'./bucket
_a
gg'
,
'./metric
_a
gg'
,
],
function
(
angular
)
{
'use strict'
;
...
...
public/app/plugins/datasource/elasticsearch/elastic
R
esponse.js
→
public/app/plugins/datasource/elasticsearch/elastic
_r
esponse.js
View file @
8a39b32b
define
([
"lodash"
,
"./query
D
ef"
"./query
_d
ef"
],
function
(
_
,
queryDef
)
{
'use strict'
;
...
...
public/app/plugins/datasource/elasticsearch/index
P
attern.js
→
public/app/plugins/datasource/elasticsearch/index
_p
attern.js
View file @
8a39b32b
File moved
public/app/plugins/datasource/elasticsearch/metric
A
gg.js
→
public/app/plugins/datasource/elasticsearch/metric
_a
gg.js
View file @
8a39b32b
define
([
'angular'
,
'lodash'
,
'./query
D
ef'
'./query
_d
ef'
],
function
(
angular
,
_
,
queryDef
)
{
'use strict'
;
...
...
public/app/plugins/datasource/elasticsearch/query
B
uilder.js
→
public/app/plugins/datasource/elasticsearch/query
_b
uilder.js
View file @
8a39b32b
File moved
public/app/plugins/datasource/elasticsearch/query
C
trl.js
→
public/app/plugins/datasource/elasticsearch/query
_c
trl.js
View file @
8a39b32b
File moved
public/app/plugins/datasource/elasticsearch/query
D
ef.js
→
public/app/plugins/datasource/elasticsearch/query
_d
ef.js
View file @
8a39b32b
File moved
public/
test/specs/elasticsearch-specs.j
s
→
public/
app/plugins/datasource/elasticsearch/specs/datasource_specs.t
s
View file @
8a39b32b
define
([
'./helpers'
,
'moment'
,
'angular'
,
'app/plugins/datasource/elasticsearch/datasource'
,
],
function
(
helpers
,
moment
,
angular
)
{
'use strict'
;
///<amd-dependency path="../datasource" />
///<amd-dependency path="test/specs/helpers" name="helpers" />
describe
(
'ElasticDatasource'
,
function
()
{
var
ctx
=
new
helpers
.
ServiceTestContext
();
import
{
describe
,
beforeEach
,
it
,
sinon
,
expect
,
angularMocks
}
from
'test/lib/common'
;
import
moment
=
require
(
'moment'
);
import
angular
=
require
(
'angular'
);
beforeEach
(
module
(
'grafana.services'
));
beforeEach
(
ctx
.
providePhase
([
'templateSrv'
,
'backendSrv'
]));
beforeEach
(
ctx
.
createService
(
'ElasticDatasource'
));
beforeEach
(
function
()
{
ctx
.
ds
=
new
ctx
.
service
({
jsonData
:
{}});
});
declare
var
helpers
:
any
;
describe
(
'When testing datasource with index pattern'
,
function
()
{
beforeEach
(
function
()
{
ctx
.
ds
=
new
ctx
.
service
({
url
:
'http://es.com'
,
index
:
'[asd-]YYYY.MM.DD'
,
jsonData
:
{
interval
:
'Daily'
}
});
describe
(
'ElasticDatasource'
,
function
()
{
var
ctx
=
new
helpers
.
ServiceTestContext
();
beforeEach
(
angularMocks
.
module
(
'grafana.services'
));
beforeEach
(
ctx
.
providePhase
([
'templateSrv'
,
'backendSrv'
]));
beforeEach
(
ctx
.
createService
(
'ElasticDatasource'
));
beforeEach
(
function
()
{
ctx
.
ds
=
new
ctx
.
service
({
jsonData
:
{}});
});
describe
(
'When testing datasource with index pattern'
,
function
()
{
beforeEach
(
function
()
{
ctx
.
ds
=
new
ctx
.
service
({
url
:
'http://es.com'
,
index
:
'[asd-]YYYY.MM.DD'
,
jsonData
:
{
interval
:
'Daily'
}
});
});
it
(
'should translate index pattern to current day'
,
function
()
{
var
requestOptions
;
ctx
.
backendSrv
.
datasourceRequest
=
function
(
options
)
{
requestOptions
=
options
;
return
ctx
.
$q
.
when
({});
};
it
(
'should translate index pattern to current day'
,
function
()
{
var
requestOptions
;
ctx
.
backendSrv
.
datasourceRequest
=
function
(
options
)
{
requestOptions
=
options
;
return
ctx
.
$q
.
when
({});
};
ctx
.
ds
.
testDatasource
();
ctx
.
$rootScope
.
$apply
();
ctx
.
ds
.
testDatasource
();
ctx
.
$rootScope
.
$apply
();
var
today
=
moment
().
format
(
"YYYY.MM.DD"
);
expect
(
requestOptions
.
url
).
to
.
be
(
"http://es.com/asd-"
+
today
+
'/_stats'
);
});
var
today
=
moment
().
format
(
"YYYY.MM.DD"
);
expect
(
requestOptions
.
url
).
to
.
be
(
"http://es.com/asd-"
+
today
+
'/_stats'
);
});
});
describe
(
'When issueing metric query with interval pattern'
,
function
()
{
beforeEach
(
function
()
{
ctx
.
ds
=
new
ctx
.
service
({
url
:
'http://es.com'
,
index
:
'[asd-]YYYY.MM.DD'
,
jsonData
:
{
interval
:
'Daily'
}
});
describe
(
'When issueing metric query with interval pattern'
,
function
()
{
beforeEach
(
function
()
{
ctx
.
ds
=
new
ctx
.
service
({
url
:
'http://es.com'
,
index
:
'[asd-]YYYY.MM.DD'
,
jsonData
:
{
interval
:
'Daily'
}
});
});
it
(
'should translate index pattern to current day'
,
function
()
{
var
requestOptions
;
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
:
[],
metrics
:
[]
}]
});
it
(
'should translate index pattern to current day'
,
function
()
{
var
requestOptions
;
ctx
.
backendSrv
.
datasourceRequest
=
function
(
options
)
{
requestOptions
=
options
;
return
ctx
.
$q
.
when
({
data
:
{
responses
:
[]}});
};
ctx
.
$rootScope
.
$apply
();
var
parts
=
requestOptions
.
data
.
split
(
'
\
n'
);
var
header
=
angular
.
fromJson
(
parts
[
0
]);
expect
(
header
.
index
).
to
.
eql
([
'asd-2015.05.30'
,
'asd-2015.05.31'
,
'asd-2015.06.01'
]);
ctx
.
ds
.
query
({
range
:
{
from
:
moment
([
2015
,
4
,
30
,
10
]),
to
:
moment
([
2015
,
5
,
1
,
10
])
},
targets
:
[{
bucketAggs
:
[],
metrics
:
[]
}]
});
ctx
.
$rootScope
.
$apply
();
var
parts
=
requestOptions
.
data
.
split
(
'
\
n'
);
var
header
=
angular
.
fromJson
(
parts
[
0
]);
expect
(
header
.
index
).
to
.
eql
([
'asd-2015.05.30'
,
'asd-2015.05.31'
,
'asd-2015.06.01'
]);
});
});
});
public/
test/specs/elasticsearch-response-specs.j
s
→
public/
app/plugins/datasource/elasticsearch/specs/elastic_response_specs.t
s
View file @
8a39b32b
This diff is collapsed.
Click to expand it.
public/
test/specs/elasticsearch-indexPattern-specs.j
s
→
public/
app/plugins/datasource/elasticsearch/specs/index_pattern_specs.t
s
View file @
8a39b32b
define
([
'moment'
,
'app/plugins/datasource/elasticsearch/indexPattern'
],
function
(
moment
,
IndexPattern
)
{
'use strict'
;
///<amd-dependency path="../index_pattern" name="IndexPattern"/>
///<amd-dependency path="test/specs/helpers" name="helpers" />
describe
(
'IndexPattern'
,
function
()
{
import
{
describe
,
beforeEach
,
it
,
sinon
,
expect
}
from
'test/lib/common'
;
import
moment
=
require
(
'moment'
);
describe
(
'when getting index for today'
,
function
()
{
it
(
'should return correct index name'
,
function
()
{
var
pattern
=
new
IndexPattern
(
'[asd-]YYYY.MM.DD'
,
'Daily'
);
var
expected
=
'asd-'
+
moment
().
format
(
'YYYY.MM.DD'
);
declare
var
IndexPattern
:
any
;
expect
(
pattern
.
getIndexForToday
()).
to
.
be
(
expected
);
});
describe
(
'IndexPattern'
,
function
()
{
describe
(
'when getting index for today'
,
function
()
{
it
(
'should return correct index name'
,
function
()
{
var
pattern
=
new
IndexPattern
(
'[asd-]YYYY.MM.DD'
,
'Daily'
);
var
expected
=
'asd-'
+
moment
().
format
(
'YYYY.MM.DD'
);
expect
(
pattern
.
getIndexForToday
()).
to
.
be
(
expected
);
});
});
describe
(
'when getting index list for time range'
,
function
()
{
describe
(
'when getting index list for time range'
,
function
()
{
describe
(
'no interval'
,
function
()
{
it
(
'should return correct index'
,
function
()
{
var
pattern
=
new
IndexPattern
(
'my-metrics'
);
var
from
=
new
Date
(
2015
,
4
,
30
,
1
,
2
,
3
);
var
to
=
new
Date
(
2015
,
5
,
1
,
12
,
5
,
6
);
expect
(
pattern
.
getIndexList
(
from
,
to
)).
to
.
eql
(
'my-metrics'
);
});
describe
(
'no interval'
,
function
()
{
it
(
'should return correct index'
,
function
()
{
var
pattern
=
new
IndexPattern
(
'my-metrics'
);
var
from
=
new
Date
(
2015
,
4
,
30
,
1
,
2
,
3
);
var
to
=
new
Date
(
2015
,
5
,
1
,
12
,
5
,
6
);
expect
(
pattern
.
getIndexList
(
from
,
to
)).
to
.
eql
(
'my-metrics'
);
});
});
describe
(
'daily'
,
function
()
{
it
(
'should return correct index list'
,
function
()
{
var
pattern
=
new
IndexPattern
(
'[asd-]YYYY.MM.DD'
,
'Daily'
);
var
from
=
new
Date
(
1432940523000
);
var
to
=
new
Date
(
1433153106000
);
describe
(
'daily'
,
function
()
{
var
expected
=
[
'asd-2015.05.29'
,
'asd-2015.05.30'
,
'asd-2015.05.31'
,
'asd-2015.06.01'
,
];
it
(
'should return correct index list'
,
function
()
{
var
pattern
=
new
IndexPattern
(
'[asd-]YYYY.MM.DD'
,
'Daily'
);
var
from
=
new
Date
(
1432940523000
);
var
to
=
new
Date
(
1433153106000
);
expect
(
pattern
.
getIndexList
(
from
,
to
)).
to
.
eql
(
expected
);
});
var
expected
=
[
'asd-2015.05.29'
,
'asd-2015.05.30'
,
'asd-2015.05.31'
,
'asd-2015.06.01'
,
];
expect
(
pattern
.
getIndexList
(
from
,
to
)).
to
.
eql
(
expected
);
});
});
});
});
public/
test/specs/elasticsearch-querybuilder-specs.j
s
→
public/
app/plugins/datasource/elasticsearch/specs/query_builder_specs.t
s
View file @
8a39b32b
define
([
'app/plugins/datasource/elasticsearch/queryBuilder'
],
function
(
ElasticQueryBuilder
)
{
'use strict'
;
///<amd-dependency path="../query_builder" name="ElasticQueryBuilder"/>
describe
(
'ElasticQueryBuilder'
,
function
()
{
var
builder
;
import
{
describe
,
beforeEach
,
it
,
sinon
,
expect
}
from
'test/lib/common'
;
beforeEach
(
function
()
{
builder
=
new
ElasticQueryBuilder
({
timeField
:
'@timestamp'
});
});
declare
var
ElasticQueryBuilder
:
any
;
describe
(
'ElasticQueryBuilder'
,
function
()
{
var
builder
;
it
(
'with defaults'
,
function
()
{
var
query
=
builder
.
build
({
metrics
:
[{
type
:
'Count'
,
id
:
'0'
}],
timeField
:
'@timestamp'
,
bucketAggs
:
[{
type
:
'date_histogram'
,
field
:
'@timestamp'
,
id
:
'1'
}],
});
beforeEach
(
function
()
{
builder
=
new
ElasticQueryBuilder
({
timeField
:
'@timestamp'
});
});
expect
(
query
.
query
.
filtered
.
filter
.
bool
.
must
[
0
].
range
[
"@timestamp"
].
gte
).
to
.
be
(
"$timeFrom"
);
expect
(
query
.
aggs
[
"1"
].
date_histogram
.
extended_bounds
.
min
).
to
.
be
(
"$timeFrom"
);
it
(
'with defaults'
,
function
()
{
var
query
=
builder
.
build
({
metrics
:
[{
type
:
'Count'
,
id
:
'0'
}],
timeField
:
'@timestamp'
,
bucketAggs
:
[{
type
:
'date_histogram'
,
field
:
'@timestamp'
,
id
:
'1'
}],
});
it
(
'with raw query'
,
function
()
{
var
query
=
builder
.
build
({
rawQuery
:
'{"query": "$lucene_query"}'
,
});
expect
(
query
.
query
.
filtered
.
filter
.
bool
.
must
[
0
].
range
[
"@timestamp"
].
gte
).
to
.
be
(
"$timeFrom"
);
expect
(
query
.
aggs
[
"1"
].
date_histogram
.
extended_bounds
.
min
).
to
.
be
(
"$timeFrom"
);
});
expect
(
query
.
query
).
to
.
be
(
"$lucene_query"
);
it
(
'with raw query'
,
function
()
{
var
query
=
builder
.
build
({
rawQuery
:
'{"query": "$lucene_query"}'
,
});
it
(
'with multiple bucket aggs'
,
function
()
{
var
query
=
builder
.
build
({
metrics
:
[{
type
:
'count'
,
id
:
'1'
}],
timeField
:
'@timestamp'
,
bucketAggs
:
[
{
type
:
'terms'
,
field
:
'@host'
,
id
:
'2'
},
{
type
:
'date_histogram'
,
field
:
'@timestamp'
,
id
:
'3'
}
],
});
expect
(
query
.
aggs
[
"2"
].
terms
.
field
).
to
.
be
(
"@host"
);
expect
(
query
.
aggs
[
"2"
].
aggs
[
"3"
].
date_histogram
.
field
).
to
.
be
(
"@timestamp"
);
expect
(
query
.
query
).
to
.
be
(
"$lucene_query"
);
});
it
(
'with multiple bucket aggs'
,
function
()
{
var
query
=
builder
.
build
({
metrics
:
[{
type
:
'count'
,
id
:
'1'
}],
timeField
:
'@timestamp'
,
bucketAggs
:
[
{
type
:
'terms'
,
field
:
'@host'
,
id
:
'2'
},
{
type
:
'date_histogram'
,
field
:
'@timestamp'
,
id
:
'3'
}
],
});
it
(
'with select field'
,
function
()
{
var
query
=
builder
.
build
({
metrics
:
[{
type
:
'avg'
,
field
:
'@value'
,
id
:
'1'
}],
bucketAggs
:
[{
type
:
'date_histogram'
,
field
:
'@timestamp'
,
id
:
'2'
}],
},
100
,
1000
);
expect
(
query
.
aggs
[
"2"
].
terms
.
field
).
to
.
be
(
"@host"
);
expect
(
query
.
aggs
[
"2"
].
aggs
[
"3"
].
date_histogram
.
field
).
to
.
be
(
"@timestamp"
);
});
var
aggs
=
query
.
aggs
[
"2"
].
aggs
;
expect
(
aggs
[
"1"
].
avg
.
field
).
to
.
be
(
"@value"
);
});
it
(
'with select field'
,
function
()
{
var
query
=
builder
.
build
({
metrics
:
[{
type
:
'avg'
,
field
:
'@value'
,
id
:
'1'
}],
bucketAggs
:
[{
type
:
'date_histogram'
,
field
:
'@timestamp'
,
id
:
'2'
}],
},
100
,
1000
);
it
(
'with term agg and order by metric agg'
,
function
()
{
var
query
=
builder
.
build
({
metrics
:
[
{
type
:
'count'
,
id
:
'1'
},
{
type
:
'avg'
,
field
:
'@value'
,
id
:
'5'
}
],
bucketAggs
:
[
{
type
:
'terms'
,
field
:
'@host'
,
settings
:
{
size
:
5
,
order
:
'asc'
,
orderBy
:
'5'
},
id
:
'2'
},
{
type
:
'date_histogram'
,
field
:
'@timestamp'
,
id
:
'3'
}
],
},
100
,
1000
);
var
firstLevel
=
query
.
aggs
[
"2"
];
var
secondLevel
=
firstLevel
.
aggs
[
"3"
];
expect
(
firstLevel
.
aggs
[
"5"
].
avg
.
field
).
to
.
be
(
"@value"
);
expect
(
secondLevel
.
aggs
[
"5"
].
avg
.
field
).
to
.
be
(
"@value"
);
});
var
aggs
=
query
.
aggs
[
"2"
].
aggs
;
expect
(
aggs
[
"1"
].
avg
.
field
).
to
.
be
(
"@value"
);
});
it
(
'with term agg and order by metric agg'
,
function
()
{
var
query
=
builder
.
build
({
metrics
:
[
{
type
:
'count'
,
id
:
'1'
},
{
type
:
'avg'
,
field
:
'@value'
,
id
:
'5'
}
],
bucketAggs
:
[
{
type
:
'terms'
,
field
:
'@host'
,
settings
:
{
size
:
5
,
order
:
'asc'
,
orderBy
:
'5'
},
id
:
'2'
},
{
type
:
'date_histogram'
,
field
:
'@timestamp'
,
id
:
'3'
}
],
},
100
,
1000
);
var
firstLevel
=
query
.
aggs
[
"2"
];
var
secondLevel
=
firstLevel
.
aggs
[
"3"
];
expect
(
firstLevel
.
aggs
[
"5"
].
avg
.
field
).
to
.
be
(
"@value"
);
expect
(
secondLevel
.
aggs
[
"5"
].
avg
.
field
).
to
.
be
(
"@value"
);
});
it
(
'with metric percentiles'
,
function
()
{
var
query
=
builder
.
build
({
metrics
:
[
{
id
:
'1'
,
type
:
'percentiles'
,
field
:
'@load_time'
,
settings
:
{
percents
:
[
1
,
2
,
3
,
4
]
}
it
(
'with metric percentiles'
,
function
()
{
var
query
=
builder
.
build
({
metrics
:
[
{
id
:
'1'
,
type
:
'percentiles'
,
field
:
'@load_time'
,
settings
:
{
percents
:
[
1
,
2
,
3
,
4
]
}
],
bucketAggs
:
[
{
type
:
'date_histogram'
,
field
:
'@timestamp'
,
id
:
'3'
}
],
},
100
,
1000
);
}
],
bucketAggs
:
[
{
type
:
'date_histogram'
,
field
:
'@timestamp'
,
id
:
'3'
}
],
},
100
,
1000
);
var
firstLevel
=
query
.
aggs
[
"3"
];
var
firstLevel
=
query
.
aggs
[
"3"
];
expect
(
firstLevel
.
aggs
[
"1"
].
percentiles
.
field
).
to
.
be
(
"@load_time"
);
expect
(
firstLevel
.
aggs
[
"1"
].
percentiles
.
percents
).
to
.
eql
([
1
,
2
,
3
,
4
]);
});
expect
(
firstLevel
.
aggs
[
"1"
].
percentiles
.
field
).
to
.
be
(
"@load_time"
);
expect
(
firstLevel
.
aggs
[
"1"
].
percentiles
.
percents
).
to
.
eql
([
1
,
2
,
3
,
4
]);
});
it
(
'with filters aggs'
,
function
()
{
var
query
=
builder
.
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
.
query_string
.
query
).
to
.
be
(
"@metric:cpu"
);
expect
(
query
.
aggs
[
"2"
].
filters
.
filters
[
"@metric:logins.count"
].
query
.
query_string
.
query
).
to
.
be
(
"@metric:logins.count"
);
expect
(
query
.
aggs
[
"2"
].
aggs
[
"4"
].
date_histogram
.
field
).
to
.
be
(
"@timestamp"
);
it
(
'with filters aggs'
,
function
()
{
var
query
=
builder
.
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
.
query_string
.
query
).
to
.
be
(
"@metric:cpu"
);
expect
(
query
.
aggs
[
"2"
].
filters
.
filters
[
"@metric:logins.count"
].
query
.
query_string
.
query
).
to
.
be
(
"@metric:logins.count"
);
expect
(
query
.
aggs
[
"2"
].
aggs
[
"4"
].
date_histogram
.
field
).
to
.
be
(
"@timestamp"
);
});
});
public/
test/specs/elasticsearch-queryctrl-specs.j
s
→
public/
app/plugins/datasource/elasticsearch/specs/query_ctrl_specs.t
s
View file @
8a39b32b
define
([
'./helpers'
,
'app/plugins/datasource/elasticsearch/queryCtrl'
,
'app/services/uiSegmentSrv'
],
function
(
helpers
)
{
'use strict'
;
///<amd-dependency path="../query_ctrl" />
///<amd-dependency path="app/services/uiSegmentSrv" />
///<amd-dependency path="test/specs/helpers" name="helpers" />
describe
(
'ElasticQueryCtrl'
,
function
()
{
var
ctx
=
new
helpers
.
ControllerTestContext
();
import
{
describe
,
beforeEach
,
it
,
sinon
,
expect
,
angularMocks
}
from
'test/lib/common'
;
beforeEach
(
module
(
'grafana.controllers'
));
beforeEach
(
module
(
'grafana.services'
));
beforeEach
(
ctx
.
providePhase
());
beforeEach
(
ctx
.
createControllerPhase
(
'ElasticQueryCtrl'
));
declare
var
helpers
:
any
;
beforeEach
(
function
()
{
ctx
.
scope
.
target
=
{};
ctx
.
scope
.
$parent
=
{
get_data
:
sinon
.
spy
()
};
describe
(
'ElasticQueryCtrl'
,
function
()
{
var
ctx
=
new
helpers
.
ControllerTestContext
();
ctx
.
scope
.
datasource
=
ctx
.
datasource
;
ctx
.
scope
.
datasource
.
metricFindQuery
=
sinon
.
stub
().
returns
(
ctx
.
$q
.
when
([]));
});
beforeEach
(
angularMocks
.
module
(
'grafana.controllers'
));
beforeEach
(
angularMocks
.
module
(
'grafana.services'
));
beforeEach
(
ctx
.
providePhase
());
beforeEach
(
ctx
.
createControllerPhase
(
'ElasticQueryCtrl'
));
describe
(
'init'
,
function
()
{
beforeEach
(
function
()
{
ctx
.
scope
.
init
();
});
beforeEach
(
function
()
{
ctx
.
scope
.
target
=
{};
ctx
.
scope
.
$parent
=
{
get_data
:
sinon
.
spy
()
};
});
ctx
.
scope
.
datasource
=
ctx
.
datasource
;
ctx
.
scope
.
datasource
.
metricFindQuery
=
sinon
.
stub
().
returns
(
ctx
.
$q
.
when
([]));
});
describe
(
'init'
,
function
()
{
beforeEach
(
function
()
{
ctx
.
scope
.
init
();
});
});
});
public/app/plugins/datasource/influxdb/specs/query_builder_specs.ts
View file @
8a39b32b
///<amd-dependency path="app/plugins/datasource/influxdb/query_builder" name="InfluxQueryBuilder"/>
//
import
{
describe
,
beforeEach
,
it
,
sinon
,
expect
}
from
'test/lib/common'
;
declare
var
InfluxQueryBuilder
:
any
;
...
...
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