mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
Load scenarios
This commit is contained in:
parent
252b18ccab
commit
a4a99b873c
13 changed files with 32298 additions and 51 deletions
|
@ -1,11 +0,0 @@
|
|||
var path = require('path');
|
||||
|
||||
|
||||
module.exports = function (grunt) {
|
||||
return {
|
||||
options: {
|
||||
server: 'http://localhost:9220',
|
||||
dataDir: path.join(grunt.config.get('root'), 'test/fixtures')
|
||||
}
|
||||
};
|
||||
};
|
|
@ -8,6 +8,7 @@ module.exports = {
|
|||
all: {
|
||||
src: [
|
||||
'src/**/__tests__/**/*.js',
|
||||
'test/fixtures/__tests__/*.js',
|
||||
'!src/**/public/**',
|
||||
'!src/ui/**'
|
||||
]
|
||||
|
|
|
@ -1,31 +0,0 @@
|
|||
var _ = require('lodash');
|
||||
var wreck = require('wreck');
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var colors = require('ansicolors');
|
||||
|
||||
module.exports = function (grunt) {
|
||||
grunt.registerTask('loadFixtures', 'Loads fixtures into elasticsearch', function () {
|
||||
const config = this.options();
|
||||
const done = this.async();
|
||||
const files = fs.readdirSync(config.dataDir);
|
||||
let doneProcessing = 0;
|
||||
|
||||
files.forEach(function (file) {
|
||||
wreck.post(`${config.server}/_bulk`, {
|
||||
payload: fs.createReadStream(path.join(config.dataDir, file)),
|
||||
json: true
|
||||
}, function bulkResponse(err, res, payload) {
|
||||
var status;
|
||||
if (err || res.statusCode !== 200) {
|
||||
grunt.fail.warn(err || payload);
|
||||
status = colors.red('error');
|
||||
} else {
|
||||
status = colors.green('success');
|
||||
}
|
||||
grunt.log.writeln(`[${status}] ${file}`);
|
||||
if (++doneProcessing === files.length) done();
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
|
@ -17,7 +17,6 @@ module.exports = function (grunt) {
|
|||
|
||||
grunt.registerTask('test:ui', [
|
||||
'esvm:ui',
|
||||
'loadFixtures',
|
||||
'run:testUIServer',
|
||||
'downloadSelenium',
|
||||
'run:seleniumServer',
|
||||
|
@ -29,7 +28,6 @@ module.exports = function (grunt) {
|
|||
|
||||
grunt.registerTask('test:ui:server', [
|
||||
'esvm:ui',
|
||||
'loadFixtures',
|
||||
'run:testUIServer',
|
||||
'downloadSelenium',
|
||||
'run:devSeleniumServer:keepalive'
|
||||
|
|
81
test/fixtures/__tests__/scenarioManager.js
vendored
Normal file
81
test/fixtures/__tests__/scenarioManager.js
vendored
Normal file
|
@ -0,0 +1,81 @@
|
|||
var expect = require('expect.js');
|
||||
var sinon = require('sinon');
|
||||
var Promise = require('bluebird');
|
||||
|
||||
var ScenarioManager = require('../scenarioManager');
|
||||
|
||||
describe('scenario manager', function () {
|
||||
var manager = new ScenarioManager('http://localhost:9200');
|
||||
|
||||
describe('loading and unloading', function () {
|
||||
var bulk;
|
||||
var create;
|
||||
var indicesDelete;
|
||||
beforeEach(function () {
|
||||
bulk = sinon.stub(manager.client, 'bulk', Promise.resolve);
|
||||
create = sinon.stub(manager.client.indices, 'create', Promise.resolve);
|
||||
indicesDelete = sinon.stub(manager.client.indices, 'delete', Promise.resolve);
|
||||
});
|
||||
|
||||
it('should be able to load scenarios', function (done) {
|
||||
manager.load('makelogs')
|
||||
.then(function () {
|
||||
expect(create.getCall(0).args[0].index).to.be('logstash-2015.09.17');
|
||||
expect(create.getCall(1).args[0].index).to.be('logstash-2015.09.18');
|
||||
expect(bulk.called).to.be(true);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should be able to delete all indices', function () {
|
||||
manager.deleteAll();
|
||||
expect(indicesDelete.calledWith({
|
||||
index: '*'
|
||||
})).to.be(true);
|
||||
});
|
||||
|
||||
it('should be able to delete a scenario', function () {
|
||||
manager.unload('makelogs');
|
||||
expect(indicesDelete.calledWith({
|
||||
index: ['logstash-2015.09.17', 'logstash-2015.09.18']
|
||||
})).to.be(true);
|
||||
});
|
||||
|
||||
it('should be able to reload a scenario', function (done) {
|
||||
var load = sinon.stub(manager, 'load', Promise.resolve);
|
||||
var unload = sinon.stub(manager, 'unload', Promise.resolve);
|
||||
var id = 'makelogs';
|
||||
manager.reload(id).then(function () {
|
||||
expect(load.calledWith(id)).to.be(true);
|
||||
expect(unload.calledWith(id)).to.be(true);
|
||||
|
||||
load.restore();
|
||||
unload.restore();
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
bulk.restore();
|
||||
create.restore();
|
||||
indicesDelete.restore();
|
||||
});
|
||||
});
|
||||
|
||||
it('should throw an error if the scenario is not defined', function () {
|
||||
expect(manager.load).withArgs('makelogs').to.throwError();
|
||||
});
|
||||
|
||||
it('should throw an error if an index is not defined when clearing', function () {
|
||||
expect(manager.unload).to.throwError();
|
||||
});
|
||||
|
||||
it('should throw an error if an es server is not specified', function () {
|
||||
function instantiate() {
|
||||
new ScenarioManager();
|
||||
}
|
||||
|
||||
expect(instantiate).to.throwError();
|
||||
});
|
||||
});
|
14
test/fixtures/config.js
vendored
Normal file
14
test/fixtures/config.js
vendored
Normal file
|
@ -0,0 +1,14 @@
|
|||
var path = require('path');
|
||||
var rootDir = path.join(__dirname, 'scenarios');
|
||||
|
||||
module.exports = {
|
||||
makelogs: {
|
||||
base: path.join(rootDir, 'makelogs'),
|
||||
mapping: 'mapping',
|
||||
bulk: ['logstash-2015.09.17', 'logstash-2015.09.18']
|
||||
},
|
||||
emptyKibana: {
|
||||
base: path.join(rootDir, 'emptyKibana'),
|
||||
bulk: ['.kibana']
|
||||
}
|
||||
};
|
81
test/fixtures/scenarioManager.js
vendored
Normal file
81
test/fixtures/scenarioManager.js
vendored
Normal file
|
@ -0,0 +1,81 @@
|
|||
var path = require('path');
|
||||
var config = require('./config');
|
||||
var elasticsearch = require('elasticsearch');
|
||||
|
||||
function ScenarioManager(server) {
|
||||
if (!server) throw new Error('No server defined');
|
||||
|
||||
this.client = new elasticsearch.Client({
|
||||
host: server
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a testing scenario
|
||||
* @param {string} id The scenario id to load
|
||||
* @return {Promise} A promise that is resolved when elasticsearch has a response
|
||||
*/
|
||||
ScenarioManager.prototype.load = function (id) {
|
||||
var scenario = config[id];
|
||||
if (!scenario) throw new Error('No scenario found for ' + id);
|
||||
|
||||
var self = this;
|
||||
return Promise.all(scenario.bulk.map(function bulk(file) {
|
||||
var mapping;
|
||||
|
||||
if (scenario.mapping) {
|
||||
mapping = self.client.indices.create({
|
||||
index: file,
|
||||
body: require(path.join(scenario.base, scenario.mapping))
|
||||
});
|
||||
} else {
|
||||
mapping = Promise.resolve();
|
||||
}
|
||||
|
||||
return mapping.then(function () {
|
||||
self.client.bulk({
|
||||
body: require(path.join(scenario.base, file)),
|
||||
});
|
||||
});
|
||||
|
||||
}));
|
||||
};
|
||||
|
||||
/**
|
||||
* Delete a scenario
|
||||
* @param {string} index
|
||||
* @return {Promise} A promise that is resolved when elasticsearch has a response
|
||||
*/
|
||||
ScenarioManager.prototype.unload = function (id) {
|
||||
var scenario = config[id];
|
||||
if (!scenario) throw new Error('Expected index');
|
||||
|
||||
return this.client.indices.delete({
|
||||
index: scenario.bulk
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Reload a scenario
|
||||
* @param {string} index
|
||||
* @return {Promise} A promise that is resolved when elasticsearch has a response
|
||||
*/
|
||||
ScenarioManager.prototype.reload = function (id) {
|
||||
var self = this;
|
||||
|
||||
return this.unload(id).then(function () {
|
||||
return self.load(id);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Sends a delete all indices request
|
||||
* @return {Promise} A promise that is resolved when elasticsearch has a response
|
||||
*/
|
||||
ScenarioManager.prototype.deleteAll = function () {
|
||||
return this.client.indices.delete({
|
||||
index: '*'
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = ScenarioManager;
|
12
test/fixtures/scenarios/emptyKibana/.kibana.js
vendored
Normal file
12
test/fixtures/scenarios/emptyKibana/.kibana.js
vendored
Normal file
|
@ -0,0 +1,12 @@
|
|||
module.exports = [{
|
||||
'index': {
|
||||
'_index': '.kibana',
|
||||
'_type': 'config'
|
||||
}
|
||||
}, {
|
||||
'index': '.kibana',
|
||||
'body': {
|
||||
'buildNum': '@@buildNum'
|
||||
},
|
||||
'id': '@@version'
|
||||
}];
|
8257
test/fixtures/scenarios/makelogs/logstash-2015.09.17.js
vendored
Normal file
8257
test/fixtures/scenarios/makelogs/logstash-2015.09.17.js
vendored
Normal file
File diff suppressed because it is too large
Load diff
23741
test/fixtures/scenarios/makelogs/logstash-2015.09.18.js
vendored
Normal file
23741
test/fixtures/scenarios/makelogs/logstash-2015.09.18.js
vendored
Normal file
File diff suppressed because it is too large
Load diff
110
test/fixtures/scenarios/makelogs/mapping.js
vendored
Normal file
110
test/fixtures/scenarios/makelogs/mapping.js
vendored
Normal file
|
@ -0,0 +1,110 @@
|
|||
module.exports = {
|
||||
'settings': {
|
||||
'index': {
|
||||
'number_of_shards': 1,
|
||||
'number_of_replicas': 0
|
||||
},
|
||||
'analysis': {
|
||||
'analyzer': {
|
||||
'url': {
|
||||
'type': 'standard',
|
||||
'tokenizer': 'uax_url_email',
|
||||
'max_token_length': 1000
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
'mappings': {
|
||||
'_default_': {
|
||||
'dynamic_templates': [{
|
||||
'string_fields': {
|
||||
'mapping': {
|
||||
'type': 'multi_field',
|
||||
'doc_values': true,
|
||||
'fields': {
|
||||
'{name}': {
|
||||
'index': 'analyzed',
|
||||
'omit_norms': true,
|
||||
'type': 'string'
|
||||
},
|
||||
'raw': {
|
||||
'index': 'not_analyzed',
|
||||
'type': 'string',
|
||||
'doc_values': true
|
||||
}
|
||||
}
|
||||
},
|
||||
'match_mapping_type': 'string',
|
||||
'match': '*'
|
||||
}
|
||||
}],
|
||||
'_timestamp': {
|
||||
'enabled': true
|
||||
},
|
||||
'properties': {
|
||||
'@timestamp': {
|
||||
'type': 'date'
|
||||
},
|
||||
'id': {
|
||||
'type': 'integer',
|
||||
'index': 'not_analyzed',
|
||||
'include_in_all': false
|
||||
},
|
||||
'clientip': {
|
||||
'type': 'ip'
|
||||
},
|
||||
'ip': {
|
||||
'type': 'ip'
|
||||
},
|
||||
'memory': {
|
||||
'type': 'double'
|
||||
},
|
||||
'referer': {
|
||||
'type': 'string',
|
||||
'index': 'not_analyzed'
|
||||
},
|
||||
'geo': {
|
||||
'properties': {
|
||||
'srcdest': {
|
||||
'type': 'string',
|
||||
'index': 'not_analyzed'
|
||||
},
|
||||
'dest': {
|
||||
'type': 'string',
|
||||
'index': 'not_analyzed'
|
||||
},
|
||||
'src': {
|
||||
'type': 'string',
|
||||
'index': 'not_analyzed'
|
||||
},
|
||||
'coordinates': {
|
||||
'type': 'geo_point'
|
||||
}
|
||||
}
|
||||
},
|
||||
'meta': {
|
||||
'properties': {
|
||||
'related': {
|
||||
'type': 'string'
|
||||
},
|
||||
'char': {
|
||||
'type': 'string',
|
||||
'index': 'not_analyzed'
|
||||
},
|
||||
'user': {
|
||||
'properties': {
|
||||
'firstname': {
|
||||
'type': 'string'
|
||||
},
|
||||
'lastname': {
|
||||
'type': 'integer',
|
||||
'index': 'not_analyzed'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
6
test/fixtures/test.json
vendored
6
test/fixtures/test.json
vendored
|
@ -1,6 +0,0 @@
|
|||
{ "index" : { "_index" : "test", "_type" : "type1", "_id" : "1" } }
|
||||
{ "field1" : "value1" }
|
||||
{ "index" : { "_index" : "test", "_type" : "type1", "_id" : "2" } }
|
||||
{ "field1" : "value2" }
|
||||
{ "index" : { "_index" : "test", "_type" : "type1", "_id" : "3" } }
|
||||
{ "field1" : "value3" }
|
|
@ -13,5 +13,5 @@ define({
|
|||
port: 4444
|
||||
},
|
||||
functionalSuites: ['test/functional/status.js'],
|
||||
excludeInstrumentation: /^(?:tests|node_modules)\//
|
||||
excludeInstrumentation: /(fixtures|node_modules)\//
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue