Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New dashboard tests using elasticdump #7298

Merged
merged 9 commits into from
May 31, 2016
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@
"auto-release-sinon": "1.0.3",
"babel-eslint": "4.1.8",
"chokidar": "1.4.3",
"elasticdump": "2.1.1",
"eslint": "1.10.3",
"eslint-plugin-mocha": "1.1.0",
"expect.js": "0.3.1",
Expand Down
8 changes: 8 additions & 0 deletions test/fixtures/dump_data/dashboard.data.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions test/fixtures/dump_data/dashboard.mapping.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{".kibana":{"mappings":{"config":{"properties":{"buildNum":{"type":"keyword"}}},"index-pattern":{"properties":{"fields":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},"timeFieldName":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},"title":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}}}},"search":{"properties":{"columns":{"type":"text"},"description":{"type":"text"},"hits":{"type":"integer"},"kibanaSavedObjectMeta":{"properties":{"searchSourceJSON":{"type":"text"}}},"sort":{"type":"text"},"title":{"type":"text"},"version":{"type":"integer"}}},"visualization":{"properties":{"description":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},"kibanaSavedObjectMeta":{"properties":{"searchSourceJSON":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}}}},"title":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},"uiStateJSON":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},"version":{"type":"integer"},"visState":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}}}},"server":{"properties":{"uuid":{"type":"keyword"}}},"dashboard":{"properties":{"description":{"type":"text"},"hits":{"type":"integer"},"kibanaSavedObjectMeta":{"properties":{"searchSourceJSON":{"type":"text"}}},"optionsJSON":{"type":"text"},"panelsJSON":{"type":"text"},"timeFrom":{"type":"text"},"timeRestore":{"type":"boolean"},"timeTo":{"type":"text"},"title":{"type":"text"},"uiStateJSON":{"type":"text"},"version":{"type":"integer"}}}}}}
2 changes: 0 additions & 2 deletions test/functional/apps/console/_console.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import {
bdd,
scenarioManager,
common,
// settingsPage,
// headerPage,
consolePage
} from '../../../support';

Expand Down
4 changes: 0 additions & 4 deletions test/functional/apps/console/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ import { bdd, remote, scenarioManager, defaultTimeout } from '../../../support';
return remote.setWindowSize(1200,800);
});

bdd.after(function unloadMakelogs() {
return scenarioManager.unload('logstashFunctional');
});

require('./_console');
});
}());
140 changes: 140 additions & 0 deletions test/functional/apps/dashboard/_dashboard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
import {
bdd,
common,
dashboardPage,
headerPage,
scenarioManager,
esClient,
elasticDump
} from '../../../support';

(function () {
var expect = require('expect.js');

(function () {
bdd.describe('dashboard tab', function describeIndexTests() {

bdd.before(function () {

var fromTime = '2015-09-19 06:31:44.000';
var toTime = '2015-09-23 18:31:44.000';

common.debug('Starting dashboard before method');
common.debug('navigateToApp dashboard');
return esClient.delete('.kibana')
.then(function () {
return common.try(function () {
return esClient.updateConfigDoc({'dateFormat:tz':'UTC', 'defaultIndex':'logstash-*'});
});
})
// and load a set of makelogs data
.then(function loadkibana4() {
common.debug('load kibana index with visualizations');
return elasticDump.elasticLoad('dashboard','.kibana');
})
.then(function () {
return scenarioManager.loadIfEmpty('logstashFunctional');
})
.then(function () {
return common.navigateToApp('dashboard');
})
.catch(common.handleError(this));
});


bdd.describe('add visualizations to dashboard', function dashboardTest() {
var visualizations = ['Visualization漢字 AreaChart',
'Visualization☺漢字 DataTable',
'Visualization漢字 LineChart',
'Visualization PieChart',
'Visualization TileMap',
'Visualization☺ VerticalBarChart',
'Visualization MetricChart'
];


bdd.it('should be able to add visualizations to dashboard', function addVisualizations() {

function addVisualizations(arr) {
return arr.reduce(function (promise, vizName) {
return promise
.then(function () {
return dashboardPage.addVisualization(vizName);
});
}, Promise.resolve());
}

return addVisualizations(visualizations)
.then(function () {
common.debug('done adding visualizations');
});

});

bdd.it('set the timepicker time to that which contains our test data', function setTimepicker() {
var fromTime = '2015-09-19 06:31:44.000';
var toTime = '2015-09-23 18:31:44.000';
var testSubName = 'Dashboard Test 1';

// .then(function () {
common.debug('Set absolute time range from \"' + fromTime + '\" to \"' + toTime + '\"');
return headerPage.setAbsoluteRange(fromTime, toTime)
.then(function sleep() {
return common.sleep(4000);
})
.then(function takeScreenshot() {
common.debug('Take screenshot');
common.saveScreenshot('./screenshot-' + testSubName + '.png');
})
.catch(common.handleError(this));
});

bdd.it('should save and load dashboard', function saveAndLoadDashboard() {
var testSubName = 'Dashboard Test 1';
// save time on the dashboard?
return dashboardPage.saveDashboard(testSubName)
// click New Dashboard just to clear the one we just created
.then(function () {
return dashboardPage.clickNewDashboard();
})
.then(function () {
return dashboardPage.loadSavedDashboard(testSubName);
})
.catch(common.handleError(this));
});

bdd.it('should have all the expected visualizations', function checkVisualizations() {
return common.tryForTime(10000, function () {
return dashboardPage.getPanelTitles()
.then(function (panelTitles) {
common.log('visualization titles = ' + panelTitles);
expect(panelTitles).to.eql(visualizations);
});
})
.catch(common.handleError(this));
});

bdd.it('should have all the expected initial sizes', function checkVisualizationSizes() {
var visObjects = [ { dataCol: '1', dataRow: '1', dataSizeX: '3', dataSizeY: '2', title: 'Visualization漢字 AreaChart' },
{ dataCol: '4', dataRow: '1', dataSizeX: '3', dataSizeY: '2', title: 'Visualization☺漢字 DataTable' },
{ dataCol: '7', dataRow: '1', dataSizeX: '3', dataSizeY: '2', title: 'Visualization漢字 LineChart' },
{ dataCol: '10', dataRow: '1', dataSizeX: '3', dataSizeY: '2', title: 'Visualization PieChart' },
{ dataCol: '1', dataRow: '3', dataSizeX: '3', dataSizeY: '2', title: 'Visualization TileMap' },
{ dataCol: '4', dataRow: '3', dataSizeX: '3', dataSizeY: '2', title: 'Visualization☺ VerticalBarChart' },
{ dataCol: '7', dataRow: '3', dataSizeX: '3', dataSizeY: '2', title: 'Visualization MetricChart' }
];
return common.tryForTime(10000, function () {
return dashboardPage.getPanelData()
.then(function (panelTitles) {
common.log('visualization titles = ' + panelTitles);
expect(panelTitles).to.eql(visObjects);
});
})
.catch(common.handleError(this));
});

});

});
}());
}());
13 changes: 13 additions & 0 deletions test/functional/apps/dashboard/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { bdd, remote, scenarioManager, defaultTimeout } from '../../../support';

(function () {
bdd.describe('dashboard app', function () {
this.timeout = defaultTimeout;

bdd.before(function () {
return remote.setWindowSize(1200,800);
});

require('./_dashboard');
});
}());
3 changes: 2 additions & 1 deletion test/functional/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ define(function (require) {
'intern/dojo/node!./status_page',
'intern/dojo/node!./apps/settings',
'intern/dojo/node!./apps/visualize',
'intern/dojo/node!./apps/console'
'intern/dojo/node!./apps/console',
'intern/dojo/node!./apps/dashboard'
], function () {});
});
});
113 changes: 113 additions & 0 deletions test/support/elastic_dump.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import { common, config} from './';

export default (function () {
var util = require('util');
var path = require('path');
var url = require('url');
var resolve = require('path').resolve;
var Elasticdump = require('elasticdump').elasticdump;

function ElasticDump() {
}

ElasticDump.prototype = {
constructor: ElasticDump,

/*
** This function is basically copied from
** https://github.com/taskrabbit/elasticsearch-dump/blob/master/bin/elasticdump
** and allows calling elasticdump for importing or exporting data from Elasticsearch
*/
elasticdumpModule: function elasticdumpModule(myinput, myoutput, index, mytype) {
var self = this;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not used


var options = {
limit: 100,
offset: 0,
debug: false,
type: mytype,
delete: false,
all: false,
maxSockets: null,
input: myinput,
'input-index': null,
output: myoutput,
'output-index': index,
inputTransport: null,
outputTransport: null,
searchBody: null,
sourceOnly: false,
jsonLines: false,
format: '',
'ignore-errors': false,
scrollTime: '10m',
timeout: null,
skip: null,
toLog: null,
};
// common.debug(options);
var dumper = new Elasticdump(options.input, options.output, options);

dumper.on('log', function (message) { common.debug(message); });
// dumper.on('debug', function (message) { common.debug(message); });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we remove the commented out code if it's not needed? here and on line 48

dumper.on('error', function (error) { common.debug('error', 'Error Emitted => ' + (error.message || JSON.stringify(error))); });

var promise = new Promise(function (resolve, reject) {
dumper.dump(function (error, totalWrites) {
if (error) {
common.debug('THERE WAS AN ERROR :-(');
reject(Error(error));
} else {
resolve ('elasticdumpModule success');
}
});
});
return promise;
},

/*
** Dumps data from Elasticsearch into json files.
** Takes a simple filename as input like 'dashboard' (for dashboard tests).
** Appends ''.mapping.json' and '.data.json' for the actual filenames.
** Writes files to the Kibana root dir.
** Fails if the files already exist, so consider appending a timestamp to filename.
*/
elasticDump: function elasticDump(index, file) {
var self = this;
common.debug('Dumping mapping from ' + url.format(config.servers.elasticsearch) + '/' + index
+ ' to (' + file + '.mapping.json)');
return this.elasticdumpModule(url.format(config.servers.elasticsearch),
file + '.mapping.json', index, 'mapping')
.then(function () {
common.debug('Dumping data from ' + url.format(config.servers.elasticsearch) + '/' + index
+ ' to (' + file + '.data.json)');
return self.elasticdumpModule(url.format(config.servers.elasticsearch),
file + '.data.json', index, 'data');
});
},

/*
** Loads data from json files into Elasticsearch.
** Takes a simple filename as input like 'dashboard' (for dashboard tests).
** Appends ''.mapping.json' and '.data.json' for the actual filenames.
** Path /test/fixtures/dump_data is hard-coded
*/
elasticLoad: function elasticLoad(file, index) {
// TODO: should we have a flag to delete the index first?
// or use scenarioManager.unload(index) ? <<- currently this
var self = this;
common.debug('Loading mapping (test/fixtures/dump_data/' + file + '.mapping.json) into '
+ url.format(config.servers.elasticsearch) + '/' + index);
return this.elasticdumpModule('test/fixtures/dump_data/' + file + '.mapping.json',
url.format(config.servers.elasticsearch), index, 'mapping')
.then(function () {
common.debug('Loading data (test/fixtures/dump_data/' + file + '.data.json) into '
+ url.format(config.servers.elasticsearch) + '/' + index);
return self.elasticdumpModule('test/fixtures/dump_data/' + file + '.data.json',
url.format(config.servers.elasticsearch), index, 'data');
});
},
};

return ElasticDump;
}());
Loading