mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
ES nested fields autocomplete (#6043)
* Re-create PR #4527 from @arcolife: fixes #4526 - add nested support to fieldname autocomplete; Also: - update _mapping to first use given time range for deducting index mapping, then fallback to today's date based index name * (elasticsearch): refactor getFields() method. * (elasticsearch): add tests for getFields() method. * (elasticsearch): fixed _get() method (tests was broken after @arcolife commit).
This commit is contained in:
committed by
Torkel Ödegaard
parent
4e567b5f02
commit
3be84b00d5
@@ -1,4 +1,4 @@
|
||||
|
||||
import _ from 'lodash';
|
||||
import {describe, beforeEach, it, sinon, expect, angularMocks} from 'test/lib/common';
|
||||
import moment from 'moment';
|
||||
import angular from 'angular';
|
||||
@@ -112,4 +112,101 @@ describe('ElasticDatasource', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('When getting fields', function() {
|
||||
var requestOptions, parts, header;
|
||||
|
||||
beforeEach(function() {
|
||||
createDatasource({url: 'http://es.com', index: 'metricbeat'});
|
||||
|
||||
ctx.backendSrv.datasourceRequest = function(options) {
|
||||
requestOptions = options;
|
||||
return ctx.$q.when({data: {
|
||||
metricbeat: {
|
||||
mappings: {
|
||||
metricsets: {
|
||||
_all: {},
|
||||
properties: {
|
||||
'@timestamp': {type: 'date'},
|
||||
beat: {
|
||||
properties: {
|
||||
name: {type: 'string'},
|
||||
hostname: {type: 'string'},
|
||||
}
|
||||
},
|
||||
system: {
|
||||
properties: {
|
||||
cpu: {
|
||||
properties: {
|
||||
system: {type: 'float'},
|
||||
user: {type: 'float'},
|
||||
}
|
||||
},
|
||||
process: {
|
||||
properties: {
|
||||
cpu: {
|
||||
properties: {
|
||||
total: {type: 'float'}
|
||||
}
|
||||
},
|
||||
name: {type: 'string'},
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}});
|
||||
};
|
||||
});
|
||||
|
||||
it('should return nested fields', function() {
|
||||
ctx.ds.getFields({
|
||||
find: 'fields',
|
||||
query: '*'
|
||||
}).then((fieldObjects) => {
|
||||
var fields = _.map(fieldObjects, 'text');
|
||||
expect(fields).to.eql([
|
||||
'@timestamp',
|
||||
'beat.name',
|
||||
'beat.hostname',
|
||||
'system.cpu.system',
|
||||
'system.cpu.user',
|
||||
'system.process.cpu.total',
|
||||
'system.process.name'
|
||||
]);
|
||||
});
|
||||
ctx.$rootScope.$apply();
|
||||
});
|
||||
|
||||
it('should return fields related to query type', function() {
|
||||
ctx.ds.getFields({
|
||||
find: 'fields',
|
||||
query: '*',
|
||||
type: 'number'
|
||||
}).then((fieldObjects) => {
|
||||
var fields = _.map(fieldObjects, 'text');
|
||||
expect(fields).to.eql([
|
||||
'system.cpu.system',
|
||||
'system.cpu.user',
|
||||
'system.process.cpu.total'
|
||||
]);
|
||||
});
|
||||
|
||||
ctx.ds.getFields({
|
||||
find: 'fields',
|
||||
query: '*',
|
||||
type: 'date'
|
||||
}).then((fieldObjects) => {
|
||||
var fields = _.map(fieldObjects, 'text');
|
||||
expect(fields).to.eql([
|
||||
'@timestamp'
|
||||
]);
|
||||
});
|
||||
|
||||
ctx.$rootScope.$apply();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user