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

[6.x] Integrate new platform (core) server side into Kibana #20661

Merged
merged 1 commit into from
Jul 11, 2018
Merged
Show file tree
Hide file tree
Changes from all 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 .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ bower_components
/src/core_plugins/console/public/tests/webpackShims
/src/ui/public/utils/decode_geo_hash.js
/src/core_plugins/timelion/public/webpackShims/jquery.flot.*
/src/core/lib/kbn_internal_native_observable
/packages/*/target
/packages/eslint-config-kibana
/packages/eslint-plugin-kibana-custom
Expand Down
15 changes: 15 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,10 @@
"glob-all": "3.0.1",
"good-squeeze": "2.1.0",
"h2o2": "5.1.1",
"h2o2-latest": "npm:h2o2@8.1.2",
"handlebars": "4.0.5",
"hapi": "14.2.0",
"hapi-latest": "npm:hapi@17.5.0",
"hjson": "3.1.0",
"http-proxy-agent": "^2.1.0",
"https-proxy-agent": "^2.2.1",
Expand Down Expand Up @@ -193,12 +195,14 @@
"script-loader": "0.7.2",
"semver": "^5.5.0",
"style-loader": "0.19.0",
"symbol-observable": "^1.2.0",
"tar": "2.2.0",
"tinygradient": "0.3.0",
"tinymath": "0.2.1",
"topojson-client": "3.0.0",
"trunc-html": "1.0.2",
"trunc-text": "1.0.2",
"type-detect": "^4.0.8",
"uglifyjs-webpack-plugin": "0.4.6",
"ui-select": "0.19.6",
"url-loader": "0.5.9",
Expand Down Expand Up @@ -228,21 +232,31 @@
"@types/angular": "^1.6.45",
"@types/babel-core": "^6.25.5",
"@types/bluebird": "^3.1.1",
"@types/chance": "^1.0.0",
"@types/classnames": "^2.2.3",
"@types/eslint": "^4.16.2",
"@types/execa": "^0.9.0",
"@types/getopts": "^2.0.0",
"@types/glob": "^5.0.35",
"@types/hapi-latest": "npm:@types/hapi@17.0.12",
"@types/has-ansi": "^3.0.0",
"@types/jest": "^22.2.3",
"@types/joi": "^10.4.4",
"@types/jquery": "3.3.1",
"@types/js-yaml": "^3.11.1",
"@types/listr": "^0.13.0",
"@types/lodash": "^3.10.1",
"@types/minimatch": "^2.0.29",
"@types/node": "^8.10.20",
"@types/prop-types": "^15.5.3",
"@types/react": "^16.3.14",
"@types/react-dom": "^16.0.5",
"@types/redux": "^3.6.31",
"@types/redux-actions": "^2.2.1",
"@types/sinon": "^5.0.0",
"@types/strip-ansi": "^3.0.0",
"@types/supertest": "^2.0.4",
"@types/type-detect": "^4.0.1",
"angular-mocks": "1.4.7",
"babel-eslint": "8.1.2",
"babel-jest": "^22.4.3",
Expand Down Expand Up @@ -282,6 +296,7 @@
"grunt-run": "0.7.0",
"gulp-babel": "^7.0.1",
"gulp-sourcemaps": "1.7.3",
"has-ansi": "^3.0.0",
"husky": "0.8.1",
"image-diff": "1.6.0",
"istanbul-instrumenter-loader": "3.0.0",
Expand Down
140 changes: 0 additions & 140 deletions src/cli/cluster/base_path_proxy.js

This file was deleted.

28 changes: 19 additions & 9 deletions src/cli/cluster/cluster_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ import { debounce, invoke, bindAll, once, uniq } from 'lodash';

import Log from '../log';
import Worker from './worker';
import BasePathProxy from './base_path_proxy';
import { Config } from '../../server/config/config';
import { transformDeprecations } from '../../server/config/transform_deprecations';
import { configureBasePathProxy } from './configure_base_path_proxy';

process.env.kbnWorkerType = 'managr';

Expand All @@ -33,10 +33,14 @@ export default class ClusterManager {
const transformedSettings = transformDeprecations(settings);
const config = await Config.withDefaultSchema(transformedSettings);

return new ClusterManager(opts, config);
const basePathProxy = opts.basePath
? await configureBasePathProxy(config)
: undefined;

return new ClusterManager(opts, config, basePathProxy);
}

constructor(opts, config) {
constructor(opts, config, basePathProxy) {
this.log = new Log(opts.quiet, opts.silent);
this.addedCount = 0;

Expand All @@ -46,17 +50,17 @@ export default class ClusterManager {
'--server.autoListen=false',
];

if (opts.basePath) {
this.basePathProxy = new BasePathProxy(this, config);
if (basePathProxy) {
this.basePathProxy = basePathProxy;

optimizerArgv.push(
`--server.basePath=${this.basePathProxy.basePath}`,
`--server.basePath=${this.basePathProxy.getBasePath()}`,
'--server.rewriteBasePath=true',
);

serverArgv.push(
`--server.port=${this.basePathProxy.targetPort}`,
`--server.basePath=${this.basePathProxy.basePath}`,
`--server.port=${this.basePathProxy.getTargetPort()}`,
`--server.basePath=${this.basePathProxy.getBasePath()}`,
'--server.rewriteBasePath=true',
);
}
Expand All @@ -77,6 +81,12 @@ export default class ClusterManager {
})
];

if (basePathProxy) {
// Pass server worker to the basepath proxy so that it can hold off the
// proxying until server worker is ready.
this.basePathProxy.serverWorker = this.server;
}

// broker messages between workers
this.workers.forEach((worker) => {
worker.on('broadcast', (msg) => {
Expand Down Expand Up @@ -119,7 +129,7 @@ export default class ClusterManager {
this.setupManualRestart();
invoke(this.workers, 'start');
if (this.basePathProxy) {
this.basePathProxy.listen();
this.basePathProxy.start();
}
}

Expand Down
64 changes: 64 additions & 0 deletions src/cli/cluster/configure_base_path_proxy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { Server } from 'hapi';
import { createBasePathProxy } from '../../core';
import { setupLogging } from '../../server/logging';

export async function configureBasePathProxy(config) {
// New platform forwards all logs to the legacy platform so we need HapiJS server
// here just for logging purposes and nothing else.
const server = new Server();
setupLogging(server, config);

const basePathProxy = createBasePathProxy({ server, config });

await basePathProxy.configure({
shouldRedirectFromOldBasePath: path => {
const isApp = path.startsWith('app/');
const isKnownShortPath = ['login', 'logout', 'status'].includes(path);

return isApp || isKnownShortPath;
},

blockUntil: () => {
// Wait until `serverWorker either crashes or starts to listen.
// The `serverWorker` property should be set by the ClusterManager
// once it creates the worker.
const serverWorker = basePathProxy.serverWorker;
if (serverWorker.listening || serverWorker.crashed) {
return Promise.resolve();
}

return new Promise(resolve => {
const done = () => {
serverWorker.removeListener('listening', done);
serverWorker.removeListener('crashed', done);

resolve();
};

serverWorker.on('listening', done);
serverWorker.on('crashed', done);
});
},
});

return basePathProxy;
}
Loading