Skip to content

Commit

Permalink
Merge branch 'master' into elasticgh-6059
Browse files Browse the repository at this point in the history
  • Loading branch information
ycombinator committed Mar 10, 2016
2 parents 802863a + 50ee56b commit ef0cc97
Show file tree
Hide file tree
Showing 65 changed files with 791 additions and 699 deletions.
2 changes: 1 addition & 1 deletion .node-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.3.0
4.3.2
105 changes: 51 additions & 54 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,94 +111,90 @@ Before running the tests you will need to install the projects dependencies as d

Once that is complete just run:

```sh
```
sh
npm run test && npm run build
```

#### Testing and debugging tests
#### Debugging unit tests

The standard `npm run test` task runs several sub tasks and can take several minutes to complete, making debugging failures pretty painful. In order to ease the pain specialized tasks provide alternate methods for running the tests.

<dl>
<dt><code>npm run test:quick</code></dt>
<dd>Runs both server and browser tests, but skips linting</dd>

<dt><code>npm run test:server</code> or <code>npm run test:browser</code></dt>
<dd>Runs the tests for just the server or browser</dd>

<dt><code>npm run test:dev</code></dt>
<dd>
Initializes an environment for debugging the browser tests. Includes an dedicated instance of the kibana server for building the test bundle, and a karma server. When running this task the build is optimized for the first time and then a karma-owned instance of the browser is opened. Click the "debug" button to open a new tab that executes the unit tests.
<br>
<img src="http://i.imgur.com/DwHxgfq.png">
</dd>
`npm run test:quick`
Runs both server and browser tests, but skips linting

<dt><code>npm run mocha [test file or dir]</code> or <code>npm run mocha:debug [test file or dir]</code></dt>
<dd>
Run a one off test with the local project version of mocha, babel compilation, and optional debugging. Great
for development and fixing individual tests.
</dd>
</dl>
`npm run test:server`
Run only the server tests

Distributable packages can be found in `target/` after the build completes.

#### Building OS packages

Packages are built using fpm, pleaserun, dpkg, and rpm. fpm and pleaserun can be installed using gem. Package building has only been tested on Linux and is not supported on any other platform.
```sh
gem install pleaserun
apt-get install ruby-dev
gem install fpm
npm run build:ospackages
```
`npm run test:browser`
Run only the browser tests

To specify a package to build you can add `rpm` or `deb` as an argument.
```sh
npm run build:ospackages -- --rpm
```
`npm run test:dev`
Initializes an environment for debugging the browser tests. Includes an dedicated instance of the kibana server for building the test bundle, and a karma server. When running this task the build is optimized for the first time and then a karma-owned instance of the browser is opened. Click the "debug" button to open a new tab that executes the unit tests.
![Browser test debugging](http://i.imgur.com/DwHxgfq.png)

### Functional UI Testing
`npm run mocha [test file or dir]` or `npm run mocha:debug [test file or dir]`
Run a one off test with the local project version of mocha, babel compilation, and optional debugging. Great
for development and fixing individual tests.

#### Handy references
#### Unit testing plugins
This should work super if you're using the [Kibana plugin generator](https://github.com/elastic/generator-kibana-plugin). If you're not using the generator, well, you're on your own. We suggest you look at how the generator works.

- https://theintern.github.io/
- https://theintern.github.io/leadfoot/Element.html
`npm run test:dev -- --kbnServer.testsBundle.pluginId=some_special_plugin --kbnServer.plugin-path=../some_special_plugin`
Run the tests for just your particular plugin. Assuming you plugin lives outside of the `installedPlugins directory`, which it should.

#### Running tests using npm task:
#### Running browser automation tests:

*The Selenium server that is started currently only runs the tests in Firefox*

To run the functional UI tests use the following commands

<dl>

<dt><code>npm run test:ui</code></dt>
<dd>Run the functional UI tests one time and exit. This is used by the CI systems and is great for quickly checking that things pass. It is essentially a combination of the next two tasks.</dd>
The following will start Kibana, Elasticsearch and Selenium for you. To run the functional UI tests use the following commands

<dt><code>npm run test:ui:server</code></dt>
<dd>Start the server required for the <code>test:ui:runner</code> tasks. Once the server is started <code>test:ui:runner</code> can be run multiple times without waiting for the server to start.</dd>
`npm run test:ui`
Run the functional UI tests one time and exit. This is used by the CI systems and is great for quickly checking that things pass. It is essentially a combination of the next two tasks.

<dt><code>npm run test:ui:runner</code></dt>
<dd>Execute the front-end selenium tests. This requires the server started by the <code>test:ui:server</code> task.</dd>
`npm run test:ui:server`
Start the server required for the `test:ui:runner` tasks. Once the server is started `test:ui:runner` can be run multiple times without waiting for the server to start.

</dl>
`npm run test:ui:runner`
Execute the front-end selenium tests. This requires the server started by the `test:ui:server` task.

#### Running tests locally with your existing (and already running) ElasticSearch, Kibana, and Selenium Server:
##### If you already have ElasticSearch, Kibana, and Selenium Server running:

Set your es and kibana ports in `test/intern.js` to 9220 and 5620, respectively. You can configure your Selenium server to run the tests on Chrome,IE, or other browsers here.

Once you've got the services running, execute the following:

```sh
```
sh
npm run test:ui:runner
```

#### General notes:
#### Browser automation notes:

- Using Page Objects pattern (https://theintern.github.io/intern/#writing-functional-test)
- At least the initial tests for the Settings, Discover, and Visualize tabs all depend on a very specific set of logstash-type data (generated with makelogs). Since that is a static set of data, all the Discover and Visualize tests use a specific Absolute time range. This guarantees the same results each run.
- These tests have been developed and tested with Chrome and Firefox browser. In theory, they should work on all browsers (that's the benefit of Intern using Leadfoot).
- These tests should also work with an external testing service like https://saucelabs.com/ or https://www.browserstack.com/ but that has not been tested.
- https://theintern.github.io/
- https://theintern.github.io/leadfoot/Element.html

#### Building OS packages

Packages are built using fpm, pleaserun, dpkg, and rpm. fpm and pleaserun can be installed using gem. Package building has only been tested on Linux and is not supported on any other platform.
```sh
gem install pleaserun
apt-get install ruby-dev
gem install fpm
npm run build:ospackages
```

To specify a package to build you can add `rpm` or `deb` as an argument.
```sh
npm run build:ospackages -- --rpm
```

Distributable packages can be found in `target/` after the build completes.

## Submitting a pull request

Expand All @@ -225,6 +221,7 @@ Remember, someone is blocked by a pull awaiting review, make it count. Be thorou
1. **Understand the issue** that is being fixed, or the feature being added. Check the description on the pull, and check out the related issue. If you don't understand something, ask the person the submitter for clarification.
1. **Reproduce the bug** (or the lack of feature I guess?) in the destination branch, usually `master`. The referenced issue will help you here. If you're unable to reproduce the issue, contact the issue submitter for clarification
1. **Check out the pull** and test it. Is the issue fixed? Does it have nasty side effects? Try to create suspect inputs. If it operates on the value of a field try things like: strings (including an empty string), null, numbers, dates. Try to think of edge cases that might break the code.
1. **Merge the target branch**. It is possible that tests or the linter have been updated in the target branch since the pull was submitted. Merging the pull could cause core to start failing.
1. **Read the code**. Understanding the changes will help you find additional things to test. Contact the submitter if you don't understand something.
1. **Go line-by-line**. Are there [style guide](https://github.com/elastic/kibana/blob/master/STYLEGUIDE.md) violations? Strangely named variables? Magic numbers? Do the abstractions make sense to you? Are things arranged in a testable way?
1. **Speaking of tests** Are they there? If a new function was added does it have tests? Do the tests, well, TEST anything? Do they just run the function or do they properly check the output?
Expand Down
2 changes: 1 addition & 1 deletion config/kibana.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@

# Time in milliseconds to wait for responses from the back end or Elasticsearch. This value
# must be a positive integer.
# elasticsearch.requestTimeout: 300000
# elasticsearch.requestTimeout: 30000

# Time in milliseconds for Elasticsearch to wait for responses from shards. Set to 0 to disable.
# elasticsearch.shardTimeout: 0
Expand Down
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"elasticsearchWithPlugins": "grunt esvm:withPlugins:keepalive",
"lint": "grunt eslint:source",
"lintroller": "grunt eslint:fixSource",
"makelogs": "makelogs",
"mocha": "mocha",
"mocha:debug": "mocha --debug-brk",
"sterilize": "grunt sterilize"
Expand Down Expand Up @@ -88,7 +89,7 @@
"boom": "2.8.0",
"bootstrap": "3.3.5",
"brace": "0.5.1",
"bunyan": "1.4.0",
"bunyan": "1.7.1",
"clipboard": "1.5.5",
"commander": "2.8.1",
"css-loader": "0.17.0",
Expand Down Expand Up @@ -145,7 +146,7 @@
"angular-mocks": "1.4.7",
"auto-release-sinon": "1.0.3",
"babel-eslint": "4.1.8",
"chokidar": "1.0.5",
"chokidar": "1.4.3",
"eslint": "1.10.3",
"eslint-plugin-mocha": "1.1.0",
"expect.js": "0.3.1",
Expand Down Expand Up @@ -176,6 +177,7 @@
"libesvm": "3.3.0",
"license-checker": "3.1.0",
"load-grunt-config": "0.7.2",
"makelogs": "3.0.0-beta3",
"marked-text-renderer": "0.1.0",
"mocha": "2.3.0",
"nock": "2.10.0",
Expand All @@ -187,7 +189,7 @@
"supertest-as-promised": "2.0.2"
},
"engines": {
"node": "4.3.0",
"npm": "2.14.15"
"node": "4.3.2",
"npm": "2.14.22"
}
}
25 changes: 15 additions & 10 deletions src/cli/cluster/cluster_manager.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import cluster from 'cluster';
const { join } = require('path');
const { join, resolve } = require('path');
const { format: formatUrl } = require('url');
import Hapi from 'hapi';
const { debounce, compact, get, invoke, bindAll, once, sample } = require('lodash');
const { debounce, compact, get, invoke, bindAll, once, sample, uniq } = require('lodash');

import Log from '../Log';
import Worker from './worker';
Expand Down Expand Up @@ -85,14 +85,19 @@ module.exports = class ClusterManager {
const chokidar = require('chokidar');
const fromRoot = require('../../utils/fromRoot');

this.watcher = chokidar.watch([
'src/plugins',
'src/server',
'src/ui',
'src/utils',
'config',
...extraPaths
], {
const watchPaths = uniq(
[
fromRoot('src/plugins'),
fromRoot('src/server'),
fromRoot('src/ui'),
fromRoot('src/utils'),
fromRoot('config'),
...extraPaths
]
.map(path => resolve(path))
);

this.watcher = chokidar.watch(watchPaths, {
cwd: fromRoot('.'),
ignored: /[\\\/](\..*|node_modules|bower_components|public|__tests__)[\\\/]/
});
Expand Down
6 changes: 3 additions & 3 deletions src/plugins/elasticsearch/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module.exports = function ({ Plugin }) {
key: string()
}).default(),
apiVersion: Joi.string().default('master'),
engineVersion: Joi.string().valid('^3.0.0').default('^3.0.0')
engineVersion: Joi.string().valid('^5.0.0').default('^5.0.0')
}).default();
},

