mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
simplify elasticsearch proxy creation to prevent a bug that creates a .kibana type
This commit is contained in:
parent
31836a6302
commit
2f416a5ad2
7 changed files with 31 additions and 42 deletions
|
@ -32,9 +32,9 @@ module.exports = function (kibana) {
|
|||
|
||||
// Expose the client to the server
|
||||
exposeClient(server);
|
||||
createProxy(server, 'GET', '/elasticsearch/{paths*}');
|
||||
createProxy(server, 'POST', '/elasticsearch/_mget');
|
||||
createProxy(server, 'POST', '/elasticsearch/_msearch');
|
||||
createProxy(server, 'GET', '/{paths*}');
|
||||
createProxy(server, 'POST', '/_mget');
|
||||
createProxy(server, 'POST', '/_msearch');
|
||||
|
||||
function noBulkCheck(request, reply) {
|
||||
if (/\/_bulk/.test(request.path)) {
|
||||
|
@ -48,10 +48,9 @@ module.exports = function (kibana) {
|
|||
createProxy(
|
||||
server,
|
||||
['PUT', 'POST', 'DELETE'],
|
||||
'/elasticsearch/' + config.get('kibana.index') + '/{paths*}',
|
||||
'/' + config.get('kibana.index') + '/{paths*}',
|
||||
{
|
||||
prefix: '/' + config.get('kibana.index'),
|
||||
config: { pre: [ noBulkCheck ] }
|
||||
pre: [ noBulkCheck ]
|
||||
}
|
||||
);
|
||||
|
||||
|
|
|
@ -2,11 +2,13 @@ var portscanner = require('portscanner');
|
|||
var path = require('path');
|
||||
var Promise = require('bluebird');
|
||||
var libesvm = require('libesvm');
|
||||
var fromRoot = require('requirefrom')('src/utils')('fromRoot');
|
||||
|
||||
function startEs() {
|
||||
var options = {
|
||||
version: '1.4.4',
|
||||
directory: path.join(__dirname, '..', '..', 'esvm'),
|
||||
branch: 'master',
|
||||
directory: fromRoot('esvm/test-es'),
|
||||
purge: true,
|
||||
config: {
|
||||
'cluster.name': 'test',
|
||||
'network.host': '127.0.0.1'
|
||||
|
@ -28,7 +30,7 @@ function maybeStartES() {
|
|||
return new Promise(function (resolve, reject) {
|
||||
portscanner.checkPortStatus(9200, '127.0.0.1', function (err, status) {
|
||||
if (err) return reject(err);
|
||||
if (status === 'closed') return startEs().then(resolve);
|
||||
if (status === 'closed') return startEs().then(resolve, reject);
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -46,11 +46,9 @@ describe('plugins/elasticsearch', function () {
|
|||
kbnServer.server.inject(options, function (res) {
|
||||
try {
|
||||
expect(res.statusCode).to.be(statusCode);
|
||||
done();
|
||||
} catch (e) {
|
||||
done(e);
|
||||
done = null;
|
||||
} finally {
|
||||
done && done();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -72,7 +70,7 @@ describe('plugins/elasticsearch', function () {
|
|||
method: 'POST',
|
||||
url: '/elasticsearch/.kibana',
|
||||
payload: {settings: { number_of_shards: 1, number_of_replicas: 1 }},
|
||||
statusCode: 201
|
||||
statusCode: 200
|
||||
});
|
||||
|
||||
testRoute({
|
||||
|
@ -87,17 +85,6 @@ describe('plugins/elasticsearch', function () {
|
|||
statusCode: 400
|
||||
});
|
||||
|
||||
testRoute({
|
||||
method: 'GET',
|
||||
url: '/elasticsearch/.kibana/_mapping/*/field/_source'
|
||||
});
|
||||
|
||||
testRoute({
|
||||
method: 'POST',
|
||||
url: '/elasticsearch/.kibana/index-pattern/_search?fields=',
|
||||
payload: {query: {match_all: {}}, size: 2147483647}
|
||||
});
|
||||
|
||||
testRoute({
|
||||
method: 'POST',
|
||||
url: '/elasticsearch/.kibana/__kibanaQueryValidator/_validate/query?explain=true&ignore_unavailable=true',
|
||||
|
|
|
@ -1,19 +1,25 @@
|
|||
var createAgent = require('./create_agent');
|
||||
var mapUri = require('./map_uri');
|
||||
module.exports = function createProxy(server, method, route, opts) {
|
||||
opts = opts || {};
|
||||
var { resolve } = require('url');
|
||||
module.exports = function createProxy(server, method, route, config) {
|
||||
|
||||
var pre = '/elasticsearch';
|
||||
var sep = route[0] === '/' ? '' : '/';
|
||||
var path = `${pre}${sep}${route}`;
|
||||
var options = {
|
||||
method: method,
|
||||
path: route,
|
||||
path: path,
|
||||
handler: {
|
||||
proxy: {
|
||||
mapUri: mapUri(server, opts.prefix),
|
||||
mapUri: mapUri(server),
|
||||
passThrough: true,
|
||||
agent: createAgent(server)
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
if (opts && opts.config) options.config = opts.config;
|
||||
|
||||
if (config) options.config = config;
|
||||
|
||||
server.route(options);
|
||||
};
|
||||
|
||||
|
|
|
@ -29,12 +29,13 @@ module.exports = function (plugin, server) {
|
|||
function waitForShards() {
|
||||
return client.cluster.health({
|
||||
timeout: '5s', // tells es to not sit around and wait forever
|
||||
index: config.get('kibana.index')
|
||||
index: config.get('kibana.index'),
|
||||
ignore: [408]
|
||||
})
|
||||
.then(function (resp) {
|
||||
// if "timed_out" === true then elasticsearch could not
|
||||
// find any idices matching our filter within 5 seconds
|
||||
if (resp.timed_out) {
|
||||
if (!resp || resp.timed_out) {
|
||||
plugin.status.yellow('No existing Kibana index found');
|
||||
return createKibanaIndex(server);
|
||||
}
|
||||
|
|
|
@ -3,16 +3,10 @@ var resolve = require('url').resolve;
|
|||
module.exports = function mapUri(server, prefix) {
|
||||
var config = server.config();
|
||||
return function (request, done) {
|
||||
var paths = request.params.paths;
|
||||
if (!paths) {
|
||||
paths = request.path.replace('/elasticsearch', '');
|
||||
}
|
||||
if (prefix) {
|
||||
paths = prefix + '/' + paths;
|
||||
}
|
||||
var path = request.path.replace('/elasticsearch', '');
|
||||
var url = config.get('elasticsearch.url');
|
||||
if (!/\/$/.test(url)) url += '/';
|
||||
if (paths) url = resolve(url, paths);
|
||||
if (path) url = resolve(url, path);
|
||||
var query = querystring.stringify(request.query);
|
||||
if (query) url += '?' + query;
|
||||
done(null, url);
|
||||
|
|
|
@ -8,16 +8,16 @@ module.exports = function (grunt) {
|
|||
|
||||
grunt.task.run(_.compact([
|
||||
'eslint:source',
|
||||
'maybeStartTestServer',
|
||||
'simplemocha:all',
|
||||
'maybeStartTestServer',
|
||||
'karma:unit'
|
||||
]));
|
||||
});
|
||||
|
||||
grunt.registerTask('quick-test', function () {
|
||||
grunt.task.run([
|
||||
'maybeStartTestServer',
|
||||
'simplemocha:all',
|
||||
'maybeStartTestServer',
|
||||
'karma:unit'
|
||||
]);
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue