mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Add some tests for ES 5.x
This commit is contained in:
parent
0d34740a62
commit
2205ce5354
@ -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);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -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'}],
|
||||
|
@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user