Expand All @@ -54,7 +54,7 @@ module.exports = function ({ Plugin }) {
return reply.continue();
}

function noCreateIndex({ path }, reply) {
function noDirectIndex({ path }, reply) {
const requestPath = trimRight(trim(path), '/');
const matchPath = createPath(kibanaIndex);

Expand All @@ -75,7 +75,7 @@ module.exports = function ({ Plugin }) {
['PUT', 'POST', 'DELETE'],
`/${kibanaIndex}/{paths*}`,
{
pre: [ noCreateIndex, noBulkCheck ]
pre: [ noDirectIndex, noBulkCheck ]
}
);

Expand Down
2 changes: 2 additions & 0 deletions src/plugins/elasticsearch/lib/__tests__/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ describe('plugins/elasticsearch', function () {
let kbnServer;

before(function () {
this.timeout(60000); // sometimes waiting for server takes longer than 10

kbnServer = kbnTestServer.createServer();
return kbnServer.ready()
.then(() => kbnServer.server.plugins.elasticsearch.waitUntilReady());
Expand Down
13 changes: 3 additions & 10 deletions src/plugins/elasticsearch/lib/create_kibana_index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import SetupError from './setup_error';
import { format } from 'util';
import { mappings } from './kibana_index_mappings';

module.exports = function (server) {
const client = server.plugins.elasticsearch.client;
const index = server.config().get('kibana.index');
Expand All @@ -16,16 +18,7 @@ module.exports = function (server) {
settings: {
number_of_shards: 1
},
mappings: {
config: {
properties: {
buildNum: {
type: 'string',
index: 'not_analyzed'
}
}
}
}
mappings
}
})
.catch(handleError('Unable to create Kibana index "<%= kibana.index %>"'))
Expand Down
11 changes: 9 additions & 2 deletions src/plugins/elasticsearch/lib/create_proxy.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
import createAgent from './create_agent';
import mapUri from './map_uri';
import { resolve } from 'url';
import { assign } from 'lodash';

function createProxy(server, method, route, config) {

const options = {
method: method,
path: createProxy.createPath(route),
config: {
timeout: {
socket: server.config().get('elasticsearch.requestTimeout')
}
},
handler: {
proxy: {
mapUri: mapUri(server),
passThrough: true,
agent: createAgent(server),
xforward: true
xforward: true,
timeout: server.config().get('elasticsearch.requestTimeout')
}
},
};

if (config) options.config = config;
assign(options.config, config);

server.route(options);
};
Expand Down
Loading

0 comments on commit ef0cc97

Please sign in to comment.